Я пытаюсь создать приложение OCR на Android, используя Tesseract
, но когда я сохраняю картинку, приложение обрушивается
Вот код, который я использую:
public class MainActivity extends AppCompatActivity {
Bitmap image;
private TessBaseAPI mTess;
String datapath = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//init image
image = BitmapFactory.decodeResource(getResources(), R.drawable.test_ara);
//initialize Tesseract API
String language = "ra";
datapath = getFilesDir()+ "/tesseract/";
mTess = new TessBaseAPI();
checkFile(new File(datapath + "tessdata/"));
mTess.init(datapath, language);
}
public void processImage(View view){
String OCRresult = null;
mTess.setImage(image);
OCRresult = mTess.getUTF8Text();
TextView OCRTextView = (TextView) findViewById(R.id.OCRTextView);
OCRTextView.setText(OCRresult);
}
private void checkFile(File dir) {
if (!dir.exists()&& dir.mkdirs()){
copyFiles();
}
if(dir.exists()) {
String datafilepath = datapath+ "/tessdata/ara.traineddata";
File datafile = new File(datafilepath);
if (!datafile.exists()) {
copyFiles();
}
}
}
private void copyFiles() {
try {
String filepath = datapath + "/tessdata/ara.traineddata";
AssetManager assetManager = getAssets();
InputStream instream = assetManager.open("tessdata/ara.traineddata");
OutputStream outstream = new FileOutputStream(filepath);
byte[] buffer = new byte[1024];
int read;
while ((read = instream.read(buffer)) != -1) {
outstream.write(buffer, 0, read);
}
outstream.flush();
outstream.close();
instream.close();
File file = new File(filepath);
if (!file.exists()) {
throw new FileNotFoundException();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
и это ошибка журнала:
2019-11-09 12:31:15.792 10381-10381/? E/e.myapplicatio: No implementation found for void com.example.myapplication.googlecode.tesseract.android.TessBaseAPI.nativeClassInit() (tried Java_com_example_myapplication_googlecode_tesseract_android_TessBaseAPI_nativeClassInit and Java_com_example_myapplication_googlecode_tesseract_android_TessBaseAPI_nativeClassInit__)
2019-11-09 12:31:15.793 10381-10381/? D/AndroidRuntime: Shutting down VM
2019-11-09 12:31:15.795 10381-10381/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 10381
java.lang.UnsatisfiedLinkError: No implementation found for void com.example.myapplication.googlecode.tesseract.android.TessBaseAPI.nativeClassInit() (tried Java_com_example_myapplication_googlecode_tesseract_android_TessBaseAPI_nativeClassInit and Java_com_example_myapplication_googlecode_tesseract_android_TessBaseAPI_nativeClassInit__)
at com.example.myapplication.googlecode.tesseract.android.TessBaseAPI.nativeClassInit(Native Method)
at com.example.myapplication.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:50)
at com.example.myapplication.MainActivity.onCreate(MainActivity.java:40)
at android.app.Activity.performCreate(Activity.java:7335)
at android.app.Activity.performCreate(Activity.java:7326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1275)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3282)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1970)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7156)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
Пожалуйста, помогите мне в этом.
Спасибо.