智能表单抽取接口文档

调用地址:https://analysis.market.alicloudapi.com/ocrservice/table
请求方式:POST
返回类型:JSON

请求参数(Body):

{
//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个
"img": "",
//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个
"url": "",
//是否需要自动旋转功能,默认不需要。 true:需要 false:不需要
"rotate": false
}

请求代码示例:

java版

    public static void main(String[] args) {
String url = "https://analysis.market.alicloudapi.com/ocrservice/table";
String appcode = "你自己的AppCode";
HashMap<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
//根据API的要求,定义相对应的Content-Type
headers.put("Content-Type", "application/json; charset=UTF-8");
//如果需要使用本地图片,需要将图片base64码放在img后面,如果使用网络图片,则需要将网络图片url放于url参数后面
String bodys = "{//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\",//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//是否需要自动旋转功能,默认不需要。true:需要false:不需要\"rotate\":false}";
try {
/**
* 重要提示如下:
* HttpClientUtils请从
* https://gitee.com/duguangdemo/publicclouddemo/blob/master/src/main/java/util/HttpClientUtils.java
* 下载
* HttpExecuteResponse请从
* https://gitee.com/duguangdemo/publicclouddemo/blob/master/src/main/java/util/HttpExecuteResponse.java
* 下载
*
* 相应的依赖请参照
* https://gitee.com/duguangdemo/publicclouddemo/blob/master/pom.xml
*/
HttpExecuteResponse response = HttpClientUtils.doPost(url,bodys, headers);
System.out.println(response.getResponseAsString());
System.out.println(response.toString());
// 需要检查response的headers信息时可用以下代码,方便排查问题用
// for (Object json : response.getHeaders()) {
// System.out.println(json);
// }

} catch (Exception e) {
e.printStackTrace();
}
}

c#版

//using System.IO;
//using System.Text;
//using System.Net;
//using System.Net.Security;
//using System.Security.Cryptography.X509Certificates;


private const String host = "https://analysis.market.alicloudapi.com";
private const String path = "/ocrservice/table";
private const String method = "POST";
private const String appcode = "你自己的AppCode";

static void Main(string[] args)
{
String querys = "";
String bodys = "{//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\",//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//是否需要自动旋转功能,默认不需要。true:需要false:不需要\"rotate\":false}";
String url = host + path;
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;

if (0 < querys.Length)
{
url = url + "?" + querys;
}

if (host.Contains("https://"))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = method;
httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
//根据API的要求,定义相对应的Content-Type
httpRequest.ContentType = "application/json; charset=UTF-8";
if (0 < bodys.Length)
{
byte[] data = Encoding.UTF8.GetBytes(bodys);
using (Stream stream = httpRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
}
catch (WebException ex)
{
httpResponse = (HttpWebResponse)ex.Response;
}

Console.WriteLine(httpResponse.StatusCode);
Console.WriteLine(httpResponse.Method);
Console.WriteLine(httpResponse.Headers);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("\n");

}

public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}

PHP版:

<?php
$host = "https://analysis.market.alicloudapi.com";
$path = "/ocrservice/table";
$method = "POST";
$appcode = "你自己的AppCode";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
//根据API的要求,定义相对应的Content-Type
array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
$querys = "";
$bodys = "{//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\",//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//是否需要自动旋转功能,默认不需要。true:需要false:不需要\"rotate\":false}";
$url = $host . $path;

$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
var_dump(curl_exec($curl));
?>

Python2:

import urllib, urllib2, sys
import ssl


host = 'https://analysis.market.alicloudapi.com'
path = '/ocrservice/table'
method = 'POST'
appcode = '你自己的AppCode'
querys = ''
bodys = {}
url = host + path

bodys[''] = "{//图像数据:base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和url参数只能同时存在一个\"img\":\"\",//图像url地址:图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,和img参数只能同时存在一个\"url\":\"\",//是否需要自动旋转功能,默认不需要。true:需要false:不需要\"rotate\":false}"
post_data = bodys['']
request = urllib2.Request(url, post_data)
request.add_header('Authorization', 'APPCODE ' + appcode)

request.add_header('Content-Type', 'application/json; charset=UTF-8')
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urllib2.urlopen(request, context=ctx)
content = response.read()
if (content):
print(content)

Python3:

import urllib.request
import urllib.parse
import json
import time
import base64
with open('1.jpg', 'rb') as f: # 以二进制读取本地图片
data = f.read()
encodestr = str(base64.b64encode(data),'utf-8')
#请求头
# 请修改为你自己的appcode,可从云市场订单或者api网关处获得
AppCode = "你自己的AppCode"
headers = {
'Authorization': 'APPCODE ' + AppCode,
'Content-Type': 'application/json; charset=UTF-8'
}

