Skip to content

Vision - Cannot pass ImageContext parameter to document_text_detection #6387

@sheshkovsky

Description

@sheshkovsky

I want to pass languageHints parameter to document_text_detection or (client.annotate_image) as described here but I get error with following Traceback:

  File ".../virtual/lib/python3.6/site-packages/google/protobuf/internal/python_message.py", line 545, in _GetFieldByName
    return message_descriptor.fields_by_name[field_name]
KeyError: 'imageContext'

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File ".../common/google_vision.py", line 55, in ocr_by_vision
    resp = client.document_text_detection(image=image, imageContext={"languageHints": ["it"]})
  File ".../virtual/lib/python3.6/site-packages/google/cloud/vision_helpers/decorators.py", line 111, in inner
    response = self.annotate_image(request, retry=retry, timeout=timeout)
  File ".../virtual/lib/python3.6/site-packages/google/cloud/vision_helpers/__init__.py", line 67, in annotate_image
    r = self.batch_annotate_images([request], retry=retry, timeout=timeout)
  File ".../virtual/lib/python3.6/site-packages/google/cloud/vision_v1/gapic/image_annotator_client.py", line 218, in batch_annotate_images
    requests=requests, )
  File ".../virtual/lib/python3.6/site-packages/google/protobuf/internal/python_message.py", line 503, in init
    copy.add(**val)
  File ".../virtual/lib/python3.6/site-packages/google/protobuf/internal/containers.py", line 372, in add
    new_element = self._message_descriptor._concrete_class(**kwargs)
  File ".../virtual/lib/python3.6/site-packages/google/protobuf/internal/python_message.py", line 484, in init
    field = _GetFieldByName(message_descriptor, field_name)
  File ".../virtual/lib/python3.6/site-packages/google/protobuf/internal/python_message.py", line 548, in _GetFieldByName
    (message_descriptor.name, field_name))
ValueError: Protocol message AnnotateImageRequest has no "imageContext" field.

To reproduce I tried :

from google.cloud import vision
from google.cloud.vision import types as vision_types

path = '/tmp/0.jpg'
client = vision.ImageAnnotatorClient()
with open(path, 'rb') as image_file:
    content = image_file.read()
image = vision_types.Image(content=content)
resp = client.document_text_detection(image=image, imageContext={"languageHints": ["it"]})

or

req = {
    "image": {"source": {'filename': path}},
    "features": [
        {"type": 1},
    ],
    "imageContext": {
        "languageHints": ["it"]
    }
}
resp = client.annotate_image(request=req)

Python Version: 3.6.4
google-cloud-vision Version: 0.34.0
OS: MacOS 10.14

Is there anyway to pass imageContext optional parameters? (I guess some fix like this is needed)

Metadata

Metadata

Assignees

Labels

api: visionIssues related to the Cloud Vision API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions