-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Refactor _detect_annotation() to support all annotation types. #2712
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
Refactor _detect_annotation() to support all annotation types. #2712
Conversation
51433d6 to
7d4a998
Compare
7d4a998 to
e766ac9
Compare
dhermes
left a comment
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.
Mostly LGTM though ISTM you should be doing
features = [feature]in _detect_annotation
vision/google/cloud/vision/image.py
Outdated
| :type feature: :class:`~google.cloud.vision.feature.Feature` | ||
| :param feature: The ``Feature`` indication the type of annotation to | ||
| perform. | ||
| :type features: list of:class:`~google.cloud.vision.feature.Feature` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| return self._source | ||
|
|
||
| def _detect_annotation(self, feature): | ||
| def _detect_annotation(self, features): |
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.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/google/cloud/vision/image.py
Outdated
| """Convert a JSON result to an entity type based on the feature.""" | ||
|
|
||
| reverse_types = { | ||
| 'FACE_DETECTION': 'faceAnnotations', |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/google/cloud/vision/image.py
Outdated
| return detected_objects[0] | ||
| return detected_objects | ||
|
|
||
| @staticmethod |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/google/cloud/vision/image.py
Outdated
| self._entity_from_response_type(feature.feature_type, results)) | ||
|
|
||
| if len(detected_objects) == 1: | ||
| return detected_objects[0] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/google/cloud/vision/image.py
Outdated
| result = results[feature_key] | ||
| detected_objects.append(SafeSearchAnnotation.from_api_repr(result)) | ||
| else: | ||
| for result in results[feature_key]: |
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.
vision/google/cloud/vision/image.py
Outdated
| detected_objects.append(detected_object) | ||
| feature_key = reverse_types[feature_type] | ||
|
|
||
| if feature_type == 'FACE_DETECTION': |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/google/cloud/vision/image.py
Outdated
|
|
||
| if feature_type == 'FACE_DETECTION': | ||
| for face in results[feature_key]: | ||
| detected_objects.append(Face.from_api_repr(face)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vision/google/cloud/vision/image.py
Outdated
| detected_objects.append(SafeSearchAnnotation.from_api_repr(result)) | ||
| else: | ||
| for result in results[feature_key]: | ||
| detected_objects.append(EntityAnnotation.from_api_repr(result)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Regarding your comment about if not isinstance(features, list):
features = [features] |
| 'LOGO_DETECTION': 'logoAnnotations', | ||
| _SAFE_SEARCH_DETECTION: 'safeSearchAnnotation', | ||
| 'TEXT_DETECTION': 'textAnnotations', | ||
| } |
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.
No, just make your callers obey the signature. So if it accepts one feature (which all the current callers so) then they send one feature. However, as I mentioned before, just leave the change in. |
1bfd25f to
f164c3f
Compare
|
Squished. Once the build goes green I'll merge. |
f164c3f to
83b128a
Compare
…quests Refactor _detect_annotation() to support all annotation types.
Refactor _detect_annotation() to support all annotation types.
This is a step towards adding the manual detect method.
See: #2697