OCR空间响应ParsedResults[0]错误



我正在用python编写一个程序,该程序扫描收据并依赖于使用OCRSpace API的OCR响应。在过去的几百次尝试中,它已经完美地工作了,但是当从iphone而不是计算机上传图像到我的flask服务器时,图像的内容没有OCR结果。我试过在他们的网站上使用相同的图像,它给出了一个正常的响应,但我的flask应用程序返回

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")

提前感谢您的帮助!

iOS 11版本的iphone和ipad使用HEIF作为标准;在传送至个人电脑或以共享方式传送时,不会有任何不兼容,因为图像已转换为广泛支持的JPEG格式;但是,当使用云服务(例如Google Photos)时,会出现不兼容问题。

高效图像文件格式(HEIF)

正如@rob247所发布的iphone默认使用HEIF格式(官方链接在这里)因此,当您将照片上传到脚本时,请在使用之前尝试将其转换为JPEG,因为opencv不支持*heif,*avif,*heic,但请参阅问题#14534,如果您喜欢其他格式,请查看opencv imread中支持的格式列表

最新更新