3

I am using vision api to extract text (document_text_detection) in my project for last two year and never faced this issue. Since yesterday the api is randomly responding with the error :

{ code: 3 message: "Invalid language hints." }

for the same image. I experimented with bunch of images, sometimes the api extracts text fine and sometimes throws "Invalid language hints" error for a same image.

I have tried updating vision api library from v1 to v2, sending language hints as 'en' still the same issue persist. I have looked into the Google documentation and checked StackOverFlow as well but unable to find any solution.

from google.cloud import vision
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = google_cred_file


vision_client = vision.ImageAnnotatorClient()
file = open(file_path,"rb")
image = vision.Image(content=file.read())

api_resp = vision_client.document_text_detection(image=image)
if api_resp.error.message:
    log.error(api_resp)
  • `Text detection returns an error if one or more of the specified languages is not one of the supported languages.` Have you read this? It seems that you have provided the wrong languages in your request! https://cloud.google.com/vision/docs/ocr – Mohamad Ghaith Alzin May 13 '22 at 05:14
  • 1
    I'm not sending any language hints in general as documentations itself suggests. `Both types of OCR requests support one or more languageHints that specify the language of any text in the image. However, in most cases, an empty value yields the best results since it enables automatic language detection.` Used language hints when I encounter this issue, as an experiment and 'en' is supported by vision api. – Manoj Kumar May 13 '22 at 05:23
  • 1
    We have the same issue on our side last 2-3 days, and we don't send any language as well. But we are using Java API for Google Vision. – Michael May 13 '22 at 07:07
  • 1
    I have tried running your image using the guide provided by @MohamadGhaithAlzin and it worked for me. See this screenshot for your reference https://i.imgur.com/3O6W3Oe.png. Can you try it on your end as well? – Scott B May 13 '22 at 09:29
  • 1
    @ManojKumar I had to implement a workaround as well to retry failed image requests to Google Vision API and sometimes first retry is enough or only from third I'm receiving successful response... – Michael May 13 '22 at 10:15
  • @ScottB Yes, It does work most of the time. I find that error rate is around 20%, tried same image at least 20 times, and, I have experimented with several images, got same kinda results. Also I have observed that mostly the vision api breaks for new images (not processed before). – Manoj Kumar May 13 '22 at 10:16
  • @Michael Yes, I'm also using a loop with three retries, still fails for some of the images. The overall latency has gone up, though. – Manoj Kumar May 13 '22 at 10:24
  • We had the same issue, at some point retrying didn't even work anymore, and the error was much more common. I guess when the rollout of a broken version was 100%. I have reported the issue to Google, they have aknowledged it and started rolling out a fix yesterday. They also report it on their status page: https://status.cloud.google.com/ they expect the rollout of the fix to be complete on monday. – jerbob92 May 14 '22 at 18:38

2 Answers2

0

@Manoj kumar - I tried to run code on my system with your image , I made change in one line and it executed successfully. Please find below.

enter image description here

Vishal Bulbule
  • 313
  • 1
  • 7
  • 1
    You didn't really change anything to the code, it's just that the error does not occur 100% of the time which caused it to work for you. Google is rolling out the fix and it's expected to be complete on Monday. We see the error way less in our logs already. – jerbob92 May 15 '22 at 20:24
0

I am part of Google Cloud Platform Support and the issue with Cloud Vision has been resolved for all affected users as of Monday, 2022-05-16 10:00 US/Pacific.

The issue is also removed from the Google Cloud Service Health page.

You may now try the Detect text Vision API Quickstart or try your own code.

Scott B
  • 2,516
  • 1
  • 8
  • 15