文档简介:
接口描述
支持识别各类商场、超市及药店的购物小票,包括店名、小票号码、机器编号、工号、消费日期、消费时间、总金额、找零、币种、实收金额、优惠金额、打印日期、打印时间、明细商品名称、单价、数量、小计金额等信息。
在线调试
您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/ocr/v1/shopping_receipt
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,要求base64编码和urlencode后大小不超过8M,最短边至少15px,最长边最大8192px,支持jpg/jpeg/png/bmp格式 优先级:image > url > pdf_file,当image字段存在时,url、pdf_file字段失效 |
url | 和 image/pdf_file 三选一 | string | - |
图片完整url,url长度不超过1024字节,url对应的图片base64编码后大小不超过8M,最短边至少15px,最长边最大8192px,支持jpg/jpeg/png/bmp格式 优先级:image > url > pdf_file,当image字段存在时,url字段失效 请注意关闭URL防盗链 |
pdf_file | 和 image/url 三选一 | string | - |
PDF文件,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过8M,最短边至少15px,最长边最大8192px 优先级:image > url > pdf_file,当image、url字段存在时,pdf_file字段失效 |
pdf_file_num | 否 | string | - | 需要识别的PDF文件的对应页码,当 pdf_file 参数有效时,识别传入页码的对应页面内容,若不传入,则默认识别第 1 页 |
probability | 否 | string | true/false | 是否返回字段置信度,默认为 false ,即不返回 |
location | 否 | string | true/false | 是否返回字段位置坐标,默认为 false,即不返回 |
请求代码示例
提示一:使用示例代码前,请记得替换其中的示例Token、图片地址或Base64信息。
提示二:部分语言依赖的类或库,请在代码注释中查看下载地址。
curl -i -k 'https://aip.baidubce.com/rest/2.0/ocr/v1/shopping_receipt?access_token=
【调用鉴权接口获取的token】' --data 'image=【图片Base64编码,需UrlEncode】
' -H 'Content-Type:application/x-www-form-urlencoded'
返回说明
返回参数
字段 | 是否必选 | 类型 | 说明 |
---|---|---|---|
log_id | 是 | uint64 | 唯一的log id,用于问题定位 |
pdf_file_size | 否 | string | 传入PDF文件的总页数,当 pdf_file 参数有效时返回该字段 |
words_result | 是 | object{} | 识别结果 |
+ shop_name | 是 | string | 店名/超市名字 |
+ receipt_num | 是 | string | 小票号码 |
+ machine_num | 是 | string | 机器编号 |
+ employee_num | 是 | string | 工号 |
+ consumption_date | 是 | string | 消费日期 |
+ consumption_time | 是 | string | 消费时间 |
+ total_amount | 是 | string | 总金额 |
+ change | 是 | string | 找零 |
+ currency | 是 | string | 币种 |
+ paid_amount | 是 | string | 实收金额 |
+ discount | 是 | string | 优惠/折扣 |
+ print_date | 是 | string | 打印日期 |
+ print_time | 是 | string | 打印时间 |
+ table_row_num | 是 | uint32 | 商品明细行数,表示Table中的object个数 |
+ table | 是 | array[] | 消费明细区域 |
++ product | 是 | string | 商品条码/名称 |
++ quantity | 是 | string | 数量 |
++ unit_price | 是 | string | 单价 |
++ subtotal_amount | 是 | string | 小计金额 |
+++ word | 是 | string | 字段识别结果,以上各字段均包含此参数 |
+++ location | 否 | object | 字段位置信息,当请求参数 location=true 时,以上各字段均包含此参数 |
++++ top | 否 | uint32 | 字段的上边距 |
++++ left | 否 | uint32 | 字段的左边距 |
++++ height | 否 | uint32 | 字段的高度 |
++++ width | 否 | uint32 | 字段的宽度 |
+++ probability | 否 | object | 字段识别结果置信度,当请求参数 probability=true 时,以上各字段均包含此参数 |
++++ average | 否 | float | 字段识别结果中各字符的置信度平均值 |
++++ min | 否 | float | 字段识别结果中各字符的置信度最小值 |
返回示例
{ "words_result": [ { "total_amount": [ { "word": "5.50" } ], "discount": [ {
"word": "0.8" } ], "currency": [ { "word": "RMB" } ], "receipt_num": [ { "word":
"22202010230414" } ], "shop_name": [ { "word": "盛玛特购物中心" } ], "consumption
_time": [ { "word": "16:18" } ], "consumption_date": [ { "word": "2020-10-23" } ],
"table_row_num": 2, "table": [ { "product": { "word": "仔姜2100871003105" },
"quantity": { "word": "0.199" }, "unit_price": { "word": "15.60" }, "subtotal_amount":
{ "word": "3.10" } }, { "product": { "word": "绿豆芽2100741001200" }, "quantity":
{ "word": "0.469" }, "unit_price": { "word": "2.56" }, "subtotal_amount": { "word":
"1.20" } }, { "product": { "word": "魔芋2100776001206" }, "quantity": { "word": "0.612" },
"unit_price": { "word": "1.96" }, "subtotal_amount": { "word": "1.20" } } ], "paid_amount":
[ { "word": "5.50" } ], "print_date": [ { "word": "2022-01-01" } ], "machine_num": [ {
"word": "22" } ], "change": [ { "word": "" } ], "employee_num": [ { "word": "4004" } ],
"print_time": [ { "word": "" } ] } ], "log_id": 1468109066360637315 }