rmtheis / tess-two

Fork of Tesseract Tools for Android
Apache License 2.0
3.76k stars 1.38k forks source link

Hardcoded path in TessBaseAPITest.java #208

Closed Robyer closed 7 years ago

Robyer commented 7 years ago

TessBaseAPITest.java uses hardcoded path "/sdcard/tesseract/" instead of Environment.getExternalStorageDirectory() (or similar) as Lint warns. Why is the warning supressed? In current state everyone have to hardcode their own path when they want to run tests.

See https://github.com/rmtheis/tess-two/blob/master/tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java#L50-L51

EDIT: Furthermore, this path is not consistent with your readme for end users, see:

Pre-requisites

Android 2.3 or higher A v3.04 trained data file for a language. Data files must be copied to the Android device in a subdirectory named tessdata.

But tests currently uses <sdcard>/tesseract/tessdata instead of <sdcard>/tessdata as readme suggests. It would be good to use same path in tests.

rmtheis commented 7 years ago

Hmm--true. Currently it's set up this way so that preparetests.sh (or preparetests.cmd) can be run from the command line to install the training data into a known/standard location and clean up files before running the tests. If Environment.getExternalStorageDirectory() were used instead, then the install location wouldn't be known prior to runtime and the setup scripts wouldn't be usable as-is.

Do you have a suggestion for how to remove the hard-coded path in a way that also makes it easy to set up a device for testing?

Robyer commented 7 years ago

Oh, I see... I googled a bit and found a possible solution: https://android.stackexchange.com/a/14109/199338

So adb shell echo $EXTERNAL_STORAGE in preparetests.cmd (on Windows it works without escaping), and for linux perhaps adb shell echo \$EXTERNAL_STORAGE (but I didn't test this). This will give us in my case /sdcard string.

Then in Java we can use System.getenv("EXTERNAL_STORAGE") which will give us the same value /sdcard. Note when using Environment.getExternalStorageDirectory().getAbsolutePath() I will get /storage/emulated/0 in my case (Samsung Galaxy S7),but I believe it points to the same directory in filesystem as I tried using both in TessBaseAPITest and both worked.

So this works: static final String TESSBASE_PATH = System.getenv("EXTERNAL_STORAGE") + "/";

rmtheis commented 7 years ago

I just re-read your second comment and I see that your suggestion differs a little from the change I just pushed. Let me know if that change doesn't work for you.

Robyer commented 7 years ago

It works 👍