Last active
October 5, 2020 12:12
-
-
Save thejungwon/b46696c983ffa06c061499f58cefa4e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import uuid | |
import time | |
import base64 | |
import json | |
api_url = '<YOUR_API_URL>' | |
secret_key = '<YOUR_SECERET_KEY>' | |
# image_url = 'YOUR_IMAGE_URL' | |
image_file = 'korean.jpg' | |
with open(image_file,'rb') as f: | |
file_data = f.read() | |
request_json = { | |
'images': [ | |
{ | |
'format': 'jpg', | |
'name': 'demo', | |
'data': base64.b64encode(file_data).decode(), | |
} | |
], | |
'requestId': str(uuid.uuid4()), | |
'version': 'V2', | |
'timestamp': int(round(time.time() * 1000)) | |
} | |
payload = json.dumps(request_json).encode('UTF-8') | |
headers = { | |
'X-OCR-SECRET': secret_key, | |
'Content-Type': 'application/json' | |
} | |
response = requests.request("POST", api_url, headers=headers, data = payload) | |
result = json.loads(response.text) | |
extracted_text = '' | |
for box in result['images'][0]['fields']: | |
extracted_text+=box['inferText'] +" " | |
extracted_text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment