0

I am trying to extract text data from images using Google Cloud Vision API. My Initial starting point was here After Enabling Vision API and Creating service account,generating json file, I created a script by referring this example.

Here's my code

from google.cloud import vision
from google.cloud.vision_v1 import types
import os

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'generated_after_creating_sec_key.json'
image_path = 'images\\image_1.png'
vision_client = vision.ImageAnnotatorClient()
print(vision_client)
image = types.Image()
image.source.image_path = image_path

response = vision_client.text_detection(image=image)
for text in response.text_annotations:
    print(text.description)

The only difference between the example shown in google page and my code is that the image uploaded in the example is on gcloud while mine happens to be on local storage.

Here's the complete stacktrace.

<google.cloud.vision_v1.ImageAnnotatorClient object at 0x000001DF861D7970>
Traceback (most recent call last):
  File "text_detection.py", line 10, in <module>
    image.source.image_path = image_path
  File "C:\Users\user\ProjectFolder\ProjName\venv\lib\site-packages\proto\message.py", line 677, in __setattr__
    pb_type = self._meta.fields[key].pb_type
KeyError: 'image_path'

What is the root cause of this error? Please help!

2 Answers 2

2

Per the Google Cloud Vision docs, you want image.source.image_uri instead.

Sign up to request clarification or add additional context in comments.

Comments

1

According to the Google Cloud Vision docs, you should use image.source.image_uri instead.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.