更新时间:2020-04-15 17:35
调用地址:https://form.market.alicloudapi.com/api/predict/ocr_table_parse
云市场文档页面:https://market.aliyun.com/products/57124001/cmapi024968.html
输入:
{
"image": "图片二进制数据的base64编码/图片url",
"configure": {"format":"html", "dir_assure":false, "line_less":false}
}
参数说明:
1. format 输出格式:html/json/xlsx;
2. dir_assure 图片方向是否确定是正向的: true(确定)/false(不确定)
3. line_less:是否无线条: true(无线条,或者只有横线没有竖线)/false(有线条)
4. skip_detection: 是否跳过检测,如果没有检测到表格,可以设置"skip_detection":true
支持三种格式输出:html/xlsx(excel)/json
#html 格式输出
{
"success":true,
"tables":"<html>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">\n<style type=\"text/css\">\n table tr td { border: 1px solid blue }\n table { border: 1px solid blue }\n span.note { font-size: 9px; color: red }\n</style>\n<table \"id\"=0>\n<tr><td colspan=1 rowspan=1>项 目 </td><td colspan=1 rowspan=1>期末余额 </td><td colspan=1 rowspan=1>年初余额 </td></tr><tr><td colspan=1 rowspan=1>合计 </td><td colspan=1 rowspan=1>5,423,591,988.10 </td><td colspan=1 rowspan=1>4,281,407,583.62 </td></tr>...</table></html>\n"
}
#xlsx 格式:
{"success":true,
"tables":"UEsDBBQAAAAIAAAAIQAR0e9YNAoAAIpUAAAYAAAA..." #base64 encoded excel file( base64编码的excel文件)
}
直接拷贝tables后面的字符串到文件保存,需要将里面的\n替换掉,在linux环境下,可以执行如下操作:
sed -i -e 's/\\n/\n/g' tmp_base64
base64 -d tmp_base64 > 9_100.xlsx
如果用python的话,可以执行如下代码:
import base64
import json
...
res_obj = json.loads(result)
with open('output.xlsx', 'wb') as fout:
fout.write(base64.b64decode(res_obj['tables']))
#json 格式输出
{
"success":true,
"tables":[
[ #table 0
[ # table0 row 0
{ # table 0 row 0 col 0
"sx":0, #start from column(单元格的起始列id)
"sy":0, #start row(单元格的起始行id)
"ex":1, #one past end column index(单元格所占的列数(colspan)为ex - sx)
"ey":1, #one past end row index(单元格所占的行数(rowspan)为ey - sy)
"height":96, #cell height,图片上单元格的高度
"width":573 #cell width,图片上单元格的宽度
"text":[
"项", #text block 0 (第一个文字块)
"目" #text block 1 (第二个文字块)
],
},
...
],
[ #table 0 row 1
{
"ex":1,
"ey":2,
"height":94,
"sx":0,
"sy":1,
"text":[
"合计"
],
"width":572
},
...
],
... #more rows
]
]
}
在文档使用中是否遇到以下问题
更多建议
匿名提交