表格识别
调用地址:https://form.market.alicloudapi.com/api/predict/ocr_table_parse
云市场文档页面:https://market.aliyun.com/products/57124001/cmapi024968.html
适用场景:线条为黑色的,横线和竖线都齐全的表格识别,如:财务报表(请用finance模型);房产证等;
输入格式
输入:
{
"image": "图片二进制数据的base64编码",
"configure": "{\"format\":\"html\", \"finance\":false, \"dir_assure\":false, "\line_less\":false}"
}
参数说明:
1. format 输出格式:html/json/xlsx;
2. finance 是否使用财务报表模型: true/false;
3. dir_assure 图片方向是否确定是正向的: true(确定)/false(不确定)
4. line_less:是否无线条: true(无线条,或者只有横线没有竖线)/false(有线条)
输出格式
支持三种格式输出: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
#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
]
]
}
原创文章,作者:网友投稿,如若转载,请注明出处:https://www.cloudads.cn/archives/33607.html