此接口為每天100次免費(fèi),應(yīng)對(duì)平時(shí)自己調(diào)試使用也夠了~
親測(cè)準(zhǔn)確度還不錯(cuò)。
請(qǐng)求地址
https://api.itapi.cn/api/ocr/v2文章來源:http://www.zghlxwxcb.cn/news/detail-552422.html
請(qǐng)求參數(shù)
參數(shù)名 | 參數(shù)說明 |
---|---|
key | 用戶請(qǐng)求密鑰,可在 密鑰管理頁(yè)面 申請(qǐng) |
data | 圖片base64編碼數(shù)據(jù) 或 網(wǎng)絡(luò)圖片URL |
請(qǐng)求結(jié)果參數(shù)說明
參數(shù)名 | 參數(shù)說明 |
---|---|
code | 狀態(tài)碼 |
msg | 狀態(tài)信息 |
debug | 錯(cuò)誤信息 |
exec_time | 系統(tǒng)執(zhí)行時(shí)間 |
user_ip | 你的ip |
data | 請(qǐng)求結(jié)果數(shù)據(jù)集 |
data.text | 識(shí)別到的完整文本內(nèi)容(注意換行符) |
data.text_list[] | 識(shí)別到的每行文本結(jié)果數(shù)組 |
POST同時(shí)支持圖片url和base64數(shù)據(jù)提交,get僅支持圖片url提交。文章來源地址http://www.zghlxwxcb.cn/news/detail-552422.html
代碼案例
/**
* 圖片轉(zhuǎn)Base64
*/
public static String getImageBase() throws Exception {
byte[] data = null;
// 讀取圖片字節(jié)數(shù)組
try {
InputStream in = new FileInputStream("本地文件路徑");
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
// 對(duì)字節(jié)數(shù)組Base64編碼
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);// 返回Base64編碼過的字節(jié)數(shù)組字符串
}
/**
* 向指定 URL 發(fā)送POST方法的請(qǐng)求
*/
public static String sendPost() throws Exception {
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("key", "用戶請(qǐng)求秘鑰");
paramMap.put("data", getImageBase());
URL url = new URL("https://api.itapi.cn/api/ocr/v2");
StringBuilder postData = new StringBuilder();
//接口不支持json傳參,處理參數(shù)
for (Map.Entry<String,String> param : paramMap.entrySet()) {
if (postData.length() != 0) postData.append('&');
postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
postData.append('=');
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
byte[] postDataBytes = postData.toString().getBytes("UTF-8");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
StringBuilder sb = new StringBuilder();
for (int c; (c = in.read()) >= 0;)
sb.append((char)c);
String response = sb.toString();
return response;
}
到了這里,關(guān)于分享一個(gè)免費(fèi)的OCR圖片文字識(shí)別接口的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!