Skip to content

Commit 34c7616

Browse files
committed
Add landmark test.
1 parent fe1a7df commit 34c7616

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

system_tests/vision.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,8 @@ def tearDown(self):
121121

122122
def _assert_coordinate(self, coordinate):
123123
if coordinate is None:
124-
return True
125-
126-
self.assertIn(type(coordinate), [int, float])
124+
return
125+
self.assertIsInstance(coordinate, (int, float))
127126
self.assertGreater(abs(coordinate), 0.0)
128127

129128
def _assert_likelihood(self, likelihood):
@@ -134,22 +133,25 @@ def _assert_likelihood(self, likelihood):
134133
Likelihood.VERY_UNLIKELY]
135134
self.assertIn(likelihood, levels)
136135

137-
def _assert_landmark(self, landmark):
136+
def _assert_landmarks(self, landmarks):
138137
from google.cloud.vision.face import Landmark
139-
from google.cloud.vision.face import FaceLandmarkTypes
140-
141-
self.assertIsInstance(landmark, Landmark)
142-
143-
valid_landmark_type = getattr(FaceLandmarkTypes,
144-
landmark.landmark_type, False)
145-
if valid_landmark_type:
146-
return True
147-
return False
138+
from google.cloud.vision.face import LandmarkTypes
139+
from google.cloud.vision.face import Position
140+
141+
for landmark in LandmarkTypes:
142+
if landmark is not LandmarkTypes.UNKNOWN_LANDMARK:
143+
feature = getattr(landmarks, landmark.value.lower())
144+
self.assertIsInstance(feature, Landmark)
145+
self.assertIsInstance(feature.position, Position)
146+
self._assert_coordinate(feature.position.x_coordinate)
147+
self._assert_coordinate(feature.position.y_coordinate)
148+
self._assert_coordinate(feature.position.z_coordinate)
148149

149150
def _assert_face(self, face):
150151
from google.cloud.vision.face import Bounds
151152
from google.cloud.vision.face import FDBounds
152153
from google.cloud.vision.face import Face
154+
from google.cloud.vision.face import Landmarks
153155
from google.cloud.vision.geometry import Vertex
154156

155157
self.assertIsInstance(face, Face)
@@ -161,9 +163,9 @@ def _assert_face(self, face):
161163
self._assert_likelihood(face.image_properties.blurred)
162164
self._assert_likelihood(face.image_properties.underexposed)
163165
self._assert_likelihood(face.headwear)
164-
self.assertGreater(abs(face.angles.roll), 0.0)
165-
self.assertGreater(abs(face.angles.pan), 0.0)
166-
self.assertGreater(abs(face.angles.tilt), 0.0)
166+
self.assertNotEqual(face.angles.roll, 0.0)
167+
self.assertNotEqual(face.angles.pan, 0.0)
168+
self.assertNotEqual(face.angles.tilt, 0.0)
167169

168170
self.assertIsInstance(face.bounds, Bounds)
169171
for vertex in face.bounds.vertices:
@@ -177,6 +179,9 @@ def _assert_face(self, face):
177179
self._assert_coordinate(vertex.x_coordinate)
178180
self._assert_coordinate(vertex.y_coordinate)
179181

182+
self.assertIsInstance(face.landmarks, Landmarks)
183+
self._assert_landmarks(face.landmarks)
184+
180185
def test_detect_faces_content(self):
181186
client = Config.CLIENT
182187
with open(FACE_FILE, 'rb') as image_file:

0 commit comments

Comments
 (0)