def posturl(url,data={}):
try:
params=json.dumps(dict).encode(encoding='UTF8')
req = urllib.request.Request(url, params, headers)
r = urllib.request.urlopen(req)
html =r.read()
r.close();
return html.decode("utf8")
except urllib.error.HTTPError as e:
print(e.code)
print(e.read().decode("utf8"))
time.sleep(1)
if __name__=="__main__":
url_request="https://analysis.market.alicloudapi.com/ocrservice/table"
dict = {'img': encodestr}

html = posturl(url_request, data=dict)
print(html)

正常返回示例:

{
//唯一id,用于问题定位
"sid": "98ff77fb5e51e70a6edde1fa4907b97d14c5319ced2564da5216703264196f5761b84fe1",
"angle": 0,
"height": 705,
"width": 748,
"orgHeight": 705,
"orgWidth": 748,
"tableInfo": {
"items": [
{
// 是否在表格内
"whether_in_form": true,
"key": {
// key名称
"name": "商品名称",
// key坐标
"pos": [
{
"x": 3,
"y": 5
},
{
"x": 107,
"y": 5
},
{
"x": 107,
"y": 47
},
{
"x": 5,
"y": 47
}
],
// key置信度
"prob": 100
},
//表单提取key的类型,group表示嵌套key,list表示key,value是一对多,object表示key,value是一对一
"type": "object",
"value": {
// value内容
"text": "NIKESBCOACHES樱花粉男女教练夹克",
// value坐标
"pos": [
{
"x": 107,
"y": 5
},
{
"x": 745,
"y": 0
},
{
"x": 743,
"y": 47
},
{
"x": 107,
"y": 47
}
],
// value置信度
"prob": 100
}
},
{
"whether_in_form": true,
"key": {
"name": "商品品牌",
"pos": [
{
"x": 5,
"y": 47
},
{
"x": 107,
"y": 47
},
{
"x": 107,
"y": 89
},
{
"x": 4,
"y": 89
}
],
"prob": 100
},
"type": "object",
"value": {
"text": "耐克",
"pos": [
{
"x": 107,
"y": 47
},
{
"x": 373,
"y": 47
},
{
"x": 373,
"y": 89
},
{
"x": 107,
"y": 89
}
],
"prob": 100
}
},
{
"whether_in_form": true,
"key": {
"name": "产地1",
"pos": [
{
"x": 373,
"y": 47
},
{
"x": 474,
"y": 47
},
{
"x": 474,
"y": 89
},
{
"x": 373,
"y": 89
}
],
"prob": 100
},
"type": "object",
"value": {
"text": "中国829510-678",
"pos": [
{
"x": 474,
"y": 47
},
{
"x": 743,
"y": 47
},
{
"x": 743,
"y": 89
},
{
"x": 474,
"y": 89
}
],
"prob": 100
}
},
{
"whether_in_form": true,
"key": {
"name": "产地2",
"pos": [
{
"x": 373,
"y": 89
},
{
"x": 474,
"y": 89
},
{
"x": 474,
"y": 132
},
{
"x": 373,
"y": 132
}
],
"prob": 100
},
"type": "object",
"value": {
"text": "印尼829509-678",
"pos": [
{
"x": 474,
"y": 89
},
{
"x": 743,
"y": 89
},
{
"x": 743,
"y": 132
},
{
"x": 474,
"y": 132
}
],
"prob": 100
}
},
{
"whether_in_form": true,
"key": {
"name": "注意事项",
"pos": [
{
"x": 373,
"y": 132
},
{
"x": 474,
"y": 132
},
{
"x": 474,
"y": 174
},
{
"x": 373,
"y": 174
}
],
"prob": 100
},
"type": "object",
"value": {
"text": "不可高温烘干",
"pos": [
{
"x": 474,
"y": 132
},
{
"x": 743,
"y": 132
},
{
"x": 743,
"y": 174
},
{
"x": 474,
"y": 174
}
],
"prob": 100
}
},
{
"whether_in_form": true,
"key": {
"name": "面料",
"pos": [
{
"x": 4,
"y": 89
},
{
"x": 107,
"y": 89
},
{
"x": 107,
"y": 132
},
{
"x": 5,
"y": 132
}
],
"prob": 100
},
"type": "object",
"value": {
"text": "聚酯纤维",
"pos": [
{
"x": 107,
"y": 89
},
{
"x": 373,
"y": 89
},
{
"x": 373,
"y": 132
},
{
"x": 107,
"y": 132
}
],
"prob": 100
}
},
{
"whether_in_form": true,
"key": {
"name": "洗涤建议",
"pos": [
{
"x": 5,
"y": 132
},
{
"x": 107,
"y": 132
},
{
"x": 107,
"y": 174
},
{
"x": 5,
"y": 174
}
],
"prob": 100
},
"type": "object",
"value": {
"text": "冷水机洗",
"pos": [
{
"x": 107,
"y": 132
},
{
"x": 373,
"y": 132
},
{
"x": 373,
"y": 174
},
{
"x": 107,
"y": 174
}
],
"prob": 100
}
},
{
"whether_in_form": true,
"key": {
"name": "商品介绍",
"pos": [
{
"x": 5,
"y": 174
},
{
"x": 107,
"y": 174
},
{
"x": 107,
"y": 424
},
{
"x": 5,
"y": 424
}
],
"prob": 100
},
"type": "object",
"value": {
"text": "NikeSBShieldCoaches男子夹克采用透气的抗水设计,让你畅享干爽舒适的训练体验。抗水NikeShield面料有效提升气候适应性令你无惧天气变化,勇敢征战街头;透气设计,网眼布内层舒适透气,助你保持适宜温度;可调式贴合感,下摆抽绳设计打造专属贴合感,助你发挥出色表现;按扣式设计,方便穿脱,垂坠式后身下摆,提升包覆效果;",
"pos": [
{
"x": 107,
"y": 174
},
{
"x": 743,
"y": 174
},
{
"x": 743,
"y": 424
},
{
"x": 107,
"y": 424
}
],
"prob": 100
}
},
{
"type": "group",
"whether_in_form": true,
"value": [
{
"whether_in_form": true,
"key": {
"name": "尺码",
"pos": [
{
"x": 5,
"y": 466
},
{
"x": 107,
"y": 466
},
{
"x": 107,
"y": 509
},
{
"x": 5,
"y": 509
}
],
"prob": 100
},
"type": "list",
"value": [
{
"text": "XS",
"pos": [
{
"x": 107,
"y": 466
},
{
"x": 234,
"y": 466
},
{
"x": 234,
"y": 509
},
{
"x": 107,
"y": 509
}
],
"prob": 100
},
{
"text": "S",
"pos": [
{
"x": 234,
"y": 466
},
{
"x": 361,
"y": 466
},
{
"x": 361,
"y": 509
},
{
"x": 234,
"y": 509
}
],
"prob": 100
},
{
"text": "M",
"pos": [
{
"x": 361,
"y": 466
},
{
"x": 488,
"y": 466
},
{
"x": 488,
"y": 509
},
{
"x": 361,
"y": 509
}
],
"prob": 100
},
{
"text": "L",
"pos": [
{
"x": 488,
"y": 466
},
{
"x": 615,
"y": 466
},
{
"x": 615,
"y": 509
},
{
"x": 488,
"y": 509
}
],
"prob": 100
},
{
"text": "XL",
"pos": [
{
"x": 615,
"y": 466
},
{
"x": 743,
"y": 466
},
{
"x": 743,
"y": 509
},
{
"x": 615,
"y": 509
}
],
"prob": 100
}
]
},
{
"whether_in_form": true,
"key": {
"name": "衣长",
"pos": [
{
"x": 5,
"y": 509
},
{
"x": 107,
"y": 509
},
{
"x": 107,
"y": 551
},
{
"x": 5,
"y": 551
}
],
"prob": 100
},
"type": "list",
"value": [
{
"text": "73",
"pos": [
{
"x": 107,
"y": 509
},
{
"x": 234,
"y": 509
},
{
"x": 234,
"y": 551
},
{
"x": 107,
"y": 551
}
],
"prob": 100
},
{
"text": "74",
"pos": [
{
"x": 234,
"y": 509
},
{
"x": 361,
"y": 509
},
{
"x": 361,
"y": 551
},
{
"x": 234,
"y": 551
}
],
"prob": 100
},
{
"text": "75",
"pos": [
{
"x": 361,
"y": 509
},
{
"x": 488,
"y": 509
},
{
"x": 488,
"y": 551
},
{
"x": 361,
"y": 551
}
],
"prob": 100
},
{
"text": "76",
"pos": [
{
"x": 488,
"y": 509
},
{
"x": 615,
"y": 509
},
{
"x": 615,
"y": 551
},
{
"x": 488,
"y": 551
}
],
"prob": 100
},
{
"text": "77",
"pos": [
{
"x": 615,
"y": 509
},
{
"x": 743,
"y": 509
},
{
"x": 743,
"y": 551
},
{
"x": 615,
"y": 551
}
],
"prob": 100
}
]
},
{
"whether_in_form": true,
"key": {
"name": "胸围",
"pos": [
{
"x": 5,
"y": 551
},
{
"x": 107,
"y": 551
},
{
"x": 107,
"y": 593
},
{
"x": 5,
"y": 593
}
],
"prob": 100
},
"type": "list",
"value": [
{
"text": "85",
"pos": [
{
"x": 107,
"y": 551
},
{
"x": 234,
"y": 551
},
{
"x": 234,
"y": 593
},
{
"x": 107,
"y": 593
}
],
"prob": 100
},
{
"text": "90",
"pos": [
{
"x": 234,
"y": 551
},
{
"x": 361,
"y": 551
},
{
"x": 361,
"y": 593
},
{
"x": 234,
"y": 593
}
],
"prob": 100
},
{
"text": "95",
"pos": [
{
"x": 361,
"y": 551
},
{
"x": 488,
"y": 551
},
{
"x": 488,
"y": 593
},
{
"x": 361,
"y": 593
}
],
"prob": 100
},
{
"text": "100",
"pos": [
{
"x": 488,
"y": 551
},
{
"x": 615,
"y": 551
},
{
"x": 615,
"y": 593
},
{
"x": 488,
"y": 593
}
],
"prob": 100
},
{
"text": "105",
"pos": [
{
"x": 615,
"y": 551
},
{
"x": 743,
"y": 551
},
{
"x": 743,
"y": 593
},
{
"x": 615,
"y": 593
}
],
"prob": 100
}
]
},
{
"whether_in_form": true,
"key": {
"name": "穿着建议适合身高",
"pos": [
{
"x": 5,
"y": 593
},
{
"x": 107,
"y": 593
},
{
"x": 107,
"y": 677
},
{
"x": 4,
"y": 677
}
],
"prob": 100
},
"type": "list",
"value": [
{
"text": "155-165",
"pos": [
{
"x": 107,
"y": 593
},
{
"x": 234,
"y": 593
},
{
"x": 234,
"y": 677
},
{
"x": 107,
"y": 677
}
],
"prob": 100
},
{
"text": "160-170",
"pos": [
{
"x": 234,
"y": 593
},
{
"x": 361,
"y": 593
},
{
"x": 361,
"y": 677
},
{
"x": 234,
"y": 677
}
],
"prob": 100
},
{
"text": "165-175",
"pos": [
{
"x": 361,
"y": 593
},
{
"x": 488,
"y": 593
},
{
"x": 488,
"y": 677
},
{
"x": 361,
"y": 677
}
],
"prob": 100
},
{
"text": "170-180",
"pos": [
{
"x": 488,
"y": 593
},
{
"x": 615,
"y": 593
},
{
"x": 615,
"y": 677
},
{
"x": 488,
"y": 677
}
],
"prob": 100
},
{
"text": "175-185",
"pos": [
{
"x": 615,
"y": 593
},
{
"x": 743,
"y": 593
},
{
"x": 743,
"y": 677
},
{
"x": 615,
"y": 677
}
],
"prob": 100
}
]
}
]
}
],
// csv格式
"csvs": [
"KV对\n商品名称,NIKESBCOACHES樱花粉男女教练夹克\n\nKV对\n商品品牌,耐克\n\nKV对\n产地1,中国829510-678\n产地2,印尼829509-678\n注意事项,不可高温烘干\n\nKV对\n面料,聚酯纤维\n\nKV对\n洗涤建议,冷水机洗\n\nKV对\n商品介绍,NikeSBShieldCoaches男子夹克采用透气的抗水设计,让你畅享干爽舒适的训练体验。抗水NikeShield面料有效提升气候适应性令你无惧天气变化,勇敢征战街头;透气设计,网眼布内层舒适透气,助你保持适宜温度;可调式贴合感,下摆抽绳设计打造专属贴合感,助你发挥出色表现;按扣式设计,方便穿脱,垂坠式后身下摆,提升包覆效果;\n\nKV列表\n尺码,衣长,胸围,穿着建议适合身高\nXS,73,85,155-165\nS,74,90,160-170\nM,75,95,165-175\nL,76,100,170-180\nXL,77,105,175-185\n\n"
],
"type": ""
}

失败返回示例:

{
"error_code": 400,
"error_msg": "img和url参数不能同时存在"
}

错误码定义:

错误码错误信息描述
400参数错误具体错误请参考返回的error_msg
401您无该功能的权限,请开通后使用您无该功能的权限,请开通后使用
403购买的容量已用完或者签名错误购买的容量已用完或者签名错误
500服务器错误,请稍后重试服务器错误,请稍后重试