Add the JitPack repository to your project root build.gradle file at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency to your app module build.gradle file:
dependencies {
// To use Standard variant:
implementation 'cz.adaptech:tesseract4android:4.1.1'
// To use OpenMP variant:
// NOTE: This variant is currently unavailable due to issues with JitPack. You must compile it yourself.
//implementation 'cz.adaptech:tesseract4android-openmp:4.1.1'
}
Use the TessBaseAPI class in your code:
// Create Tesseract instance
TessBaseAPI tess = new TessBaseAPI();
// Given path must contain subdirectory `tessdata` where are `*.traineddata` language files
String dataPath = new File(Environment.getExternalStorageDirectory(), "tesseract").getAbsolutePath();
// Initialize API for specified language (can be called multiple times during Tesseract lifetime)
if (!tess.init(dataPath, "eng")) {
// Error initializing Tesseract (wrong data path or language)
tess.recycle();
return;
}
// Specify image and then recognize it and get result (can be called multiple times during Tesseract lifetime)
tess.setImage(image);
String text = tess.getUTF8Text();
// Release Tesseract when you don't want to use it anymore
tess.recycle();
Tesseract4Android
最新推荐文章于 2024-04-15 09:31:23 发布