Skip to content

Instantly share code, notes, and snippets.

@Chetan-Goyal
Created January 30, 2020 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chetan-Goyal/7f63ec5a0426dab7b7f32f7a0d19a34d to your computer and use it in GitHub Desktop.
Save Chetan-Goyal/7f63ec5a0426dab7b7f32f7a0d19a34d to your computer and use it in GitHub Desktop.
import requests
def ocr_space_file(filename, overlay=False, api_key='2704fc2bc388957', language='eng'):
payload = {'isOverlayRequired': overlay,
'apikey': api_key,
'language': language,
'detectOrientation': True,
'scale': True,
'OCREngine': 2,
}
with open(filename, 'rb') as f:
r = requests.post('https://api.ocr.space/parse/image',
files={filename: f},
data=payload,
)
return r.content.decode()
if __name__ == "__main__":
# Initializing image path to temporary variables
file_path = '/home/chetan/Downloads/Sample_OCR_Images/TILT_2.jpg'
# Calling Functions
test_file = ocr_space_file(filename=file_path)
# Loading Json data
import json
data_test_file = json.loads(test_file)
# Printing Results
print('\n----------------TEST FILE---------------\n')
print(data_test_file['ParsedResults'][0]['ParsedText'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment