我是靠谱客的博主 温婉眼睛,这篇文章主要介绍Android实现图片文字识别,现在分享给大家,希望可以做个参考。

导言

OCR,tess-two ,openCV等晕人的东西先分清,OCR,tess-two是图片文字识别,而openCV是图像识别比对,对于更复杂的图片文字识别需求可以采用百度云人工智能通用文字识别开发的SDK,准确性更高

可运行的步骤

1、添加依赖

复制代码
1
implementation 'com.rmtheis:tess-two:8.0.0'

2、下载字体识别库(chi_sim.traineddata 中文简体,chi_tra.traineddata 中文繁体,eng.traineddata 英文库)

3、为了apk的大小,我们需要将字体识别库文件拷贝到SD卡目录中,比如eng.traineddata的copy

复制代码
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
private String mDataPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator; private String mFilePath = mDataPath + File.separator + "tessdata" + File.separator + "eng.traineddata"; private void copyFile() { try { File mFile = new File(mFilePath); if (mFile.exists()) { mFile.delete(); } if (!mFile.exists()) { File p = new File(mFile.getParent()); if (!p.exists()) { p.mkdirs(); } try { mFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } OutputStream os = new FileOutputStream(mFilePath); InputStream is = this.getAssets().open("eng.traineddata"); byte[] buffer = new byte[1024]; int len = 0; while ((len = is.read(buffer)) != -1) { os.write(buffer, 0, len); } os.flush(); os.close(); is.close(); } catch (Exception e) { e.printStackTrace(); } }

4、tess two初始化

复制代码
1
2
3
TessBaseAPI baseApi; baseApi = new TessBaseAPI(); baseApi.init(mDataPath, "eng");

5、处理bitmap图片并识别里面的内容

复制代码
1
2
3
//OCR图片文字识别 baseApi.setImage(bitmap); String result = baseApi.getUTF8Text().replace(" ", "").toLowerCase();

6、他要求看需求,本文结束

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。

最后

以上就是温婉眼睛最近收集整理的关于Android实现图片文字识别的全部内容,更多相关Android实现图片文字识别内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部