Google Vision API text detection strange behaviour - Javascript

前提是你 提交于 2019-11-29 11:32:32

I had the same issue. For me, (I don't know why, but...) changing from TEXT_DETECTION to DOCUMENT_TEXT_DETECTION solved the issue. Now the results received from the API are the same seen when I upload the image on Google Vision page.

I had a similar issue.

The Google Cloud Vision API says that the "OCR automaticly detects latin charatecrs, but sometimes it can fail" or have a strange behavior. The API also says that you can add a parameter to help the ocr to detect better the text, giving a context to the image.

You have to add the following code to the request.

"imageContext": {
        "languageHints": [
          "en"
        ]
 }

The result should look like this:

{
  "requests": [
    {
      "image": {
            content: imageData.split(',')[1]
      },
      "features": [{
            type: 'TEXT_DETECTION',
            maxResults:50
        }],
      "imageContext": {
        "languageHints": [
          "en"
        ]
      }
    }
  ]
}

Note that language Hints its an array, so you can add more languages, to give the OCR, precisely, a hint.

You can read more: https://cloud.google.com/vision/docs/reference/rest/v1/images/annotate#imagecontext

This helped me to don't get strange characters.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!