コード例 #1
0
def _entity_from_response_type(feature_type, results):
    """Convert a JSON result to an entity type based on the feature.

    :rtype: list
    :returns: List containing any of
              :class:`~google.cloud.vision.entity.EntityAnnotation`,
              :class:`~google.cloud.vision.face.Face`

              or one of

              :class:`~google.cloud.vision.safe_search.SafeSearchAnnotation`,
              :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`.
    """
    detected_objects = []
    if feature_type == _FACE_ANNOTATIONS:
        detected_objects.extend(
            Face.from_api_repr(face) for face in results)
    elif feature_type == _IMAGE_PROPERTIES_ANNOTATION:
        return ImagePropertiesAnnotation.from_api_repr(results)
    elif feature_type == _SAFE_SEARCH_ANNOTATION:
        return SafeSearchAnnotation.from_api_repr(results)
    else:
        for result in results:
            detected_objects.append(EntityAnnotation.from_api_repr(result))
    return detected_objects
コード例 #2
0
def _entity_from_response_type(feature_type, results):
    """Convert a JSON result to an entity type based on the feature."""

    detected_objects = []
    feature_key = _REVERSE_TYPES[feature_type]

    if feature_type == _FACE_DETECTION:
        detected_objects.extend(
            Face.from_api_repr(face) for face in results[feature_key])
    elif feature_type == _IMAGE_PROPERTIES:
        detected_objects.append(
            ImagePropertiesAnnotation.from_api_repr(results[feature_key]))
    elif feature_type == _SAFE_SEARCH_DETECTION:
        result = results[feature_key]
        detected_objects.append(SafeSearchAnnotation.from_api_repr(result))
    else:
        for result in results[feature_key]:
            detected_objects.append(EntityAnnotation.from_api_repr(result))
    return detected_objects
コード例 #3
0
def _entity_from_response_type(feature_type, results):
    """Convert a JSON result to an entity type based on the feature.

    :rtype: list
    :returns: List containing any of
              :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`,
              :class:`~google.cloud.vision.entity.EntityAnnotation`,
              :class:`~google.cloud.vision.face.Face`,
              :class:`~google.cloud.vision.safe.SafeSearchAnnotation`.
    """
    detected_objects = []
    if feature_type == _FACE_ANNOTATIONS:
        detected_objects.extend(Face.from_api_repr(face) for face in results)
    elif feature_type == _IMAGE_PROPERTIES_ANNOTATION:
        detected_objects.append(ImagePropertiesAnnotation.from_api_repr(results))
    elif feature_type == _SAFE_SEARCH_ANNOTATION:
        detected_objects.append(SafeSearchAnnotation.from_api_repr(results))
    else:
        for result in results:
            detected_objects.append(EntityAnnotation.from_api_repr(result))
    return detected_objects
コード例 #4
0
ファイル: image.py プロジェクト: jonparrott/gcloud-python
    def _detect_annotation(self, feature):
        """Generic method for detecting a single annotation.

        :type feature: :class:`~google.cloud.vision.feature.Feature`
        :param feature: The ``Feature`` indication the type of annotation to
                        perform.

        :rtype: list
        :returns: List of
                  :class:`~google.cloud.vision.entity.EntityAnnotation`.
        """
        reverse_types = {
            'LABEL_DETECTION': 'labelAnnotations',
            'LANDMARK_DETECTION': 'landmarkAnnotations',
            'LOGO_DETECTION': 'logoAnnotations',
            'TEXT_DETECTION': 'textAnnotations',
        }
        detected_objects = []
        result = self.client.annotate(self, [feature])
        for response in result[reverse_types[feature.feature_type]]:
            detected_object = EntityAnnotation.from_api_repr(response)
            detected_objects.append(detected_object)
        return detected_objects
コード例 #5
0
    def _detect_annotation(self, feature):
        """Generic method for detecting a single annotation.

        :type feature: :class:`~google.cloud.vision.feature.Feature`
        :param feature: The ``Feature`` indication the type of annotation to
                        perform.

        :rtype: list
        :returns: List of
                  :class:`~google.cloud.vision.entity.EntityAnnotation`.
        """
        reverse_types = {
            'LABEL_DETECTION': 'labelAnnotations',
            'LANDMARK_DETECTION': 'landmarkAnnotations',
            'LOGO_DETECTION': 'logoAnnotations',
            'TEXT_DETECTION': 'textAnnotations',
        }
        detected_objects = []
        result = self.client.annotate(self, [feature])
        for response in result[reverse_types[feature.feature_type]]:
            detected_object = EntityAnnotation.from_api_repr(response)
            detected_objects.append(detected_object)
        return detected_objects