Detect multiple objects in a Cloud Storage file (beta)

Perform object detection for multiple objects in an image on a file stored in Cloud Storage (for beta launch).

Code sample


Before trying this sample, follow the Python setup instructions in the Vision quickstart using client libraries. For more information, see the Vision Python API reference documentation.

def localize_objects_uri(uri):
    """Localize objects in the image on Google Cloud Storage

    uri: The path to the file in Google Cloud Storage (gs://...)
    from import vision_v1p3beta1 as vision
    client = vision.ImageAnnotatorClient()

    image = vision.Image()
    image.source.image_uri = uri

    objects = client.object_localization(

    print('Number of objects found: {}'.format(len(objects)))
    for object_ in objects:
        print('\n{} (confidence: {})'.format(, object_.score))
        print('Normalized bounding polygon vertices: ')
        for vertex in object_.bounding_poly.normalized_vertices:
            print(' - ({}, {})'.format(vertex.x, vertex.y))

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser