Esempio n. 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
Esempio n. 2
0
def _make_image_properties_from_pb(image_properties):
    """Create ``ImageProperties`` object from a protobuf response.

    :type image_properties: :class:`~google.cloud.grpc.vision.v1.\
                            image_annotator_pb2.ImagePropertiesAnnotation`
    :param image_properties: Protobuf instance of
                             ``ImagePropertiesAnnotation``.

    :rtype: list or ``None``
    :returns: List of ``ImageProperties`` or ``None``.
    """
    return ImagePropertiesAnnotation.from_pb(image_properties)
Esempio n. 3
0
    def detect_properties(self, limit=10):
        """Detect the color properties of an image.

        :type limit: int
        :param limit: The maximum number of image properties to find.

        :rtype: list
        :returns: List of
                  :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`.
        """
        feature = Feature(FeatureTypes.IMAGE_PROPERTIES, limit)
        result = self.client.annotate(self, [feature])
        response = result['imagePropertiesAnnotation']
        return ImagePropertiesAnnotation.from_api_repr(response)
Esempio n. 4
0
    def detect_properties(self, limit=10):
        """Detect the color properties of an image.

        :type limit: int
        :param limit: The maximum number of image properties to find.

        :rtype: list
        :returns: List of
                  :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`.
        """
        feature = Feature(FeatureTypes.IMAGE_PROPERTIES, limit)
        result = self.client.annotate(self, [feature])
        response = result['imagePropertiesAnnotation']
        return ImagePropertiesAnnotation.from_api_repr(response)
Esempio n. 5
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
Esempio n. 6
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