提取和识别图片中的数字。
无参数
无参数
名称 | 类型 | 是否必须 | 描述 |
---|---|---|---|
secret_key | string | true | 用户授权key |
secret_code | string | true | 接口编号 |
secret_sign | string | true | 加密签名:md5(secret_key+secret_secret)转大写 |
image | string | true | 图像数据,base64编码。最短边至少15px,最长边最大4096px |
recognizeGranularity | string | true | 是否定位单字符位置,big:不定位单字符位置,默认值;small:定位单字符位置 |
detectDirection | boolean | true | 是否检测图像朝向,默认不检测,即:false。可选值包括true - 检测朝向;false - 不检测朝向。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。 |
curl http://cloud.kuaidi100.com/api -X POST -d \
"secret_key=***&secret_code=c9b26b2e815e4d60b03c2b10226ea62b&secret_sign=md5(***)&image=&recognizeGranularity=big&detectDirection=false"
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
public class CloudDemo {
public static void main (String[] args) {
CloudDemo cloudDemo = new CloudDemo();
Map params = new HashMap();
params.put("secret_key", "***");
params.put("secret_code", "c9b26b2e815e4d60b03c2b10226ea62b");
params.put("secret_sign", "md5(***)");
params.put("image", "");
params.put("recognizeGranularity", "big");
params.put("detectDirection", "false");
cloudDemo.post(params);
}
public String post(Map params) {
StringBuilder response = new StringBuilder("");
BufferedReader reader = null;
try {
StringBuilder builder = new StringBuilder();
for (Map.Entry param : params.entrySet()) {
if (builder.length() > 0) {
builder.append('&');
}
builder.append(URLEncoder.encode(param.getKey(), "UTF-8"));
builder.append('=');
builder.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
byte[] bytes = builder.toString().getBytes("UTF-8");
URL url = new URL("http://cloud.kuaidi100.com/api");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
conn.setRequestMethod("POST");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(bytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(bytes);
reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line = "";
while ((line = reader.readLine()) != null) {
response.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != reader) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return response.toString();
}
}
class MD5Utils { private static MessageDigest mdigest = null;
private static char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
private static MessageDigest getMdInst() {
if (null == mdigest) {
try {
mdigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
return mdigest;
}
public static String encode(String s) {
if(null == s) {
return "";
}
try { byte[] bytes = s.getBytes();
getMdInst().update(bytes);
byte[] md = getMdInst().digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for(int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = digits[byte0 >>> 4 & 0xf];
str[k++] = digits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
暂无示例
<?php
$params = "";
$params .= 'secret_key=***'.'&';
$params .= 'secret_code=c9b26b2e815e4d60b03c2b10226ea62b'.'&';
$params .= 'secret_sign=md5(***)'.'&';
$params .= 'image='.'&';
$params .= 'recognizeGranularity=big'.'&';
$params .= 'detectDirection=false'.'&';
$params .= substr($params, 0, -1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, 'http://cloud.kuaidi100.com/api');
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
echo $result;
?>
# coding = utf-8
import sys,os
import requests,json,hashlib
params = {}
params['secret_key'] = '***'
params['secret_code'] = 'c9b26b2e815e4d60b03c2b10226ea62b'
params['secret_sign'] = 'md5(***)'
params['image'] = ''
params['recognizeGranularity'] = 'big'
params['detectDirection'] = 'false'
result = requests.post('http://cloud.kuaidi100.com/api', params)
print(result.text)
无参数
{
"code": 200, //状态码
"message": "success",
"data": {
"taskId": "2799513649690627707", //唯一的taskid,用于问题定位
"direction": null,
"wordsResultNum": 3, //识别结果数,表示words_result的元素个数
"wordsResult": [ //定位和识别结果数组
{
"chars": null, //单字符结果
"location": { //位置数组(坐标0点为左上角)
"x": 605, //表示定位位置的长方形左上顶点的水平坐标
"y": 340, //表示定位位置的长方形左上顶点的垂直坐标
"width": 270, //表示定位位置的长方形的宽度
"height": 30 //表示定位位置的长方形的高度
},
"text": "543543777555638" //识别文字的结果
},
{
"chars": null,
"location": {
"x": 952,
"y": 453,
"width": 216,
"height": 31
},
"text": "17600987577"
},
{
"chars": null,
"location": {
"x": 953,
"y": 657,
"width": 213,
"height": 29
},
"text": "15798448856"
}
]
}
}
{
"code": 10003,
"message": "缺少必填参数:image",
"data": null
}
状态码 | 状态码信息 | 描述 |
---|---|---|
200 | success | 成功 |
提取和识别图片中的数字,自动过滤非数字内容,仅返回数字内容及位置信息。