Zekun
Zekun

Reputation: 375

Google Cloud Vision API "Bad image data" error

I'm using google cloud vision API trying to detect text from maps. The image size I'm processing is less than 20MB and it is stored in cloud storage. When I run the document_text_detection API, some of the images lead to the following error (some were processed successfully)

Something went wrong with the Vision API:code: 3 message: "Bad image data"

I wonder what could be the reason? I tried convert the jpeg file to png format and then convert back. The image that is problematic is here.

Any suggestions would be appreciated.

Upvotes: 5

Views: 5754

Answers (3)

jrmgx
jrmgx

Reputation: 729

It is also possible that the file resolution is too important, even if it is less than 20Mo

File info: JPEG image data, JFIF standard 1.01, 
resolution (DPI), density 300x300, 
segment length 16, baseline, precision 8, 
10334x14326, components 3

File size: 3.5Mo

The image resolution is 10_334 x 14_326
and this image is failing with the error {"error":{"code":3,"message":"Bad image data."}}

Upvotes: 0

Lauri Harpf
Lauri Harpf

Reputation: 1488

Another situation that can cause the "Bad image data" error is using the "Authenticated URL" instead of the URI or the "Public URL" of the resource. Don't know why that happens, just ran across it exploring the Using API Explorer tutorial of the Cloud Vision API.

Likely unrelated to your situation, posting this for the benefit of those who hit the same problem and end up here after searching for a solution.

Upvotes: 2

Zekun
Zekun

Reputation: 375

Seems like converting jpg files to png format could do the trick. The only problem is that the png file might be too big for the API to accept. In this case, I managed to reduced the image size by either lowering the image quality or shrink the image to smaller width and height.

Upvotes: 1

Related Questions