0 down vote favorite
<http://stackoverflow.com/questions/32584628/tesseract-ocr-returns-null-string#>
I am building an OCR app for android and i use tesseract ocr engine.
Somehow every time i use the engine on a photo it returns an empty text.
This is my code:
public String detectText(Bitmap bitmap) {
TessBaseAPI tessBaseAPI = new TessBaseAPI();
String mDataDir = setTessData();
tessBaseAPI.setDebug(true);
tessBaseAPI.init(mDataDir + File.separator, "eng");
tessBaseAPI.setImage(bitmap);
tessBaseAPI.setPageSegMode(TessBaseAPI.OEM_TESSERACT_ONLY);
String text = tessBaseAPI.getUTF8Text();
tessBaseAPI.end();
return text;}
private String setTessData(){
String mDataDir = this.getExternalFilesDir("data").getAbsolutePath();
String mTrainedDataPath = mDataDir + File.separator + "tessdata";
String mLang = "eng";
// Checking if language file already exist inside data folder
File dir = new File(mTrainedDataPath);
if (!dir.exists()) {
if (!dir.mkdirs()) {
//showDialogFragment(SD_ERR_DIALOG, "sd_err_dialog");
} else {
}
}
if (!(new File(mTrainedDataPath + File.separator + mLang +
".traineddata")).exists()) {
// If English or Hebrew, we just copy the file from assets
if (mLang.equals("eng") || mLang.equals("heb")){
try {
AssetManager assetManager = context.getAssets();
InputStream in = assetManager.open(mLang + ".traineddata");
OutputStream out = new FileOutputStream(mTrainedDataPath +
File.separator + mLang + ".traineddata");
copyFile(in, out);
//Toast.makeText(context, getString(R.string.selected_language)
+ " " + mLangArray[mLangID], Toast.LENGTH_SHORT).show();
//Log.v(TAG, "Copied " + mLang + " traineddata");
} catch (IOException e) {
//showDialogFragment(SD_ERR_DIALOG, "sd_err_dialog");
}
}
else{
// Checking if Network is available
if (!isNetworkAvailable(this)){
//showDialogFragment(NETWORK_ERR_DIALOG, "network_err_dialog");
}
else {
// Shows a dialog with File dimension. When user click on OK
download starts. If he press Cancel revert to english language (like NETWORK
ERROR)
//showDialogFragment(CONTINUE_DIALOG, "continue_dialog");
}
}
}
else {
//Toast.makeText(mThis, getString(R.string.selected_language) + " " +
mLangArray[mLangID], Toast.LENGTH_SHORT).show();
}
return mDataDir;}
I have debugged it many times and the bitmap is being transferred correctly
to the detectText method. The language data files(tessdata) exists on the
phone and the path to them is also correct.
Does anybody knows what the problem here?
--
You received this message because you are subscribed to the Google Groups
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tesseract-ocr/7ea2c58a-503f-45c9-bbad-c4540a3fabc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.