百度智能云iOCR自定义模板文字识别通用版API文档
文档简介:
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise
URL参数:
参数 值
access_token 通过API Key和Secret Key获取的access_token,参考“Access Token获取”
Header如下:
参数 值
Content-Type application/x-www-form-urlencoded
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise
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格式 |
url | 和 image/pdf_file 三选一 | string | - |
图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式,当image字段存在时url字段失效 请注意关闭URL防盗链 |
pdf_file | 和 image/url 三选一 | string | - |
PDF文件,base64编码后进行urlencode,需去掉编码头(data:application/pdf;base64, ) 要求base64编码和urlencode后大小不超过4M 注:目前仅支持单页PDF识别,如上传的为多页PDF,仅识别第一页 |
templateSign | 和 classifierId 二选一 | string | - | 模板 ID,自定义模板或预置模板的唯一标示,可用于调用指定的识别模板进行结构化识别,可在「模板管理」页查看并复制使用 |
classifierId | 和 templateSign 二选一 | string | - |
分类器Id,分类器的唯一标示,可用于调用指定的分类器对传入的图片进行自动分类及识别 与 templateSign 至少存在一个,如同时存在,则优先级 templateSign > classfierId |
请求代码示例
提示一:使用示例代码前,请记得替换其中的示例Token、图片地址或Base64信息。
提示二:部分语言依赖的类或库,请在代码注释中查看下载地址。
# 请求模板id curl -i -k 'https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise?access_token=
【调用鉴权接口获取的token】' --data 'templateSign=xxx&image=【图片Base64编码,需UrlEncode】
' -H 'Content-Type:application/x-www-form-urlencoded' # 请求分类器id curl -i -k
'https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise?access_token=
【调用鉴权接口获取的token】' --data 'classifierId=xxx&image=【图片Base64编码,需UrlEncode】
' -H 'Content-Type:application/x-www-form-urlencoded'
返回说明
返回参数
字段 | 是否必选 | 类型 | 说明 |
---|---|---|---|
logid | 是 | uint64 | 唯一的log id,用于问题定位 |
error_code | 是 | int | 0代表成功,如果有错误码返回可以参考错误码列表排查问题 |
error_msg | 是 | string | 如果error_code具体的失败信息,可以参考下方错误码列表排查问题 |
data | 是 | jsonObject | 识别返回的结果 |
+ isStructured | 是 | string | 表示是否结构化成功,true为成功,false为失败;成功时,返回结构化的识别结果;失败时,如果能识别,按行返回识别结果,如果不能识别,返回空 |
+ templateSign | 否 | string | 图片分类结果对应的模板id或指定使用的模版id |
+ scores | 否 | float | 分类置信度,如果指定templateSign,则该值为1 |
+ ret | 否 | jsonArray | 识别出来的字段数组,每一个单元里包含以下几个元素 |
++ word_name | 否 | string | isStructured 为 true 时存在,表示字段的名字;如果 isStructured 为 false 时,不存在 |
++ word | 否 | string | 识别的字符串或单字 |
++ location | 否 | jsonObject | 字段在原图上对应的矩形框 |
++ probability | 否 | jsonObject | 字段的置信度,包括平均、最小和方差 |
返回示例
{ "data": { "ret": [ { "probability": { "average": 0.998482, "min": 0.9957, "variance": 0.000002 },
"location": { "height": 88, "left": 1202, "top": 437, "width": 267 }, "word_name": "终点站",
"word": "天津" }, { "probability": { "average": 0.994316, "min": 0.629856, "variance": 0.000281 },
"location": { "height": 82, "left": 359, "top": 593, "width": 660 }, "word_name": "发车时间",
"word": "201706092107" }, { "probability": { "average": 0.998482, "min": 0.9957, "variance": 0.000002 },
"location": { "height": 90, "left": 432, "top": 432, "width": 261 }, "word_name": "始发站", "word": "北京南" },
{ "probability": { "average": 0.952242, "min": 0.77037, "variance": 0.008272 },
"location": { "height": 79, "left": 879, "top": 464, "width": 252 }, "word_name": "车次",
"word": "C2097" }, { "probability": { "average": 0.980604, "min": 0.932502, "variance": 0.000352 },
"location": { "height": 74, "left": 982, "top": 877, "width": 206 }, "word_name": "乘车人",
"word": "向宇波" }, { "probability": { "average": 0.994155, "min": 0.903164, "variance": 0.000396 },
"location": { "height": 65, "left": 1171, "top": 593, "width": 248 }, "word_name": "座位号",
"word": "07车无座" }, { "probability": { "average": 0.993914, "min": 1.2888, "variance": 0.000009 },
"location": { "height": 67, "left": 429, "top": 674, "width": 193 }, "word_name": "价格", "word": "54.50" } ],
"templateSign": "1c65a67f151df56ba4e29c4dddace5ee", "scores": 1, "isStructured": true,
"logId": "153206517722624" }, "error_code": 0, "error_msg": "" }