Google Cloud Vision API 'Request Admission Denied'
Asked Answered
Z

4

5

I am new to Google Cloud Vision API. I am doing OCR on images primarily for bills and receipts.

For a few images it is working fine, but when I try some other images it gives me this error:

Error:  { [Error: Request Admission Denied.]
  code: 400,
  errors:
   [ { message: 'Request Admission Denied.',
       domain: 'global',
       reason: 'badRequest' } ] }

This is my code:

// construct parameters
const req = new vision.Request({
image: new vision.Image('./uploads/reciept.png'),
features: [
new vision.Feature('TEXT_DETECTION', 1)
]
})

vision.annotate(req).then((res) => {
// handling response
//console.log(res.responses[0].textAnnotations);
var desc=res.responses[0].textAnnotations;
var descarr=[];
for (i = 0; i < desc.length; i++) { 
descarr.push(desc[i].description);
}
Zion answered 13/6, 2016 at 18:38 Comment(1)
Are you receiving this error when OCRing specific images? Can you keep doing OCR the same image several times to see if the issue is related to image specification or API itself?Verdin
M
6

Ran into this problem as well. It was an image size issue. I don't know what the hard limit is. 4MB worked, but 9MB didn't, it's somewhere in between there.

Milburt answered 30/6, 2016 at 19:47 Comment(2)
According to cloud.google.com/vision/docs/image-best-practices#file_sizes the max file size is 4MB, the max request size is 8MBDulles
Yep, this fixed it for me (resizing the image). It'd be good if they added a more informative error message.Doughman
K
1

I was able to work around this by saving the image as another format and submitting that instead; there was something "wrong" (or at least, unexpected by Google) with the image file itself. Not sure about image manipulation in the language you're using (js?), but in Python it was as simple as:

from PIL import Image
bad_image = Image.open(open('failure.jpg', 'rb'))
bad_image.save(open('success.png', 'wb'))
Kurgan answered 15/6, 2016 at 21:57 Comment(2)
I am using JS . Did your work also involve extracting information out of raw text?Zion
That's what I'm trying to do more broadly, though I don't think it was relevant to the particular image that encountered this error. There was nothing visually unique about the image that encountered this error compared to images that succeeded.Kurgan
N
1

The Best Practices doc says that the image file size should not exceed 4 MB. Based on this responses above, this could be the problem.

Nasia answered 16/8, 2016 at 14:5 Comment(0)
E
0

Interesting. I ran into the same problem today, using Google's Java client. The way I read James' answer, he had a JPEG file that failed, but worked as a PNG file. In my case, I had a PNG file that failed, but worked as a JPEG.

I had concluded it was a size limitation, as I'd expect JPEGs to be typically smaller than PNGs; however, James' experience suggests otherwise.

I couldn't find any relevant documentation in Google's Javadocs. Since the response is a 400 error, perhaps the Java library is not encoding the image buffer correctly.

Emaciated answered 24/6, 2016 at 18:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.