全部产品

自定义模板识别

更新时间:2019-11-19 12:02:19

预备知识

自定义模板

购买页面https://market.aliyun.com/products/57124001/cmapi029975.html
调用地址:在购买页面-API接口查看
模板设计页面: https://ocr.data.aliyun.com

输入格式(单模板):

  1. {
  2. "image": "图片二进制数据的base64编码",
  3. "configure": "{\"template_id\":\"95d551ee-8b2b-4ad0-89a9-ed13417f4a781536146904\"}"
  4. }

输入格式(多模板自动匹配):

  • 基于关键字

    • 可以输入一组template_id,每组template_id有对应的条件(cond),满足条件即使用该template_id
    • 基本条件包含include,exclude,分别表示包含/不包含某个关键字
    • 组合条件使用and, or表示,详见下面的示例
      1. {
      2. "image": "图片二进制数据的base64编码",
      3. "configure":{"template_list": [
      4. {"template_id": "fc7b375c-8e98-48ef-81fb-ec3843b2fb371534902155", #星巴克的模板id
      5. "cond": {"and": [{"or": [{"include": "星巴克"},
      6. {"include":"starbuck"}]
      7. },
      8. {"exclude":"Costa"}]}
      9. },
      10. {"template_id": "7bc26bd7-41ad-4145-9f5a-4af21b26de9a", #costa的模板id
      11. "cond": {"include":"costa"}
      12. }]
      13. }
      14. }
    • 如果关键字匹配失败,将执行下述的自动匹配
  • 自动匹配

    • 也可以直接通过如下方式进行多模板调用,系统会自动匹配出与调用图片最相近的模板
      1. {
      2. "image": "图片二进制数据的base64编码",
      3. "configure":{"template_list": [
      4. "fc7b375c-8e98-48ef-81fb-ec3843b2fb371534902155", #星巴克的模板id
      5. "7bc26bd7-41ad-4145-9f5a-4af21b26de9a", #costa的模板id
      6. ]
      7. }
      8. }

输出格式(不带表格的):

  1. {
  2. "config_str":"{\"template_id\":\"95d551ee-8b2b-4ad0-89a9-ed13417f4a781536146904\"}",
  3. "items":{"cash_id":":11535001", #key-value组合,key是用户在界面上填写的
  4. "cash_name":":李伟",
  5. "change":"¥0.00",
  6. "date":":2018.03.16 16:46",
  7. "drop":"¥-0.10",
  8. "num":":2",
  9. "pay":"¥65.50",
  10. "sell_type":"外带",
  11. "seller":"24662",
  12. "shop_name":"TEL:0571-5697229",
  13. "total":"¥65.60"
  14. },
  15. "request_id":"20180723151536_fa0edbe7408fc589b93119f7a53a1260",
  16. "success":true
  17. }

输出格式(带表格的输出):

  1. {
  2. "config_str":"{\"template_id\":\"dd3ada93-c6ed-4427-8e0b-fbdebad614061532347130\"}",
  3. "items":{
  4. "item_no" : "1313131313",
  5. "mail" : "daigou@gmail.com",
  6. "name" : "代购小哥",
  7. "nation" : "美国",
  8. "phone" : "987654321",
  9. "table0" : { #table0是用户在界面上填写的表格名称
  10. #labels是用户在界面上填写的, 表格每一列的名称, values是每一行的值
  11. #一行的数组和labels是一一对应的关系
  12. labels":["brand", "model", "name", "quantity", "standard", "total"]
  13. "values":[["Iphone","8p","手机","3","128G","15000rmb"],
  14. ["戴森","V8","吸尘器","1","Absolute","3500元"],
  15. ["","","","","",""],
  16. ["","","","","",""],
  17. ["","","","","",""]
  18. ]
  19. }
  20. }
  21. }

正常返回:http_status = 200
错误代码:图片输入错误或者算法错误, http_status = 400
没有设置template_json, http_status = 452
没有设置锚点, http_status = 453
没有设置识别内容, http_status = 454
没有对应的template_id, http_status = 455