【发布时间】:2021-04-25 10:33:41
【问题描述】:
我正在用 Python 编写一个程序,该程序使用 OCRSpace API 扫描收据并依赖于 OCR 响应。过去,它通过数百次尝试完美运行,但是当从 iphone 而不是计算机将图像上传到我的烧瓶服务器时,图像的内容没有 OCR 结果。我尝试在他们的网站上使用相同的图像,它给出了正常的响应,但我的烧瓶应用程序返回了
parsed_results = result.get("ParsedResults")[0]
TypeError: 'NoneType' object is not subscriptable
我正在使用代码:
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")
提前感谢您的帮助!
【问题讨论】: