识别文字,并返回文字在图片中的位置信息
无参数
无参数
名称 | 类型 | 是否必须 | 描述 |
---|---|---|---|
secret_key | string | true | 用户授权key |
secret_code | string | true | 接口编号 |
secret_sign | string | true | 加密签名:md5(secret_key+secret_secret)转大写 |
image | string | true | 图像数据,base64编码。最短边至少15px,最长边最大4096px。当image字段存在时url字段失效 |
imageUrl | string | true | 图片完整url,长度不超过1024字节,当image字段存在时imageUrl字段失效 |
recognizeGranularity | string | true | 是否定位单字符位置,big:不定位单字符位置,默认值;small:定位单字符位置 |
languageType | string | true | 识别语言类型,默认为CHN_ENG。可选值包括:CHN_ENG:中英文混合(默认);ENG:英文;POR:葡萄牙语;FRE:法语;GER:德语;ITA:意大利语;SPA:西班牙语;RUS:俄语;JAP:日语;KOR:韩语 |
detectDirection | boolean | true | 是否检测图像朝向,默认不检测,即:false |
detectLanguage | boolean | true | 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语) |
vertexesLocation | boolean | true | 是否返回文字外接多边形顶点位置,不支持单字位置。默认为false |
probability | boolean | true | 是否返回识别结果中每一行的置信度 |
curl http://cloud.kuaidi100.com/api -X POST -d \
"secret_key=***&secret_code=12e1f09717ca44f0b24314e74905204a&secret_sign=md5(***)&image=&imageUrl=&recognizeGranularity=big&languageType=CHN_ENG&detectDirection=false&detectLanguage=false&vertexesLocation=false&probability=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", "12e1f09717ca44f0b24314e74905204a");
params.put("secret_sign", "md5(***)");
params.put("image", "");
params.put("imageUrl", "");
params.put("recognizeGranularity", "big");
params.put("languageType", "CHN_ENG");
params.put("detectDirection", "false");
params.put("detectLanguage", "false");
params.put("vertexesLocation", "false");
params.put("probability", "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=12e1f09717ca44f0b24314e74905204a'.'&';
$params .= 'secret_sign=md5(***)'.'&';
$params .= 'image='.'&';
$params .= 'imageUrl='.'&';
$params .= 'recognizeGranularity=big'.'&';
$params .= 'languageType=CHN_ENG'.'&';
$params .= 'detectDirection=false'.'&';
$params .= 'detectLanguage=false'.'&';
$params .= 'vertexesLocation=false'.'&';
$params .= 'probability=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'] = '12e1f09717ca44f0b24314e74905204a'
params['secret_sign'] = 'md5(***)'
params['image'] = ''
params['imageUrl'] = ''
params['recognizeGranularity'] = 'big'
params['languageType'] = 'CHN_ENG'
params['detectDirection'] = 'false'
params['detectLanguage'] = 'false'
params['vertexesLocation'] = 'false'
params['probability'] = 'false'
result = requests.post('http://cloud.kuaidi100.com/api', params)
print(result.text)
无参数
{
"code": 200,
"message": "success",
"data": {
"taskId": "8033257463106111835", //唯一的taskid,用于问题定位
"direction": null, //图像方向,当detect_direction=true时存在。
"wordsResult": [
{
"vertexesLocation": null, //当前为四个顶点: 左上,右上,右下,左下。当vertexes_location=true时存在
"probability": null, //识别结果中每一行的置信度值,包含average:行置信度平均值,variance:行置信度方差,min:行置信度最小值
"chars": null,
"minFinegrainedVertexesLocation": null,
"finegrainedVertexesLocation": null,
"location": { //位置数组(坐标0点为左上角)
"x": 3, //表示定位位置的长方形左上顶点的水平坐标
"y": 2, //表示定位位置的长方形左上顶点的垂直坐标
"width": 127, //表示定位位置的长方形的宽度
"height": 21 //表示定位位置的长方形的高度
},
"text": "长恨歌百度汉语" //识别结果字符串
},
{
"vertexesLocation": null,
"probability": null,
"chars": null,
"minFinegrainedVertexesLocation": null,
"finegrainedVertexesLocation": null,
"location": {
"x": 7,
"y": 30,
"width": 81,
"height": 18
},
"text": "作者:白居易"
}
],
"wordsResultNum": 11, //识别结果数,表示words_result的元素个数
"language": null
}
}
{
"code": 10003,
"message": "缺少必填参数:image或imageUrl",
"data": null
}
状态码 | 状态码信息 | 描述 |
---|---|---|
200 | success | 成功 |
识识别图片中的文字,并返回文字在图片中的位置信息,可以用于二次处理。