python - 在线运行支持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 ?
解决方案
推荐阅读
- php - 我使用 DQL 进行了自定义查询,但对象没有看到该方法
- asp.net-mvc - 从模型设置日期,而不是由 datetimepicker 默认设置
- sql - 这两种在 SQL 中连接表的方法之间的真正区别是什么
- authentication - 为python客户端连接设置安全cookie
- scala - 如何使用 ScalaMock 模拟按名称调用的函数?
- python - Python多处理信号量不起作用
- javascript - 为每个项目设置一个值,除了通过不可变 JS 的项目
- tfs - 仅使用 TFS 应用层时,在哪里更改用户?
- ios - 如何在动态 tableView Swift 中删除行
- java - 强制 .equals() 覆盖的 Java 接口