using google storage and google vision API

Refresh

5 weeks ago

Views

3 time

0

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 google.cloud 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
    print('Texts:')

    for text in texts:
        print('\n"{}"'.format(text.description))

        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 :

detect_text_uri('https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Transparent_Electricity_Meter_found_in_Israel.JPG/220px-Transparent_Electricity_Meter_found_in_Israel.JPG')

0 answers