I am developing an Android OCR project. In my project, I am using tess-two. But I am having problem with initializing trainned data from tessdata folder for tess-two.
I installed tess-two in grandle like this
dependencies {
compile 'com.rmtheis:tess-two:6.0.2'
}
Then I tried detect text from bitmap like this
public String detectText(Bitmap bitmap) {
TessBaseAPI tessBaseAPI = new TessBaseAPI();
tessBaseAPI.setDebug(true);
tessBaseAPI.init(DATA_PATH, "eng"); //Init the Tess with the trained data file, with english language
//For example if we want to only detect numbers
tessBaseAPI.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "1234567890");
tessBaseAPI.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST, "!@#$%^&*()_+=-qwertyuiop[]}{POIU" +
"YTREWQasdASDfghFGHjklJKLl;L:'\"\\|~`xcvXCVbnmBNM,./<>?");
tessBaseAPI.setImage(bitmap);
String text = tessBaseAPI.getUTF8Text();
tessBaseAPI.end();
return text;
}
That is fired when a button is clicked. My activity includes only that function. The problem is with data path variable.
This is my project structure
Yes, I added two tessdata folders to demonstrate two scenarios.
First try. I set DATA_PATH like this
DATA_PATH = Environment.getRootDirectory().getPath()+"/data/";
That gives me "Data path does not exist!" error. So I found these solutions Tesseract OCR Android tessdata directory not found and Get path of data directory(android) .
So I tried to set DATA_PATH like this
DATA_PATH = Environment.getRootDirectory().getPath();
It gives me "Data path must contain subfolder tessdata!" error.
Then I tried this
DATA_PATH = Environment.getRootDirectory().getPath()+"/data/tessdata/";
Then I gives me this error again "Data path does not exist!".
Then I tried this way
DATA_PATH = Environment.getRootDirectory().getPath()+"/tessdata/";
It gives me this error "Data path does not exist!".
So all the ways I tried are not working. How can I initialize tessdata folder correctly? I have no idea to set the path for it.