Skip to content

Commit 9b77fc0

Browse files
committed
Fix linting error invalid-name and too-many-arguments.
1. x,y,z coordinates were too short for attribute names. 2. Too many args for Face.__init__ so moved image property values to FaceImageProperties.
1 parent e32ecd2 commit 9b77fc0

File tree

3 files changed

+88
-59
lines changed

3 files changed

+88
-59
lines changed

gcloud/vision/face.py

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,18 @@ def anger_likelihood(self):
140140
class Face(object):
141141
"""Representation of a face found by the Vision API"""
142142

143-
def __init__(self, angles, blurred_likelihood, bounds,
144-
detection_confidence, emotions, fd_bounds,
145-
headwear_likelihood, landmarks, landmarking_confidence,
146-
under_exposed_likelihood):
143+
def __init__(self, angles, bounds, detection_confidence, emotions,
144+
fd_bounds, headwear_likelihood, image_properties, landmarks,
145+
landmarking_confidence):
147146
self._angles = angles
148-
self._blurred_likelihood = blurred_likelihood
149147
self._bounds = bounds
150148
self._detection_confidence = detection_confidence
151149
self._emotions = emotions
152150
self._fd_bounds = fd_bounds
153151
self._headwear_likelihood = headwear_likelihood
154152
self._landmarks = landmarks
155153
self._landmarking_confidence = landmarking_confidence
156-
self._under_exposed_likelihood = under_exposed_likelihood
154+
self._image_properties = image_properties
157155

158156
@classmethod
159157
def from_api_repr(cls, response):
@@ -166,21 +164,19 @@ def from_api_repr(cls, response):
166164
:returns: A instance of `Face` with data parsed from `response`.
167165
"""
168166
angles = Angles.from_api_repr(response)
169-
blurred_likelihood = getattr(Likelihood, response['blurredLikelihood'])
170167
bounds = Bounds.from_api_repr(response['boundingPoly'])
171168
detection_confidence = response['detectionConfidence']
172169
emotions = Emotions.from_api_repr(response)
173170
fd_bounds = FDBounds.from_api_repr(response['fdBoundingPoly'])
174171
headwear_likelihood = getattr(Likelihood,
175172
response['headwearLikelihood'])
173+
image_properties = FaceImageProperties.from_api_repr(response)
176174
landmarks = Landmarks(response['landmarks'])
177175
landmarking_confidence = response['landmarkingConfidence']
178-
under_exposed_likelihood = getattr(Likelihood,
179-
response['underExposedLikelihood'])
180176

181-
return cls(angles, blurred_likelihood, bounds, detection_confidence,
182-
emotions, fd_bounds, headwear_likelihood, landmarks,
183-
landmarking_confidence, under_exposed_likelihood)
177+
return cls(angles, bounds, detection_confidence, emotions, fd_bounds,
178+
headwear_likelihood, image_properties, landmarks,
179+
landmarking_confidence)
184180

185181
@property
186182
def angles(self):
@@ -192,16 +188,6 @@ def angles(self):
192188

193189
return self._angles
194190

195-
@property
196-
def blurred_likelihood(self):
197-
"""Likelihood of the image being blurred.
198-
199-
:rtype: str
200-
:returns: String representing the likelihood based on
201-
:class:`gcloud.vision.face.Likelihood`
202-
"""
203-
return self._blurred_likelihood
204-
205191
@property
206192
def bounds(self):
207193
"""Accessor to the bounding poly information of the detected face.
@@ -249,6 +235,15 @@ def headwear_likelihood(self):
249235
"""
250236
return self._headwear_likelihood
251237

238+
@property
239+
def image_properties(self):
240+
"""Image properties from imaged used in face detection.
241+
242+
:rtype: :class:`gcloud.vision.face.FaceImageProperties`
243+
:returns: ``FaceImageProperties`` object with image properties.
244+
"""
245+
return self._image_properties
246+
252247
@property
253248
def landmarks(self):
254249
"""Accessor to the facial landmarks detected in a face.
@@ -268,15 +263,46 @@ def landmarking_confidence(self):
268263
"""
269264
return self._landmarking_confidence
270265

266+
267+
class FaceImageProperties(object):
268+
"""A representation of the image properties from face detection."""
269+
def __init__(self, blurred_likelihood, underexposed_likelihood):
270+
self._blurred_likelihood = blurred_likelihood
271+
self._underexposed_likelihood = underexposed_likelihood
272+
273+
@classmethod
274+
def from_api_repr(cls, response):
275+
"""Factory: construct image properties from image.
276+
277+
:rtype: :class:`gcloud.vision.face.FaceImageProperties`
278+
:returns: Instance populated with image property data.
279+
"""
280+
blurred_likelihood = getattr(Likelihood,
281+
response['blurredLikelihood'])
282+
underexposed_likelihood = getattr(Likelihood,
283+
response['underExposedLikelihood'])
284+
285+
return cls(blurred_likelihood, underexposed_likelihood)
286+
271287
@property
272-
def under_exposed_likelihood(self):
273-
"""Likelihood that the image used for detection was under exposed.
288+
def blurred_likelihood(self):
289+
"""Likelihood of the image being blurred.
274290
275291
:rtype: str
276-
:returns: String representing the likelihood based on
277-
:class:`gcloud.vision.face.Likelihood`
292+
:returns: String representation derived from
293+
:class:`gcloud.vision.face.Position`.
294+
"""
295+
return self._blurred_likelihood
296+
297+
@property
298+
def underexposed_likelihood(self):
299+
"""Likelihood that the image used for detection was underexposed.
300+
301+
:rtype: str
302+
:returns: String representation derived from
303+
:class:`gcloud.vision.face.Position`.
278304
"""
279-
return self._under_exposed_likelihood
305+
return self._underexposed_likelihood
280306

