首页 > 解决方案 > 在线运行支持OCR空间的OCR函数后,JSON文件显示在哪里?

问题描述

import requests


def ocr_space_file(filename, createsearchable=False, searchablepdfhidetextlayer=False, overlay=False, 
api_key='1f43648e2788957', language='eng', filetype='pdf'):
""" OCR.space API request with local file.
    Python3.5 - not tested on 2.7
:param filename: Your file path & name.
:param overlay: Is OCR.space overlay required in your response.
                Defaults to False.
:param api_key: OCR.space API key.
                Defaults to 'helloworld'.
:param language: Language code to be used in OCR.
                List of available language codes can be found on https://ocr.space/OCRAPI
                Defaults to 'en'.
:return: Result in JSON format.
"""

payload = {'isOverlayRequired': overlay,
           'iscreatesearchablepdf': createsearchable,
           'issearchablepdfhidetextlayer': searchablepdfhidetextlayer,
           'apikey': api_key,
           'language': language,
           'filetype': filetype,
           }
with open(filename, 'rb') as f:
    r = requests.post('https://api.ocr.space/parse/image',
                      files={filename: f},
                      data=payload,
                      )
return r.content.decode()

test_file = ocr_space_file(filename='final_hospital.pdf', language='eng')

该功能似乎是正确的,因为我尝试运行它并且没有错误。但我不知道返回的 JSON 文件在哪里。我是否在免费的 OCR API 端点上检查它:https ://api.ocr.space/parse/image ?

标签: pythonfunctionapiocr

解决方案


推荐阅读