Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move emotions to Face class. #2782

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions docs/vision-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ was detected.
>>> client = vision.Client()
>>> image = client.image(source_uri='gs://my-test-bucket/image.jpg')
>>> faces = image.detect_faces(limit=10)
>>> faces[0].landmarks.left_eye.landmark_type
>>> first_face = faces[0]
>>> first_face.landmarks.left_eye.landmark_type
'LEFT_EYE'
>>> faces[0].landmarks.left_eye.position.x_coordinate
>>> first_face.landmarks.left_eye.position.x_coordinate
1301.2404
>>> faces[0].detection_confidence
>>> first_face.detection_confidence
0.9863683
>>> faces[0].joy_likelihood
>>> first_face.joy
0.54453093
>>> faces[0].anger_likelihood
>>> first_face.anger
0.02545464


Expand Down
70 changes: 55 additions & 15 deletions vision/google/cloud/vision/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,44 +101,44 @@ def from_api_repr(cls, response):
anger_likelihood)

@property
def joy_likelihood(self):
"""Likelihood of joy in detected face.
def anger(self):
"""Likelihood of anger in detected face.

:rtype: str
:returns: String derived from
:class:`~google.cloud.vision.face.Likelihood`.
"""
return self._joy_likelihood
return self._anger_likelihood

@property
def sorrow_likelihood(self):
"""Likelihood of sorrow in detected face.
def joy(self):
"""Likelihood of joy in detected face.

:rtype: str
:returns: String derived from
:class:`~google.cloud.vision.face.Likelihood`.
"""
return self._sorrow_likelihood
return self._joy_likelihood

@property
def surprise_likelihood(self):
"""Likelihood of surprise in detected face.
def sorrow(self):
"""Likelihood of sorrow in detected face.

:rtype: str
:returns: String derived from
:class:`~google.cloud.vision.face.Likelihood`.
"""
return self._surprise_likelihood
return self._sorrow_likelihood

@property
def anger_likelihood(self):
"""Likelihood of anger in detected face.
def surprise(self):
"""Likelihood of surprise in detected face.

:rtype: str
:returns: String derived from
:class:`~google.cloud.vision.face.Likelihood`.
"""
return self._anger_likelihood
return self._surprise_likelihood


class Face(object):
Expand Down Expand Up @@ -182,6 +182,16 @@ def from_api_repr(cls, response):
headwear_likelihood, image_properties, landmarks,
landmarking_confidence)

@property
def anger(self):
"""Accessor to likelihood that the detected face is angry.

:rtype: str
:returns: String derived from
:class:`~google.cloud.vision.face.Likelihood`.
"""
return self.emotions.anger

@property
def angles(self):
"""Accessor to the pan, tilt and roll angles of a Face.
Expand Down Expand Up @@ -230,7 +240,7 @@ def fd_bounds(self):
return self._fd_bounds

@property
def headwear_likelihood(self):
def headwear(self):
"""Headwear likelihood.

:rtype: :class:`~google.cloud.vision.face.Likelihood`
Expand All @@ -248,6 +258,16 @@ def image_properties(self):
"""
return self._image_properties

@property
def joy(self):
"""Likelihood of joy in detected face.

:rtype: str
:returns: String derived from
:class:`~google.cloud.vision.face.Likelihood`.
"""
return self.emotions.joy

@property
def landmarks(self):
"""Accessor to the facial landmarks detected in a face.
Expand All @@ -267,6 +287,26 @@ def landmarking_confidence(self):
"""
return self._landmarking_confidence

@property
def sorrow(self):
"""Likelihood of sorrow in detected face.

:rtype: str
:returns: String derived from
:class:`~google.cloud.vision.face.Likelihood`.
"""
return self.emotions.sorrow

@property
def surprise(self):
"""Likelihood of surprise in detected face.

:rtype: str
:returns: String derived from
:class:`~google.cloud.vision.face.Likelihood`.
"""
return self.emotions.surprise


class FaceImageProperties(object):
"""A representation of the image properties from face detection."""
Expand All @@ -289,7 +329,7 @@ def from_api_repr(cls, response):
return cls(blurred_likelihood, underexposed_likelihood)

@property
def blurred_likelihood(self):
def blurred(self):
"""Likelihood of the image being blurred.

:rtype: str
Expand All @@ -299,7 +339,7 @@ def blurred_likelihood(self):
return self._blurred_likelihood

@property
def underexposed_likelihood(self):
def underexposed(self):
"""Likelihood that the image used for detection was underexposed.

:rtype: str
Expand Down
14 changes: 7 additions & 7 deletions vision/unit_tests/test_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def test_face_landmarks(self):
def test_facial_emotions(self):
from google.cloud.vision.face import Likelihood
self.assertEqual(Likelihood.VERY_LIKELY,
self.face.emotions.joy_likelihood)
self.face.joy)
self.assertEqual(Likelihood.VERY_UNLIKELY,
self.face.emotions.sorrow_likelihood)
self.face.sorrow)
self.assertEqual(Likelihood.VERY_UNLIKELY,
self.face.emotions.surprise_likelihood)
self.face.surprise)
self.assertEqual(Likelihood.VERY_UNLIKELY,
self.face.emotions.anger_likelihood)
self.face.anger)

def test_faciale_angles(self):
self.assertEqual(-0.43419784, self.face.angles.roll)
Expand All @@ -60,11 +60,11 @@ def test_faciale_angles(self):
def test_face_headware_and_blur_and_underexposed(self):
from google.cloud.vision.face import Likelihood
self.assertEqual(Likelihood.VERY_UNLIKELY,
self.face.image_properties.blurred_likelihood)
self.face.image_properties.blurred)
self.assertEqual(Likelihood.VERY_UNLIKELY,
self.face.headwear_likelihood)
self.face.headwear)
self.assertEqual(Likelihood.VERY_UNLIKELY,
self.face.image_properties.underexposed_likelihood)
self.face.image_properties.underexposed)

def test_face_bounds(self):
self.assertEqual(4, len(self.face.bounds.vertices))
Expand Down