pythonpython-3.xdictionaryiogoogle-vision

How to call google vision legacy models?


I want to use the legacy text_detection and document_text_detection model. (refer: https://cloud.google.com/vision/docs/service-announcements) Im trying it this way using features:

import io
from google.cloud import vision

vision_client = vision.ImageAnnotatorClient()


with io.open("/mnt/d/snap.png", 'rb') as image_file:
    content = image_file.read()

image = vision.Image(content=content)


response = vision_client.document_text_detection(image=image)
# print(response) --> uses stable models, works fine



feature = vision.Feature(model="builtin/legacy")

response = vision_client.document_text_detection(image=image, features=feature)
# print(response) --> throws error show below

I'm getting the following error:

TypeError: dict() got multiple values for keyword argument 'features'

What am I doing wrong?


Solution

  • Try this:

    import io from google.cloud import vision
    
    vision_client = vision.ImageAnnotatorClient()
    
    with io.open("/mnt/d/snap.png", 'rb') as image_file:
        content = image_file.read()
    
    #image = vision.Image(content=content)
    
    response = vision_client.annotate_image({'image': {'content': content},'features': [{'type_': vision.Feature.Type.DOCUMENT_TEXT_DETECTION,'model': "builtin/legacy"}]})