Tesseract OCR引起:java.lang.IllegalArgumentException:数据路径不存在

时间:2016-06-19 10:05:03

标签: android ocr tesseract

我正在创建简单的OCR应用程序以下链接。我所做的一切&现在我正在尝试构建/编译应用程序但是低于错误

Caused by: java.lang.IllegalArgumentException: Data path does not exist!

我的代码是:

    public class MainActivity extends AppCompatActivity {

        private ImageView imageView;
        private Bitmap bitmap;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            imageView = (ImageView) findViewById(R.id.imageView);
            imageView.setImageResource(R.drawable.textimage);

            bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();

            TessBaseAPI baseApi = new TessBaseAPI();
            baseApi.init("/mnt/sdcard/tesseract/tessdata/eng.trainedata", "eng");

/* Also tried
     baseApi.init("/mnt/sdcard/tesseract/", "eng");
     baseApi.init("/mnt/sdcard/tesseract/tessdata/", "eng");
*/
            baseApi.setImage(bitmap);
            Log.v("....Text...", "....");
            String recognizedText = baseApi.getUTF8Text();
            Log.v("....Text...", " " + recognizedText);
            baseApi.end();
        }
    }

我得到的错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ts.myapplicationtest1/com.ts.myapplicationtest1.MainActivity}: java.lang.IllegalArgumentException: Data path does not exist!
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalArgumentException: Data path does not exist!
at com.googlecode.tesseract.android.TessBaseAPI.init(TessBaseAPI.java:303)
at com.googlecode.tesseract.android.TessBaseAPI.init(TessBaseAPI.java:280)
at com.ts.myapplicationtest1.MainActivity.onCreate(MainActivity.java:34)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

请参阅我的手机目录的数据集截图:

Screenshot

1 个答案:

答案 0 :(得分:0)

Datapath设置为tessdata文件夹的父文件夹,因此它应为/mnt/sdcard/tesseract/