导言
OCR,tess-two ,openCV等晕人的东西先分清,OCR,tess-two是图片文字识别,而openCV是图像识别比对,对于更复杂的图片文字识别需求可以采用百度云人工智能通用文字识别开发的SDK,准确性更高
可运行的步骤
1、添加依赖
implementation 'com.rmtheis:tess-two:8.0.0'
2、下载字体识别库(chi_sim.traineddata 中文简体,chi_tra.traineddata 中文繁体,eng.traineddata 英文库)
3、为了apk的大小,我们需要将字体识别库文件拷贝到SD卡目录中,比如eng.traineddata的copy
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初始化
TessBaseAPI baseApi;
baseApi = new TessBaseAPI();
baseApi.init(mDataPath, "eng");
5、处理bitmap图片并识别里面的内容
//OCR图片文字识别
baseApi.setImage(bitmap);
String result = baseApi.getUTF8Text().replace(" ", "").toLowerCase();
6、他要求看需求,本文结束
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)