0

I am trying to integrate Tesseract in android. So I have to initialize the tesseract with trained data by calling baseApi.init(DATA_PATH, lang). DATA_PATH is the path of traineddata.lang file which is to be put in assests folder then in tessdata folder in String format.But I am not able to find a way to do this and getting this error repeatedly.

02-20 19:26:17.574: W/dalvikvm(4427): threadid=1: thread exiting with uncaught exception (group=0x41cf9da0)
02-20 19:26:17.584: E/AndroidRuntime(4427): FATAL EXCEPTION: main
02-20 19:26:17.584: E/AndroidRuntime(4427): Process: com.example.helloworld, PID: 4427
02-20 19:26:17.584: >E/AndroidRuntime(4427): java.lang.IllegalArgumentException: Data path must contain subfolder tessdata!
02-20 19:26:17.584: >E/AndroidRuntime(4427): at com.googlecode.tesseract.android.TessBaseAPI.init(TessBaseAPI.java:283)

I have already used these and not able to proceed further.

  • String DATA_PATH = "file:///assets/tessdata/eng.traineddata";
  • String DATA_PATH = "file://android_assest/tessdata/eng.traineddata";

also using both with URI also.

1 Answers1

0

A quite from https://developer.android.com/tools/projects/index.html

You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager. For example, this is a good location for textures and game data.

So you can't get path on asset file, as well as it would be inside apk. In order to get path of file, you can read file and save on SD card.

Community
  • 1
  • 1
Divers
  • 9,531
  • 7
  • 45
  • 88
  • I don't have to take input from the file myself but only have to pass the path as String format and the in-built function will do the processing what it have to do. Also apk might have been saved in internal memory of the phone. – Ishabh Gupta Feb 20 '15 at 14:20
  • Please read what I wrote. Read asset file and write it to sd card and you will be able to get a path to that. – Divers Feb 20 '15 at 14:23
  • What if there is no SD Card in the phone? – Ishabh Gupta Feb 20 '15 at 14:30