I am making a program in python that scans receipts and relies on an OCR response using the OCRSpace API. It has worked perfectly in that past with a couple hundred tries but when uploading an image to my flask server from an iphone instead of a computer, the image's contents do not have an OCR result. I have tried using the same image on their website and it gives a normal response but with my flask app it returns
parsed_results = result.get("ParsedResults")[0]
TypeError: 'NoneType' object is not subscriptable
I am using the code:
img = cv2.imread(file_path)
height, width, _ = img.shape
roi = img[0: height, 0: width]
_, compressedimage = cv2.imencode(".jpg", roi, [1, 90])
file_bytes = io.BytesIO(compressedimage)
url_api = "https://api.ocr.space/parse/image"
result = requests.post(url_api,
files = {os.path.join(r'PATH', file_name): file_bytes},
data = {"apikey": "KEY",
"language": "eng",
#"OCREngine": 2,
"isTable": True})
result = result.content.decode()
result = json.loads(result)
parsed_results = result.get("ParsedResults")[0]
global OCRText
OCRText = parsed_results.get("ParsedText")
Thanks for any help in advance!
from OCR Space response ParsedResults[0] error
No comments:
Post a Comment