I have developed application for OCR using tesseract Library,
Application got exit during the execution of following code :
/*...
... Other Code stuff
...*/
protected Boolean doInBackground(String... arg0) {
/*...
... Other Code stuff
...*/
Pix pix = getPixFromBitmap(bitmap);
pix = preprocess(pix);
Pixa pixa = slice(pix); // Code Updated
try {
baseApi.setPageSegMode(TessBaseAPI.PSM_SINGLE_LINE);
int num = pixa.size();
for (int i = 0; i < num; i++) {
Pix pixi = pixa.getPix(i);
/*...
... Other Code stuff
...*/
}
pixa.recycle();
baseApi.end();
} catch (RuntimeException e) {
Log.e("OcrRecognizeAsyncTask","Caught RuntimeException in request to Tesseract. Setting state to CONTINUOUS_STOPPED.");
e.printStackTrace();
try {
// baseApi.clear();
activity.stopHandler();
} catch (NullPointerException e1) {
// Continue
}
return false;
}
private Pixa slice(Pix pix) {
HydrogenTextDetector htd = new HydrogenTextDetector();
HydrogenTextDetector.Parameters hydrogenParams = htd.getParameters();
hydrogenParams.debug = false;
hydrogenParams.skew_enabled = true;
htd.setParameters(hydrogenParams);
htd.setSourceImage(pix);
pix.recycle();
htd.detectText();
Pixa unsorted = htd.getTextAreas();
Pixa pixa = unsorted.sort(Constants.L_SORT_BY_X, Constants.L_SORT_DECREASING);
unsorted.recycle();
htd.clear();
return pixa;
}
Logcat detail as follow :
02-23 13:37:09.986: I/WindowManager(102): Setting rotation to 0, animFlags=1
02-23 13:37:10.006: I/ActivityManager(102): Config changed: { scale=1.0 imsi=405/30 loc=en_IN touch=3 keys=1/1/2 nav=3/1 orien=1 layout=17 uiMode=17 seq=33}
02-23 13:37:10.116: I/UsageStats(102): Unexpected resume of com.htc.launcher while already resumed in edu.sfsu.cs.orange.ocr
02-23 13:37:10.816: W/InputManagerService(102): Got RemoteException sending setActive(false) notification to pid 4880 uid 10062
I am converting Bitmap to Leptonica Pix object than Pix to Leptonica Pixa object and than doing OCR reorganization.
During processing, sometime OCR reorganization done successfully and sometime android Home screen come automatically.
I don't know what is the issue behind that, and why RemoteException warning come?
Please help me to resolve this issue.
Thanks,
You can not end the baseApi in between the AsyncTask. That is the issue you are stuck with crashing problem.
You have used following code,
pixa.recycle();
baseApi.end();
Comment the following line and than try to run the application, It may solve your problem.
pixa.recycle();
// baseApi.end();
==================================================================================
Clear the Heap Memory automatically you can implement following code :
public void onCreate(Bundle savedInstanceState) {
{
clearMemoryCountDownTimer mClearMemoryCountDownTimer = new clearMemoryCountDownTimer(5000, 5000).start();
}
private class clearMemoryCountDownTimer extends CountDownTimer {
public clearMemoryCountDownTimer(long millisInFuture,
long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
start();
Log.i(TAG, "Timer Finished");
}
@Override
public void onTick(long millisUntilFinished) {
if (Debug.getNativeHeapFreeSize() < 100000) {
clearMemory();
Log.i(TAG, "requiredClearMemory");
}
Log.i(TAG, "getNativeHeapSize : " + Debug.getNativeHeapSize());
Log.i(TAG,
"getNativeHeapFreeSize : " + Debug.getNativeHeapFreeSize());
Log.i(TAG,
"getNativeHeapAllocatedSize : "
+ Debug.getNativeHeapAllocatedSize());
}
void clearMemory() {
Log.i(TAG, "System.gc()-Start");
System.gc();
Log.i(TAG, "System.gc()-End");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With