Exemple #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
Exemple #2
0
def _make_safe_search_from_pb(safe_search):
    """Create ``SafeSearchAnnotation`` object from a protobuf response.

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

    :rtype: :class: `~google.cloud.vision.safe_search.SafeSearchAnnotation`
    :returns: Instance of ``SafeSearchAnnotation``.
    """
    return SafeSearchAnnotation.from_pb(safe_search)