using google storage and google vision API


5 weeks ago


3 time


I have the follow function that passes a image url to google vision service and returns the letters and numbers (characters) in the image. It works fine with general web urls but I'm calling it to access files stored in Google storage, it doesn't work. How can i get this to work? I've looked at examples from googling but I cant work out how to do this?

If its not possible to use google storage, is there a way you can just upload the image rather than storing in on a file system? I have no need for storing the image, all i care about is the returned characters.

def detect_text_uri(uri):
    """Detects text in the file located in Google Cloud Storage or on the Web.
    from import vision
    client = vision.ImageAnnotatorClient()
    image = vision.types.Image()
    image.source.image_uri = uri
    image.source.gcs_image_uri = uri

    response = client.text_detection(image=image)
    texts = response.text_annotations

    for text in texts:

        vertices = (['({},{})'.format(vertex.x, vertex.y)
                    for vertex in text.bounding_poly.vertices])

        print('bounds: {}'.format(','.join(vertices)))
    return texts

This line doesn't work which should read an image I've placed in google storage, all thats returned is a blank responce:

detect_text_uri("'source': {'image_uri': 'gs://ocr_storage/meter_reader.jpg'}")

This line works fine :


0 answers