文档简介:
接口描述
支持识别图片/PDF格式文档中的表格内容,返回各表格的表头表尾内容、单元格文字内容及其行列位置信息,全面覆盖各类表格样式,包括常规有线表格、无线表格、含合并单元格表格。同时,支持多表格内容识别。
视频教程请参见 表格文字识别V2使用教程
在线调试
您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/ocr/v1/table
URL参数:
参数 | 值 |
---|---|
access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
参数 | 值 |
---|---|
Content-Type | application/x-www-form-urlencoded |
Body中放置请求参数,参数详情如下:
请求参数
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
---|---|---|---|---|
image | 和 url/pdf_file 三选一 | string | - |
图像数据,base64编码后进行urlencode,需去掉编码头(data:image/jpeg;base64, ) 要求base64编码和urlencode后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式 优先级: image > url > pdf_file,当image字段存在时,url、pdf_file字段失效 |
url | 和 image/pdf_file 三选一 | string | - |
图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式, 优先级: image > url > pdf_file,当image字段存在时url字段失效 请注意关闭URL防盗链 |
pdf_file | 和 image/url 三选一 | string | - |
PDF文件,base64编码后进行urlencode,要求base64编码和urlencode后大小不不超过4M 优先级: image > url > pdf_file,当image、url字段存在时,pdf_file字段失效 |
pdf_file_num | 否 | string | - | 需要识别的PDF文件的对应页码,当 pdf_file 参数有效时,识别传入页码的对应页面内容,若不传入,则默认识别第 1 页 |
cell_contents | 否 | string | true/false |
是否输出单元格文字位置信息 - false: 默认值,仅输出单元格行列信息及四角点坐标,不输出单元格内文字位置信息; - true: 输出单元格内文字的外接四边形四角点坐标,若文字折行,则分行分别输出 |
请求代码示例
提示一:使用示例代码前,请记得替换其中的示例Token、图片地址或Base64信息。
提示二:部分语言依赖的类或库,请在代码注释中查看下载地址。
curl -i -k 'https://aip.baidubce.com/rest/2.0/ocr/v1/table?access_token=【调用鉴权接口获取的token】
' --data 'image=【图片Base64编码,需UrlEncode】' -H 'Content-Type:application/x-www-form-urlencoded'
返回说明
返回参数
字段 | 是否必输出 | 类型 | 说明 |
---|---|---|---|
log_id | 是 | string | 日志id,用于问题定位 |
table_num | 是 | int | 检测到的表格数量 |
tables_result | 是 | array[] | 表格内容 |
+ table_location | 是 | array[] | 单个表格的四角点x,y坐标 |
+ header | 是 | array[] | 表头信息 |
++ location | 是 | array[] | 表头位置,四角点 x,y 坐标 |
++ words | 是 | string | 表头文字内容,按行拆分 |
+ body | 是 | array[] | 单元格信息 |
++ cell_location | 是 | array[] | 单元格四角点x,y坐标 |
++ row_start | 是 | array[] | 单元格行起始编号,横线编号从0开始 |
++ row_end | 是 | array[] | 单元格行终止编号 |
++ col_start | 是 | array[] | 单元格列起始编号,竖线编号从0开始 |
++ col_end | 是 | array[] | 单元格列终止编号 |
++ words | 是 | string | 单元格文字内容 |
++ contents | 否 | array[] | 单元格内文字内容,分行显示,当请求参数 cell_contents = true 时返回 |
+++ poly_location | 否 | array[] | 单元格内文字各行的四角点x,y坐标 |
+++ word | 否 | string | 单元格内分行文字内容 |
+ footer | 是 | array[] | 表尾信息 |
++ location | 是 | array[] | 表尾位置,四角点 x,y 坐标 |
++ words | 是 | string | 表尾信息,按行拆分 |
pdf_file_size | 否 | string | 传入PDF文件的总页数,当 pdf_file 参数有效时返回该字段 |
返回示例
{ "tables_result": [ { "table_location": [ { "x": 67, "y": 43 }, { "x": 708, "y": 43 },
{ "x": 708, "y": 200 }, { "x": 67, "y": 200 } ], "header": [ { "location": [ { "x": 101,
"y": 16 }, { "x": 264, "y": 16 }, { "x": 264, "y": 34 }, { "x": 101, "y": 34 } ], "words":
"1.营业收入/营业成本" } ], "body": [ { "cell_location": [ { "x": 68, "y": 44 }, { "x": 188,
"y": 44 }, { "x": 188, "y": 101 }, { "x": 68, "y": 101 } ], "col_start": 0, "row_start": 0,
"row_end": 2, "col_end": 1, "words": "项目", "contents": [ { "poly_location": [ { "x": 84,
"y": 60 }, { "x": 128, "y": 61 }, { "x": 128, "y": 76 }, { "x": 84, "y": 75 } ], "word": "项目"
} ] }, { "cell_location": [ { "x": 192, "y": 43 }, { "x": 442, "y": 43 }, { "x": 442, "y": 68 },
{ "x": 192, "y": 68 } ], "col_start": 1, "row_start": 0, "row_end": 1, "col_end": 3, "words":
"本期数", "contents": [ { "poly_location": [ { "x": 308, "y": 49 }, { "x": 349, "y": 49 },
{ "x": 348, "y": 63 }, { "x": 307, "y": 63 } ], "word": "本期数" } ] } ], "footer": [] } ],
"table_num": 1, "log_id": 1516052468533474289 }