我是靠谱客的博主 可爱猫咪,这篇文章主要介绍分享一个免费的OCR图片文字识别接口,现在分享给大家,希望可以做个参考。

此接口为每天100次免费,应对平时自己调试使用也够了~
亲测准确度还不错。

请求地址

https://api.itapi.cn/api/ocr/v2

请求参数

参数名参数说明
key用户请求密钥,可在 密钥管理页面 申请
data图片base64编码数据 或 网络图片URL

请求结果参数说明

参数名参数说明
code状态码
msg状态信息
debug错误信息
exec_time系统执行时间
user_ip你的ip
data请求结果数据集
data.text识别到的完整文本内容(注意换行符)
data.text_list[]识别到的每行文本结果数组

POST同时支持图片url和base64数据提交,get仅支持图片url提交。

代码案例

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/** * 图片转Base64 */ public static String getImageBase() throws Exception { byte[] data = null; // 读取图片字节数组 try { InputStream in = new FileInputStream("本地文件路径"); data = new byte[in.available()]; in.read(data); in.close(); } catch (IOException e) { e.printStackTrace(); } // 对字节数组Base64编码 BASE64Encoder encoder = new BASE64Encoder(); return encoder.encode(data);// 返回Base64编码过的字节数组字符串 } /** * 向指定 URL 发送POST方法的请求 */ public static String sendPost() throws Exception { Map<String, String> paramMap = new HashMap<String, String>(); paramMap.put("key", "用户请求秘钥"); paramMap.put("data", getImageBase()); URL url = new URL("https://api.itapi.cn/api/ocr/v2"); StringBuilder postData = new StringBuilder(); //接口不支持json传参,处理参数 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; }

最后

以上就是可爱猫咪最近收集整理的关于分享一个免费的OCR图片文字识别接口的全部内容,更多相关分享一个免费内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部