【问题标题】:OCR Space response ParsedResults[0] errorOCR 空间响应 ParsedResults[0] 错误
【发布时间】: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")

提前感谢您的帮助!

【问题讨论】:

    标签: python api rest flask ocr


    【解决方案1】:

    从 iOS 11 开始的 iPhone 和 iPad 使用 HEIF 作为标准;传输到 PC 或发送时没有不兼容,例如通过共享,将图像转换为广泛支持的 JPEG 格式;但是,使用云服务时会出现不兼容性,例如谷歌照片。

    High Efficiency Image File Format (HEIF)

    【讨论】:

    • 只是一个想法 ;)
    • 该程序在 iphone 上拍摄的一组特定图像存在问题。该程序对在计算机上拍摄并发送到 iPhone 的照片没有任何问题。如果照片最初是在 iPhone 上拍摄的,会有什么不同吗?
    【解决方案2】:

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

    【讨论】:

    • @Python 123 请尝试转换为 JPEG 并告诉我结果
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 2021-07-18
    相关资源
    最近更新 更多