Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Vision API 'Request Admission Denied'

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);
}
like image 588
Vaibhav Singh Avatar asked Jun 13 '16 18:06

Vaibhav Singh


2 Answers

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.

like image 66
seadragon Avatar answered Sep 22 '22 21:09

seadragon


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'))
like image 37
James Avatar answered Sep 25 '22 21:09

James