百度智能云iOCR自定义模板文字识别财会版API文档
文档简介:
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise/finance
URL参数:
参数 值
access_token 通过API Key和Secret Key获取的access_token,参考“Access Token获取”
Header如下:
参数 值
Content-Type application/x-www-form-urlencoded
Body中放置请求参数,参数详情如下:
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise/finance
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 | 否 | string | - | 模板 ID,自定义模板或预置模板的唯一标示,可用于调用指定的识别模板进行结构化识别,可在「模板管理」页查看并复制使用 |
classifierId | 否 | string | - |
分类器Id,分类器的唯一标示,可用于调用指定的分类器对传入的图片进行自动分类及识别 与 templateSign 至少存在一个,如同时存在,则优先级 templateSign > classfierId |
请求代码示例
提示一:使用示例代码前,请记得替换其中的示例Token、图片地址或Base64信息。
提示二:部分语言依赖的类或库,请在代码注释中查看下载地址。
# 请求模板id curl -i -k 'https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise
/finance?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/finance?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 | 识别返回的结果 |
+ ret | 是 | jsonArray | 识别出来的字段数组,每一个单元里包含以下几个元素 |
++ word_name | 否 | string | isStructured 为 true 时存在,表示字段的名字;如果 isStructured 为 false 时,不存在 |
++ word | 否 | string | 识别的字符串或单字 |
++ location | 否 | jsonObject | 字段在原图上对应的矩形框位置,通过上边距、左边距、宽度、高度表示 |
++ probability | 否 | jsonObject | 字段的置信度,包括平均、最小和方差 |
+ templateSign | 否 | string |
图片分类结果对应的模板id或指定使用的模版id。templateSign的对应关系为: - mixed_receipt:混贴发票,可对粘贴单中的多张不同票据进行检测分类,返回每张发票的类别及识别结果; - vat_invoice:增值税发票; - taxi:出租车票; - roll_ticket:卷票; - train_ticket:火车票; - quota_invoice:定额发票; - travel_itinerary:行程单; - car_invoice:汽车票; - toll_invoice:通行费发票; - printed_invoice:机打发票。 |
+ scores | 否 | float | 分类置信度,如果指定templateSign,则该值为1 |
+ isStructured | 否 | string | 表示是否结构化成功,true为成功,false为失败;成功时,返回结构化的识别结果;失败时,如果能识别,按行返回结果,如果不能识别,返回空 |
返回示例
- 使用自定义模板及自定义分类器功能时,返回结果可参考 iOCR通用版-返回示例;
- templateSign = mixed_receipt 时,返回结果如下所示:
{ "data": { "ret": [ { "ret": [ { "rect": { "top": 277, "left": 237, "width": 61, "height": 10 },
"probability": { "average": 0.98831981420517, "min": 0.96548694372177 }, "word_name": "AmountInWords",
"word": "叁佰陆拾圆整" }, { "rect": { "top": 29, "left": 482, "width": 85, "height": 18 }, "probability":
{ "average": 0.99745708703995, "min": 0.99514311552048 }, "word_name": "InvoiceNumConfirm", "word": "07286261" },
{ "rect": { "top": 352, "left": 393, "width": 32, "height": 12 }, "probability": { "average": 0.99022936820984,
"min": 0.98398983478546 }, "word_name": "NoteDrawer", "word": "余佳燕" }, { "rect": { "top": 326, "left": 158,
"width": 214, "height": 10 }, "probability": { "average": 0.94039279222488, "min": 0.39105615019798 },
"word_name": "SellerAddress", "word": "杭州市转塘科技经济区块16号8幢0571-85022088" },
{ "rect": { "top": 311, "left": 171, "width": 146, "height": 12 }, "probability": { "average": 0.99681425094604,
"min": 0.98468536138535 }, "word_name": "SellerRegisterNum", "word": "91330106673959654P" },
{ "rect": { "top": 0, "left": 0, "width": -1, "height": -1 }, "probability": { "average": 0, "min": 0 },
"word_name": "MachineCode", "word": "" }, { "rect": { "top": 0, "left": 0, "width": -1, "height": -1 },
"probability": { "average": 0, "min": 0 }, "word_name": "Remarks", "word": "" }, { "rect": { "top": 339, "left": 158,
"width": 181, "height": 11 }, "probability": { "average": 0.99247741699219, "min": 0.8911309838295 },
"word_name": "SellerBank", "word": "招商银行杭州高新支行502905023610702" }, { "rect": { "top": 259,
"left": 576, "width": 43, "height": 10 }, "probability": { "average": 0.97683322429657,
"min": 0.89436012506485 }, "word_name": "TotalTax", "word": "20.38" }, { "rect": { "top": 32, "left": 124, "width": 101,
"height": 16 }, "probability": { "average": 0.99661940336227, "min": 0.99573355913162 }, "word_name":
"InvoiceCodeConfirm", "word": "3321192130" }, { "rect": { "top": 0, "left": 0, "width": -1, "height": -1 }, "probability":
{ "average": 0, "min": 0 }, "word_name": "CheckCode", "word": "" }, { "rect": { "top": 32, "left": 124,
"width": 101, "height": 16 }, "probability": { "average": 0.99661940336227, "min": 0.99573355913162 },
"word_name": "InvoiceCode", "word": "3321192130" }, { "rect": { "top": 65, "left": 534, "width": 73,
"height": 12 }, "probability": { "average": 0.99508810043335, "min": 0.97497177124023 }, "word_name":
"InvoiceDate", "word": "2019年08月28日" }, { "rect": { "top": 104, "left": 168, "width": 147, "height": 12 },
"probability": { "average": 0.9933996796608, "min": 0.96598559617996 }, "word_name": "PurchaserRegisterNum",
"word": "91110911717743469K" }, { "rect": { "top": 18, "left": 257, "width": 164, "height": 19 },
"probability": { "average": 0.99611341953278, "min": 0.98104286193848 }, "word_name": "InvoiceTypeOrg", "word":
"浙江增值税专用发票" }, { "rect": { "top": 93, "left": 405, "width": 191, "height": 45 }, "probability":
{ "average": 0.97755342721939, "min": 0.82740485668182 }, "word_name": "Password",
"word": "508>3909>1*>01/-46709-6/3+*7+8>/1*19+7-0**>+58290-6>647-+324865*9*1
<*2191/7754/2<838+//5-69--748*<251408<" }, { "rect": { "top": 0, "left": 0, "width": -1, "height": -1 },
"probability": { "average": 0, "min": 0 },
"word_name": "Agent", "word": "否" }, { "rect": { "top": 278, "left": 511, "width": 54, "height": 10 },
"probability": { "average": 0.95414996147156, "min": 0.68566131591797 }, "word_name": "AmountInFiguers",
"word": "360.00" }, { "rect": { "top": 134, "left": 159, "width": 204, "height": 11 }, "probability":
{ "average": 0.97773444652557, "min": 0.61343103647232 }, "word_name": "PurchaserBank", "word":
"招商银行北京分行大电路支行866180100210002" }, { "rect": { "top": 352, "left": 259, "width":
26, "height": 12 }, "probability": { "average": 0.98384791612625, "min": 0.97088402509689 },
"word_name": "Checker", "word": "柳余" }, { "rect": { "top": 0, "left": 0, "width": -1,
"height": -1 }, "probability": { "average": 0, "min": 0 }, "word_name": "City", "word": "" },
{ "rect": { "top": 258, "left": 460, "width": 49, "height": 11 }, "probability":
{ "average": 0.98758614063263, "min": 0.9416212439537 }, "word_name": "TotalAmount", "word": "339.62" },
{ "rect": { "top": 90, "left": 159, "width": 150, "height": 12 }, "probability":
{ "average": 0.96976244449615, "min": 0.70321601629257 }, "word_name": "PurchaserName", "word":
"百度在线网络技术(北京)有限公司" }, { "rect": { "top": 0, "left": 0, "width": -1, "height": -1 },
"probability": { "average": 0, "min": 0 }, "word_name": "Province", "word": "浙江" }, { "rect": {
"top": 18, "left": 257, "width": 164, "height": 19 }, "probability": { "average": 0.99611341953278,
"min": 0.98104286193848 }, "word_name": "InvoiceType", "word": "专用发票" }, { "rect": { "top": 145,
"left": 626, "width": 9, "height": 28 }, "probability": { "average": 0.99723851680756, "min": 0.99662339687347 },
"word_name": "SheetNum", "word": "第二联" }, { "rect": { "top": 119, "left": 159, "width": 158, "height": 12 },
"probability": { "average": 0.89263164997101, "min": 0.21246993541718 }, "word_name": "PurchaserAddress",
"word": "北京市海淀区上地十侧10号百厘大厦三座" }, { "rect": { "top": 353, "left": 113, "width": 22,
"height": 10 }, "probability": { "average": 0.84802502393723, "min": 0.560218334198 },
"word_name": "Payee", "word": "佳机" }, { "rect": { "top": 298, "left": 158, "width": 85,
"height": 11 }, "probability": { "average": 0.96288979053497, "min": 0.8344641327858 },
"word_name": "SellerName", "word": "阿里云计算有限公司" }, { "rect": { "top": 29, "left": 482,
"width": 85, "height": 18 }, "probability": { "average": 0.99745708703995, "min": 0.99514311552048 },
"word_name": "InvoiceNum", "word": "07286261" }, { "rect": { "top": 163, "left": 71, "width": 116,
"height": 11 }, "probability": { "average": 0.9905007481575, "min": 0.98428183794022 }, "word_name":
"DetailsOfTax#1#CommodityName", "word": "*信息技术服务*软件服务费" }, { "word_name":
"DetailsOfTax#1#CommodityType", "word": "" }, { "rect": { "top": 164, "left": 292,
"width": 10, "height": 10 }, "probability": { "average": 0.89159053564072, "min": 0.80279469490051 },
"word_name": "DetailsOfTax#1#CommodityUnit", "word": "套" }, { "rect": { "top": 166, "left": 360,
"width": 7, "height": 8 }, "probability": { "average": 0.95917397737503, "min": 0.95113134384155 },
"word_name": "DetailsOfTax#1#CommodityNum", "word": "1" }, { "rect": { "top": 165, "left": 397,
"width": 28, "height": 9 }, "probability": { "average": 0.97336208820343, "min": 0.89550644159317 },
"word_name": "DetailsOfTax#1#CommodityPrice", "word": "339.62" }, { "rect": { "top": 165, "left": 480,
"width": 28, "height": 9 }, "probability": { "average": 0.98559606075287, "min": 0.96932607889175 },
"word_name": "DetailsOfTax#1#CommodityAmount", "word": "339.62" }, { "rect": { "top": 165, "left": 522,
"width": 11, "height": 9 }, "probability": { "average": 0.92075562477112, "min": 0.8382123708725 },
"word_name": "DetailsOfTax#1#CommodityTaxRate", "word": "6%" }, { "rect": { "top": 165, "left": 595,
"width": 24, "height": 9 }, "probability": { "average": 0.97626549005508, "min": 0.9149768948555 },
"word_name": "DetailsOfTax#1#CommodityTax", "word": "20.38" } ], "receiptCoordinate":
"{\"height\":642,\"left\":155,\"top\":178,\"width\":1106}", "error_msg": "success",
"templateSign": "vat_invoice", "scores": 1, "templateName": "增值税发票", "isStructured": true,
"error_code": 0 }, { "ret": [ { "probability": { "average": 0, "min": 0 }, "word_name": "PickupTime",
"word": "16:50" }, { "probability": { "average": 0, "min": 0 }, "word_name": "DropoffTime", "word": "17:06" },
{ "rect": { "top": 212, "left": 48, "width": 66, "height": 9 }, "probability": { "average": 0.98931306600571,
"min": 0.92181307077408 }, "word_name": "Time", "word": "16:50-17:06" },
{ "probability": { "average": 0, "min": 0 }, "word_name": "City", "word": "" },
{ "rect": { "top": 288, "left": 84, "width": 30, "height": 9 }, "probability": { "average": 0.99606895446777,
"min": 0.99255055189133 }, "word_name": "FuelOilSurcharge", "word": "1.00" },
{ "rect": { "top": 198, "left": 53, "width": 61, "height": 9 }, "probability": { "average": 0.99483448266983,
"min": 0.98498445749283 }, "word_name": "Date", "word": "2019-03-20" }, { "probability":
{ "average": 0, "min": 0 }, "word_name": "Province", "word": "陕西省" }, { "probability":
{ "average": 0, "min": 0 }, "word_name": "CallServiceSurcharge", "word": "0.00" }, { "rect":
{ "top": 275, "left": 76, "width": 38, "height": 9 }, "probability": { "average": 0.98517167568207,
"min": 0.97685235738754 }, "word_name": "Fare", "word": "21.10" }, { "rect": { "top": 314, "left":
76, "width": 39, "height": 9 }, "probability": { "average": 0.97668653726578, "min": 0.93554848432541 },
"word_name": "TotalFare", "word": "2.00" }, { "rect": { "top": 173, "left": 72, "width": 42, "height": 8 },
"probability": { "average": 0.98336416482925, "min": 0.88234621286392 }, "word_name": "TaxiNum", "word":
"BQ6353" }, { "rect": { "top": 225, "left": 89, "width": 25, "height": 8 }, "probability":
{ "average": 0.99482887983322, "min": 0.99453765153885 }, "word_name": "PricePerkm", "word": "2.30" },
{ "rect": { "top": 124, "left": 14, "width": 90, "height": 11 }, "probability": { "average": 0.99889290332794,
"min": 0.99876511096954 }, "word_name": "InvoiceCode", "word": "161001881016" }, { "rect": { "top": 238,
"left": 96, "width": 18, "height": 8 }, "probability": { "average": 0.99126571416855, "min": 0.98285579681396 },
"word_name": "Distance", "word": "6.0" }, { "rect": { "top": 137, "left": 14, "width": 60, "height": 10 },
"probability": { "average": 0.99211621284485, "min": 0.94001615047455 }, "word_name": "InvoiceNum",
"word": "05070716" }, { "probability": { "average": 0, "min": 0 }, "word_name": "Location", "word"
"陕西省" } ], "receiptCoordinate": "{\"height\":618,\"left\":1325,\"top\":200,\"width\":215}",
"error_msg": "success", "templateSign": "taxi", "scores": 1, "templateName": "出租车发票",
"isStructured": true, "error_code": 0 } ], "templateSign": "mixed_receipt", "templateName": "混贴票据",
"scores": 1, "isStructured": true, "logId": "164196999300761", "version": 1 }, "error_code": 0,
"error_msg": "", "log_id": "164196999300761" }