表格提取与excel导出接口文档

调用地址:https://tableexcel.market.alicloudapi.com/ocrservice/tableExcel
请求方式: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": ""
}

请求代码示例:

java版

    public static void main(String[] args) {
String url = "http://tableexcel.market.alicloudapi.com/ocrservice/tableExcel";
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 = "{\"img\":\"\",\"url\":\"\"}";
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 = "http://tableexcel.market.alicloudapi.com";
private const String path = "/ocrservice/tableExcel";
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\":\"\"}";
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 = "http://tableexcel.market.alicloudapi.com";
$path = "/ocrservice/tableExcel";
$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\":\"\"}";
$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 = 'http://tableexcel.market.alicloudapi.com'
path = '/ocrservice/tableExcel'
method = 'POST'
appcode = '你自己的AppCode'
querys = ''
bodys = {}
url = host + path

bodys[''] = "{\"img\":\"\",\"url\":\"\"}"
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://tableexcel.market.alicloudapi.com/ocrservice/tableExcel"
dict = {'img': encodestr}

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

正常返回示例:

{
//唯一id,用于问题定位
"sid": "bfcb418f71fd057f11ea4e17b15688dc27f9d4c6a47a867a376f251706266353341da54c",
//算法版本
"prism_version": "1.0.6",
//识别的文字块的数量,prism_wordsInfo数组大小
"prism_wnum": 2,
//角度,
"angle": 范围:0-360,0表示向上,90表示向右,180表示向下,270度表示向左
//识别的文字的具体内容
"prism_wordsInfo": [
{
//文字块
"word": "2017",
//置信度
"prob": 99,
//文字块的位置,按照文字块四个角的坐标顺时针排列,分别为左上XY坐标、右上XY坐标、右下XY坐标、左下XY坐标
"pos": [
{
"x": 107,
"y": 203
},
{
"x": 247,
"y": 203
},
{
"x": 247,
"y": 213
},
{
"x": 107,
"y": 213
}
],
//单字信息
"charInfo": [
{
//单字文字
"word": "2",
//单字置信度
"prob": 99,
//单字左上角横坐标
"x": 777,
//单字左上角纵坐标
"y": 2993,
//单字宽度
"w": 26,
//单字长度
"h": 30
},
{
"word": "0",
"prob": 99,
"x": 803,
"y": 2989,
"w": 32,
"h": 37
},
{
"word": "1",
"prob": 99,
"x": 835,
"y": 2989,
"w": 38,
"h": 39
},
{
"word": "7",
"prob": 99,
"x": 873,
"y": 2988,
"w": 38,
"h": 40
}
],
//如果该文字块在表格内则存在该字段,tableId表示表格的id
"tableId": 0,
//如果该文字块在表格内则存在该字段,表示表格中单元格的id
"tableCellId": 0
}
],
//表格信息,如果不存在表格,则改字段内容为空
"prism_tablesInfo": [
{
//表格id,和prism_wordsInfo信息中的tableId对应
"tableId": 0,
//表格中横坐标单元格的数量
"xCellSize": 1,
//表格中纵坐标单元格的数量
"yCellSize": 1,
//单元格信息,包含单元格在整个表格中的空间拓扑关系
"cellInfos": [
{
//表格中单元格id,和prism_wordsInfo信息中的tableCellId对应
"tableCellId": 0,
//单元格中的文字
"word": ":2017",
//xStartCell缩写,表示横轴方向该单元格起始在第几个单元格,第一个单元格值为0
"xsc": 0,
//xEndCell缩写,表示横轴方向该单元格结束在第几个单元格,第一个单元格值为0,如果xsc和xec都为0说明该文字在横轴方向占据了一个单元格并且在第一个单元格内
"xec": 0,
//yStartCell缩写,表示纵轴方向该单元格起始在第几个单元格,第一个单元格值为0
"ysc": 0,
//yEndCell缩写,表示纵轴方向该单元格结束在第几个单元格,第一个单元格值为0
"yec": 0,
//单元格位置,按照单元格四个角的坐标顺时针排列,分别为左上XY坐标、右上XY坐标、右下XY坐标、左下XY坐标
"pos": [
{
"x": 107,
"y": 203
},
{
"x": 247,
"y": 203
},
{
"x": 247,
"y": 213
},
{
"x": 107,
"y": 213
}
]
}
]
}
]
// excel文件base64内容
"fileBase64": ""
}

失败返回示例:

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

错误码定义:

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