예제 #1
0
    def annotate(self, images):
        """Annotate images through GAX.

        :type images: list
        :param images: List containing pairs of
                       :class:`~google.cloud.vision.image.Image` and
                       :class:`~google.cloud.vision.feature.Feature`.
                       e.g. [(image, [feature_one, feature_two]),]

        :rtype: list
        :returns: List of
                  :class:`~google.cloud.vision.annotations.Annotations`.
        """
        requests = []
        for image, features in images:
            gapic_features = [
                _to_gapic_feature(feature) for feature in features
            ]
            gapic_image = _to_gapic_image(image)
            request = image_annotator_pb2.AnnotateImageRequest(
                image=gapic_image, features=gapic_features)
            requests.append(request)

        annotator_client = self._annotator_client
        responses = annotator_client.batch_annotate_images(requests).responses
        return [Annotations.from_pb(response) for response in responses]
예제 #2
0
    def annotate(self, image, features):
        """Annotate images through GAX.

        :type image: :class:`~google.cloud.vision.image.Image`
        :param image: Instance of ``Image``.

        :type features: list
        :param features: List of :class:`~google.cloud.vision.feature.Feature`.

        :rtype: list
        :returns: List of
                  :class:`~google.cloud.vision.annotations.Annotations`.
        """
        gapic_features = [_to_gapic_feature(feature) for feature in features]
        gapic_image = _to_gapic_image(image)
        request = image_annotator_pb2.AnnotateImageRequest(
            image=gapic_image, features=gapic_features)
        requests = [request]
        annotator_client = self._annotator_client
        responses = annotator_client.batch_annotate_images(requests).responses
        return [Annotations.from_pb(response) for response in responses]
예제 #3
0
    def annotate(self, image, features):
        """Annotate images through GAX.

        :type image: :class:`~google.cloud.vision.image.Image`
        :param image: Instance of ``Image``.

        :type features: list
        :param features: List of :class:`~google.cloud.vision.feature.Feature`.

        :rtype: :class:`~google.cloud.vision.annotations.Annotations`
        :returns: Instance of ``Annotations`` with results or ``None``.
        """
        gapic_features = [_to_gapic_feature(feature) for feature in features]
        gapic_image = _to_gapic_image(image)
        request = image_annotator_pb2.AnnotateImageRequest(
            image=gapic_image, features=gapic_features)
        requests = [request]
        annotator_client = self._annotator_client
        images = annotator_client.batch_annotate_images(requests)
        if len(images.responses) == 1:
            return Annotations.from_pb(images.responses[0])
        elif len(images.responses) > 1:
            raise NotImplementedError(
                'Multiple image processing is not yet supported.')
예제 #4
0
"""Functional test for Google Cloud Vision API."""

from google.cloud.gapic.vision.v1.image_annotator_api import ImageAnnotatorApi
from google.cloud.grpc.vision.v1 import image_annotator_pb2

# point this at an image for your project
image_url = 'gs://gapic-vision-v1/demo-image.jpg'

api = ImageAnnotatorApi()
image_source = image_annotator_pb2.ImageSource(gcs_image_uri = image_url)
image = image_annotator_pb2.Image(source = image_source)

feature = image_annotator_pb2.Feature(type = image_annotator_pb2.Feature.LABEL_DETECTION)
features = [feature]

request = image_annotator_pb2.AnnotateImageRequest(image = image, features = features)
requests = [request]
response = api.batch_annotate_images(requests)

print response.__str__