Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Google Vision API OCR - Python
import base64
with open("yourfile.ext", "rb") as image_file:
encoded_string = base64.b64encode(
import requests
base64_image = ""
base64_image = base64_image.replace("^data:image\/(png|jpg|jpeg);base64,", "")
url = "<GOOGLE API ACCESS TOKEN goes here>"
payload = {
"requests": [{"image": {"content": base64_image },
"features": [{"type": "TEXT_DETECTION"}]}]
headers = {
'Content-Type': 'application/json; charset=utf-8',
'Content-Type': 'text/plain'
response = requests.request("POST", url, headers=headers, json = payload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment