python-docs-samples icon indicating copy to clipboard operation
python-docs-samples copied to clipboard

How to change google ocr model?

Open Hyeoghwan opened this issue 1 year ago • 1 comments

Here is my code

from google.cloud import vision
client = vision.ImageAnnotatorClient()
with open(...) as f:
  content = f.read()
image = vision.Image(content=content)
response = client.document_text_detection(image=image)

I have to get the same format of the document_text_detection method. and have to change the model to test. from "builtin/stable" to "builtin/latest"

I tried like that.

vision.ImageAnnotatorClient.Feature.model = "builtin/latest"
client = vision.ImageAnnotatorClient()

But it doesn't seem to work. from what I have searched for, change the reqeust is the one way to do that. like,

image = vision.Image(content=content)
feature = vision.Feature(type=vision.Feature.Type.TEXT_DETECTION, model="builtin/latest")
request = vision.AnnotateImageRequest(image=image, features=[feature])

...

ocr_text_obj = self.client.annotate_image(request, retry=self.google_retry, timeout=timeout_sec)

but, the return format of the self.client.annotate_image is not what I want. So, I just want to change the feature and to use document_text_detection. How to do that?

Hyeoghwan avatar Jan 16 '24 06:01 Hyeoghwan