I am a student and a newbie in the field of Android development and must fulfill the OCR function for Android for the contact management application for my school project. This is for converting images to text from name cards.
I searched a lot of forums for information on this and found some good examples of this.
Currently, I have found open source code on the Internet that does not require the configuration of ndk and environment variables, etc. for settings. However, when I implemented it in eclipse (juno), there is a small error in which I am not sure how to solve it.
I searched Google for a long time without any results. Therefore, deciding to ask here. Below are the error codes.
final class OcrRecognizeAsyncTask extends AsyncTask<Void, Void, Boolean> {
private CaptureActivity activity;
private TessBaseAPI baseApi;
private byte[] data;
private int width;
private int height;
private OcrResult ocrResult;
private long timeRequired;
OcrRecognizeAsyncTask(CaptureActivity activity, TessBaseAPI baseApi, byte[] data, int width, int height) {
this.activity = activity;
this.baseApi = baseApi;
this.data = data;
this.width = width;
this.height = height;
}
@Override
protected Boolean doInBackground(Void... arg0) {
long start = System.currentTimeMillis();
Bitmap bitmap = activity.getCameraManager().buildLuminanceSource(data, width, height).renderCroppedGreyscaleBitmap();
String textResult;
try {
baseApi.setImage(ReadFile.readBitmap(bitmap));
textResult = baseApi.getUTF8Text();
timeRequired = System.currentTimeMillis() - start;
if (textResult == null || textResult.equals("")) {
return false;
}
ocrResult = new OcrResult();
ocrResult.setWordConfidences(baseApi.wordConfidences());
ocrResult.setMeanConfidence( baseApi.meanConfidence());
ocrResult.setRegionBoundingBoxes(baseApi.getRegions().getBoxRects());
ocrResult.setTextlineBoundingBoxes(baseApi.getTextlines().getBoxRects());
ocrResult.setWordBoundingBoxes(baseApi.getWords().getBoxRects());
ocrResult.setStripBoundingBoxes(baseApi.getStrips().getBoxRects());
final ResultIterator iterator = baseApi.getResultIterator();
int[] lastBoundingBox;
ArrayList<Rect> charBoxes = new ArrayList<Rect>();
iterator.begin();
do {
lastBoundingBox =iterator.getBoundingBox(PageIteratorLevel.RIL_SYMBOL);
Rect lastRectBox = new Rect(lastBoundingBox[0], lastBoundingBox[1],
lastBoundingBox[2], lastBoundingBox[3]);
charBoxes.add(lastRectBox);
} while (iterator.next(PageIteratorLevel.RIL_SYMBOL));
iterator.delete();
ocrResult.setCharacterBoundingBoxes(charBoxes);
} 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) {
}
return false;
}
timeRequired = System.currentTimeMillis() - start;
ocrResult.setBitmap(bitmap);
ocrResult.setText(textResult);
ocrResult.setRecognitionTimeRequired(timeRequired);
return true;
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
Handler handler = activity.getHandler();
if (handler != null) {
if (result) {
Message message = Message.obtain(handler, R.id.ocr_decode_succeeded, ocrResult);
message.sendToTarget();
} else {
Message message = Message.obtain(handler, R.id.ocr_decode_failed, ocrResult);
message.sendToTarget();
}
activity.getProgressDialog().dismiss();
}
if (baseApi != null) {
baseApi.clear();
}
}
}
The error is in the do and while loop:
do {
lastBoundingBox = iterator.***getBoundingBox***(PageIteratorLevel.RIL_SYMBOL);
Rect lastRectBox = new Rect(lastBoundingBox[0], lastBoundingBox[1],
lastBoundingBox[2], lastBoundingBox[3]);
charBoxes.add(lastRectBox);
} while (iterator.next(PageIteratorLevel.RIL_SYMBOL));
iterator.***delete***();
ocrResult.setCharacterBoundingBoxes(charBoxes);
, ,
getBoundingBox delete :
" getBoundingBox (int) - undefined ResultIterator"
" getBoundingBox (int) - undefined ResultIterator"
, .
- , , , .