281307

282308
class FaceLandmarkTypes(object):
@@ -348,7 +374,7 @@ def from_api_repr(cls, response_landmark):
348374

349375
@property
350376
def position(self):
351-
"""Landmark position.
377+
"""Landmark position on face.
352378
353379
:rtype: :class:`gcloud.vision.face.Position`
354380
:returns: Instance of `Position` with landmark coordinates.
@@ -357,7 +383,7 @@ def position(self):
357383

358384
@property
359385
def landmark_type(self):
360-
"""Landmark type.
386+
"""Landmark type of facial feature.
361387
362388
:rtype: str
363389
:returns: String representation of facial landmark type.

gcloud/vision/geometry.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ class Position(object):
5252
See:
5353
https://cloud.google.com/vision/reference/rest/v1/images/annotate#Position
5454
"""
55-
def __init__(self, x, y, z):
56-
self._x = x
57-
self._y = y
58-
self._z = z
55+
def __init__(self, x_coordinate, y_coordinate, z_coordinate):
56+
self._x_coordinate = x_coordinate
57+
self._y_coordinate = y_coordinate
58+
self._z_coordinate = z_coordinate
5959

6060
@classmethod
6161
def from_api_repr(cls, response_position):
@@ -64,37 +64,37 @@ def from_api_repr(cls, response_position):
6464
:rtype: :class:`gcloud.vision.geometry.Position`
6565
:returns: `Position` constructed with 3D points from API response.
6666
"""
67-
x = response_position['x']
68-
y = response_position['y']
69-
z = response_position['z']
70-
return cls(x, y, z)
67+
x_coordinate = response_position['x']
68+
y_coordinate = response_position['y']
69+
z_coordinate = response_position['z']
70+
return cls(x_coordinate, y_coordinate, z_coordinate)
7171

7272
@property
73-
def x(self):
73+
def x_coordinate(self):
7474
"""X position coordinate.
7575
7676
:rtype: float
7777
:returns: X position coordinate.
7878
"""
79-
return self._x
79+
return self._x_coordinate
8080

8181
@property
82-
def y(self):
82+
def y_coordinate(self):
8383
"""Y position coordinate.
8484
8585
:rtype: float
8686
:returns: Y position coordinate.
8787
"""
88-
return self._y
88+
return self._y_coordinate
8989

