导言 OCR,tess-two ,OpenCV等晕人的东西先分清,OCR,tess-two是图片文字识别,而openCV是图像识别比对,对于更复杂的图片文字识别需求可以采用百度云人工
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、他要求看需求,本文结束
--结束END--
本文标题: Android实现图片文字识别
本文链接: https://www.lsjlt.com/news/130224.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0