Hi,
I have registered for OCR API and tried to use the OCR API to read the image to text but while reading image OCR API returning
error message in JSON format. Below is JSON response and my python code snippet. I have replaced API Key in below code with dummy content.
Please let me know if I need to provide API Key to trace the error. I have registered with OCR API using mail id : asitsatapathy1@gmail.com
JSON Response:
{“OCRExitCode”:99,“IsErroredOnProcessing”:true,“ErrorMessage”:[“Unable
to recognize the file type”],“ProcessingTimeInMilliseconds”:“15”}
The above error response says the file type is unrecognizable.
I have created a .JPG file using mspaint and the this image has text content
only which is basically the screenshot of email from OCR team after
subscription. Please help me resolving this issue.
Python Code:
import cv2
import numpy as np
import io import requests
import json
img = cv2.imread(“C:\Asit\6.png”)
print(img.shape) height,
width, _ = img.shape
#Cutting image to read only on portion
roi = img[0:height, 100:width]
#Compress the image before sending to OCR API
_, compressedimage = cv2.imencode(“.png”,roi, [1,90]) _, compressedimage = cv2.imencode(“.png”,img, [1,90])
#Convert the image into bytes so that can be sent to OCR API
file_bytes = io.BytesIO(compressedimage)
#Free OCR API
url_api = “https://api.ocr.space/parse/image”
result = requests.post(url_api, files={“C:\Asit\6.png”:file_bytes}, data={“apikey”:“My API KEY”, “language”:“eng”})
result = result.content.decode()
print(result)
result = json.loads(result)
text_detected = result.get(“ParsedResults”)[0].get(“ParsedText”)
print(text_detected)
cv2.imshow(“Img”, img)
cv2.imshow(“roi”,roi)
cv2.waitKey(0)
cv2.destroyAllWindows()