-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add image.detect() for detecting multiple types. #2770
Add image.detect() for detecting multiple types. #2770
Conversation
5c6485d
to
74eef27
Compare
Bumpidy bump bump. |
================== | ||
|
||
Image Annotations | ||
~~~~~~~~~~~~~~~~~ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self.assertEqual(items.labels[2].description, 'truck') | ||
self.assertEqual(items.labels[2].score, 0.88429511) | ||
|
||
image_request = client._connection._requested[0]['data']['requests'][0] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
from google.cloud.vision.feature import FeatureTypes | ||
from unit_tests._fixtures import LABEL_DETECTION_RESPONSE | ||
from unit_tests._fixtures import LOGO_DETECTION_RESPONSE | ||
RETURNED = LABEL_DETECTION_RESPONSE |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
from unit_tests._fixtures import LOGO_DETECTION_RESPONSE | ||
RETURNED = LABEL_DETECTION_RESPONSE | ||
LOGOS = LOGO_DETECTION_RESPONSE['responses'][0]['logoAnnotations'] | ||
RETURNED['responses'][0]['logoAnnotations'] = LOGOS |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
from google.cloud.vision.entity import EntityAnnotation | ||
from google.cloud.vision.face import Face | ||
from google.cloud.vision.feature import FeatureTypes | ||
from google.cloud.vision.color import ImagePropertiesAnnotation |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
for feature_type, annotation in response.items(): | ||
annotations[feature_type].extend( | ||
_entity_from_response_type(feature_type, annotation)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
texts = annotations.get( | ||
_REVERSE_TYPES[FeatureTypes.TEXT_DETECTION], []) | ||
|
||
return cls(faces=faces, properties=properties, labels=labels, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
def _entity_from_response_type(feature_type, results): | ||
"""Convert a JSON result to an entity type based on the feature.""" | ||
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
|
||
def _entity_from_response_type(feature_type, results): | ||
"""Convert a JSON result to an entity type based on the feature.""" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
"""Convert a JSON result to an entity type based on the feature.""" | ||
|
||
detected_objects = [] | ||
if feature_type == _REVERSE_TYPES[FeatureTypes.FACE_DETECTION]: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Great feedback! I was able to remove a good chunk of code from your suggestions. |
2da9e85
to
a720bff
Compare
Rebased to get rid of the conflict. |
""" | ||
def __init__(self, faces=None, properties=None, labels=None, | ||
landmarks=None, logos=None, safe_searches=None, texts=None): | ||
self.faces = faces or () |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
'logoAnnotations': 'logos', | ||
'safeSearchAnnotation': 'safe_searches', | ||
'textAnnotations': 'texts' | ||
} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
:class:`~google.cloud.vision.safe.SafeSearchAnnotation`. | ||
""" | ||
detected_objects = [] | ||
if feature_type == 'faceAnnotations': |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
IMAGE_PROPERTIES_ANNOTATION = 'imagePropertiesAnnotation' | ||
SAFE_SEARCH_ANNOTATION = 'safeSearchAnnotation' | ||
|
||
KEY_MAP = { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after nit
…ant, make duplicated response keys constants.
ec99e2f
to
52aaf05
Compare
Travis went green so I'm merging. |
@@ -21,6 +21,21 @@ | |||
from google.cloud.vision.safe import SafeSearchAnnotation | |||
|
|||
|
|||
FACE_ANNOTATIONS = 'faceAnnotations' | |||
IMAGE_PROPERTIES_ANNOTATION = 'imagePropertiesAnnotation' | |||
SAFE_SEARCH_ANNOTATION = 'safeSearchAnnotation' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
…to-vision-2697 Add image.detect() for detecting multiple types.
…2697 Add image.detect() for detecting multiple types.
Closes #2697, #2769