目录
1.调用费用
2.调用流程
1)注册textin账户,进入右上角工作台
2)获取x-ti-app-id及x-ti-secret-code
3)开通API服务
4)调用代码
3. json文件主要信息(举例信息以字典形式给出)
新用户拥有1千次调用次数
调用费用:超过部分02元/次;5千次套餐包800元
官方链接:TextIn - 机器人市场 - 通用表格识别
textin链接:合合TextIn - 合合信息旗下一站式OCR云服务平台
工作台--账号管理--开发者信息
公有云API--
代码修改初始信息:x-ti-app-id、x-ti-secret-code、img_path、save_path
import requests
import json
x_ti_app_id = "32dcfa8429501ab636a671b07a338583"
x_ti_secret_code = ""
img_path = "D:\\table_generation-master\\demo\\table_recog_test\\0M208145r02110zw_1.png"
save_path = "D:\\table_generation-master\\demo\\baidu_result\\jit_hehe.json"
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
class CommonOcr(object):
def __init__(self, img_path):
# 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-app-id
# 示例代码中 x-ti-app-id 非真实数据
self._app_id = x_ti_app_id
# 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-secret-code
# 示例代码中 x-ti-secret-code 非真实数据
self._secret_code = x_ti_secret_code
self._img_path = img_path
def recognize(self):
# 通用表格识别
url = 'https://api.textin.com/ai/service/v2/recognize/table'
head = {}
try:
image = get_file_content(self._img_path)
head['x-ti-app-id'] = self._app_id
head['x-ti-secret-code'] = self._secret_code
result = requests.post(url, data=image, headers=head)
return result.text
except Exception as e:
return e
if __name__ == "__main__":
response = CommonOcr(img_path)
result = response.recognize()
print(result)
result = json.loads(result)["result"]
result = json.dumps(result, ensure_ascii=False)
with open(save_path, 'w', encoding='utf-8') as fp:
fp.write(result)