检测和识别图片中的文字,支持多语种识别
无参数
无参数
名称 | 类型 | 是否必须 | 描述 |
---|---|---|---|
secret_key | string | true | 用户授权key |
secret_code | string | true | 接口编号 |
secret_sign | string | true | 加密签名:md5(secret_key+secret_secret)转大写 |
image | string | true | 图像数据,base64编码。最短边至少15px,最长边最大4096px |
imageUrl | string | true | 图片完整URL。当image字段存在时imageUrl字段失效,不支持https的图片链接 |
languageType | string | true | 识别语言类型,默认为CHN_ENG。可选值包括:CHN_ENG:中英文混合;ENG:英文;POR:葡萄牙语;FRE:法语;GER:德语;ITA:意大利语;SPA:西班牙语;RUS:俄语;JAP:日语;KOR:韩语 |
detectDirection | string | true | 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度 |
detectLanguage | string | true | 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语) |
probability | string | true | 是否返回识别结果中每一行的置信度 |
curl http://cloud.kuaidi100.com/api -X POST -d \
"secret_key=***&secret_code=1f74dc27ae84440c9245e56badc9da15&secret_sign=md5(***)&image=&imageUrl=&languageType=CHN_ENG&detectDirection=false&detectLanguage=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", "1f74dc27ae84440c9245e56badc9da15");
params.put("secret_sign", "md5(***)");
params.put("image", "");
params.put("imageUrl", "");
params.put("languageType", "CHN_ENG");
params.put("detectDirection", "false");
params.put("detectLanguage", "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=1f74dc27ae84440c9245e56badc9da15'.'&';
$params .= 'secret_sign=md5(***)'.'&';
$params .= 'image='.'&';
$params .= 'imageUrl='.'&';
$params .= 'languageType=CHN_ENG'.'&';
$params .= 'detectDirection=false'.'&';
$params .= 'detectLanguage=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'] = '1f74dc27ae84440c9245e56badc9da15'
params['secret_sign'] = 'md5(***)'
params['image'] = ''
params['imageUrl'] = ''
params['languageType'] = 'CHN_ENG'
params['detectDirection'] = 'false'
params['detectLanguage'] = 'false'
params['probability'] = 'false'
result = requests.post('http://cloud.kuaidi100.com/api', params)
print(result.text)
无参数
{
"code": 200,
"message": "success",
"data": {
"taskId": "5255445707831999483", //唯一的taskid,用于问题定位
"direction": 0, //图像方向,当detect_direction=true时存在。
"wordsResult": [
{
"text": "长恨歌", //识别结果字符串
"probability": { //识别结果中每一行的置信度值
"average": 0.974127, //行置信度平均值
"variance": 0.001217, //行置信度方差
"min": 0.900807 //行置信度最小值
}
},
{
"text": "作者:白居易",
"probability": {
"average": 0.906242,
"variance": 0.004539,
"min": 0.81699
}
},
{
"text": "汉皇重色思倾国,御宇多年求不得。",
"probability": {
"average": 0.976622,
"variance": 0.002007,
"min": 0.850192
}
},
{
"text": "杨家有女初长成,并在深国人未识。",
"probability": {
"average": 0.926022,
"variance": 0.022327,
"min": 0.492522
}
}
],
"wordsResultNum": 11, //识别结果数,表示words_result的元素个数
"language": 3 //当detect_language=true时存在
}
}
{
"code": 10003,
"message": "缺少必填参数:image或imageUrl",
"data": null
}
状态码 | 状态码信息 | 描述 |
---|---|---|
200 | success | 成功 |
支持多语种识别(中、英、法、俄、西、葡、德、意、日、韩、中英混合),并支持中、英、日、韩四语种的类型检测