Esempio n. 1
0
def _to_gapic_image(image):
    """Helper function to convert an ``Image`` to a gRPC ``Image``.

    :type image: :class:`~google.cloud.vision.image.Image`
    :param image: Local ``Image`` class to be converted to gRPC ``Image``.

    :rtype: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.Image`
    :returns: gRPC ``Image`` converted from
              :class:`~google.cloud.vision.image.Image`.
    """
    if image.content is not None:
        return image_annotator_pb2.Image(content=image.content)
    if image.source is not None:
        return image_annotator_pb2.Image(
            source=image_annotator_pb2.ImageSource(
                gcs_image_uri=image.source), )
    raise ValueError('No image content or source found.')
Esempio n. 2
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__