9090
@property
91-
def z(self):
91+
def z_coordinate(self):
9292
"""Z position coordinate.
9393
9494
:rtype: float
9595
:returns: Z position coordinate.
9696
"""
97-
return self._z
97+
return self._z_coordinate
9898

9999

100100
class Vertex(object):
@@ -103,24 +103,24 @@ class Vertex(object):
103103
See:
104104
https://cloud.google.com/vision/reference/rest/v1/images/annotate#Vertex
105105
"""
106-
def __init__(self, x, y):
107-
self._x = x
108-
self._y = y
106+
def __init__(self, x_coordinate, y_coordinate):
107+
self._x_coordinate = x_coordinate
108+
self._y_coordinate = y_coordinate
109109

110110
@property
111-
def x(self):
111+
def x_coordinate(self):
112112
"""X position coordinate.
113113
114114
:rtype: float
115115
:returns: X position coordinate.
116116
"""
117-
return self._x
117+
return self._x_coordinate
118118

119119
@property
120-
def y(self):
120+
def y_coordinate(self):
121121
"""Y position coordinate.
122122
123123
:rtype: float
124124
:returns: Y position coordinate.
125125
"""
126-
return self._y
126+
return self._y_coordinate

gcloud/vision/test_face.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ def test_face_landmarks(self):
3131
self.assertEqual(0.54453093, self.face.landmarking_confidence)
3232
self.assertEqual(0.9863683, self.face.detection_confidence)
3333
self.assertTrue(hasattr(self.face.landmarks, 'left_eye'))
34-
self.assertEqual(1004.8003, self.face.landmarks.left_eye.position.x)
35-
self.assertEqual(482.69385, self.face.landmarks.left_eye.position.y)
36-
self.assertEqual(0.0016593217, self.face.landmarks.left_eye.position.z)
34+
self.assertEqual(1004.8003,
35+
self.face.landmarks.left_eye.position.x_coordinate)
36+
self.assertEqual(482.69385,
37+
self.face.landmarks.left_eye.position.y_coordinate)
38+
self.assertEqual(0.0016593217,
39+
self.face.landmarks.left_eye.position.z_coordinate)
3740
self.assertEqual('LEFT_EYE',
3841
self.face.landmarks.left_eye.landmark_type)
3942

@@ -56,18 +59,18 @@ def test_faciale_angles(self):
5659
def test_face_headware_and_blur_and_underexposed(self):
5760
from gcloud.vision.face import Likelihood
5861
self.assertEqual(Likelihood.VERY_UNLIKELY,
59-
self.face.blurred_likelihood)
62+
self.face.image_properties.blurred_likelihood)
6063
self.assertEqual(Likelihood.VERY_UNLIKELY,
6164
self.face.headwear_likelihood)
6265
self.assertEqual(Likelihood.VERY_UNLIKELY,
63-
self.face.under_exposed_likelihood)
66+
self.face.image_properties.underexposed_likelihood)
6467

6568
def test_face_bounds(self):
6669
self.assertEqual(4, len(self.face.bounds.vertices))
67-
self.assertEqual(748, self.face.bounds.vertices[0].x)
68-
self.assertEqual(58, self.face.bounds.vertices[0].y)
70+
self.assertEqual(748, self.face.bounds.vertices[0].x_coordinate)
71+
self.assertEqual(58, self.face.bounds.vertices[0].y_coordinate)
6972

7073
def test_facial_skin_bounds(self):
7174
self.assertEqual(4, len(self.face.fd_bounds.vertices))
72-
self.assertEqual(845, self.face.fd_bounds.vertices[0].x)
73-
self.assertEqual(310, self.face.fd_bounds.vertices[0].y)
75+
self.assertEqual(845, self.face.fd_bounds.vertices[0].x_coordinate)
76+
self.assertEqual(310, self.face.fd_bounds.vertices[0].y_coordinate)

0 commit comments

Comments
 (0)