I'm using the Google Text detection API for performing OCR on images.
I've found that my OCR results are much better when I perform some pre-processing on the images using opencv.
My question is - how can I call the Google cloud Vision API's on images I have in memory as Numpy arrays? The official Google docs only show the vision api accepting an image in disk as the input.
I want to avoid unnecessary disk writes.
Pricing is tiered - the first 1000 units used each month are free, units 1001 to 5,000,000 are priced as marked, etc. If you pay in a currency other than USD, the prices listed in your currency on Cloud Platform SKUs apply.
One way of providing the image to Google Cloud Vison API is as a base64 encoded string. The quickstart example uses the Python client API, which accepts a stream of bytes for the image content.
Instead of writing to file you can encode your OpenCV image img
to a byte string you can directly pass to Cloud Vision API:
image = types.Image(content=cv2.imencode('.jpg', img)[1].tostring())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With