Script to run Google VisionΒΆ

#!/usr/bin/env python

# Run Google OCR on the US weathermap sample image

import pickle

from google.cloud import vision
from google.cloud.vision import types
from google.protobuf import json_format

# Load the jpeg
with open("../../../samples/US_Weather_map_19150814.jpg",'rb') as jf:
    ie=jf.read()

# Analyze the document
image = types.Image(content=ie)
client = vision.ImageAnnotatorClient()
response = client.document_text_detection(image=image)
document = response.full_text_annotation

# Save the resulting JSON
pickle.dump(document, open( "detection.pkl", "wb" ) )
with open('detection.txt', 'w') as file:
     file.write(json_format.MessageToJson(document))