Python code for "builtin/legacy" like sequence using New OCR model ( "legacy_layout" value for the advanced_ocr_options)

112 views
Skip to first unread message

Rahul

unread,
Aug 26, 2022, 12:24:18 PM8/26/22
to cloud-vision-discuss


image = vision.Image(content=img_obj)
response1 = vision.AnnotateImageRequest(image=image, features=[{'type_': vision.Feature.Type.DOCUMENT_TEXT_DETECTION, 'model': "builtin/legacy"}], image_context={"text_detection_params": {"advanced_ocr_options": ["legacy_layout"]}})
response = client.annotate_image(response1)

texts = response.text_annotations

s_g

unread,
Aug 26, 2022, 2:12:35 PM8/26/22
to cloud-vision-discuss
Thanks for contributing to the community! 

Tianli Yu

unread,
Sep 2, 2022, 6:17:50 PM9/2/22
to cloud-vision-discuss
Thanks for the code snippet. One thing to clarify, since the legacy_layout advanced_ocr_option is implemented on the current stable model ONLY (builtin/legacy does not need it anyway), one could omit the "model" parameter in the code:

image = vision.Image(content=img_obj)
response1 = vision.AnnotateImageRequest(image=image, features=[{'type_': vision.Feature.Type.DOCUMENT_TEXT_DETECTION}], image_context={"text_detection_params": {"advanced_ocr_options": ["legacy_layout"]}})

response = client.annotate_image(response1)

texts = response.text_annotations

The reason why the code in the original post still works is because the API ignores builtin/legacy and default it to the builtin/stable model after Aug 20.
Reply all
Reply to author
Forward
0 new messages