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

Add image.detect() for detecting multiple types. #2770

Merged

Conversation

daspecster
Copy link
Contributor

@daspecster daspecster commented Nov 24, 2016

Closes #2697, #2769

@daspecster daspecster added the api: vision Issues related to the Cloud Vision API. label Nov 24, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 24, 2016
@daspecster daspecster force-pushed the add-manual-detect-to-vision-2697 branch from 5c6485d to 74eef27 Compare November 24, 2016 16:06
@daspecster daspecster mentioned this pull request Nov 28, 2016
10 tasks
@daspecster
Copy link
Contributor Author

Bumpidy bump bump.

==================

Image Annotations
~~~~~~~~~~~~~~~~~

This comment was marked as spam.

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.

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.

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.

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.


for feature_type, annotation in response.items():
annotations[feature_type].extend(
_entity_from_response_type(feature_type, annotation))

This comment was marked as spam.

texts = annotations.get(
_REVERSE_TYPES[FeatureTypes.TEXT_DETECTION], [])

return cls(faces=faces, properties=properties, labels=labels,

This comment was marked as spam.


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.



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.

"""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.

@daspecster
Copy link
Contributor Author

Great feedback!

I was able to remove a good chunk of code from your suggestions.

@daspecster daspecster force-pushed the add-manual-detect-to-vision-2697 branch from 2da9e85 to a720bff Compare November 29, 2016 21:29
@daspecster
Copy link
Contributor Author

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.

'logoAnnotations': 'logos',
'safeSearchAnnotation': 'safe_searches',
'textAnnotations': 'texts'
}

This comment was marked as spam.

:class:`~google.cloud.vision.safe.SafeSearchAnnotation`.
"""
detected_objects = []
if feature_type == 'faceAnnotations':

This comment was marked as spam.

IMAGE_PROPERTIES_ANNOTATION = 'imagePropertiesAnnotation'
SAFE_SEARCH_ANNOTATION = 'safeSearchAnnotation'

KEY_MAP = {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor

@dhermes dhermes left a 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.
@daspecster daspecster force-pushed the add-manual-detect-to-vision-2697 branch from ec99e2f to 52aaf05 Compare November 30, 2016 03:14
@daspecster
Copy link
Contributor Author

Travis went green so I'm merging.

@daspecster daspecster merged commit 5cbbcb9 into googleapis:master Nov 30, 2016
@daspecster daspecster deleted the add-manual-detect-to-vision-2697 branch November 30, 2016 03:31
@@ -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.

richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
…to-vision-2697

Add image.detect() for detecting multiple types.
parthea pushed a commit that referenced this pull request Oct 21, 2023
…2697

Add image.detect() for detecting multiple types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: vision Issues related to the Cloud Vision API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants