I am working on a Android application using real-time OCR. I using OpenCV and Tesseract Library. But the performance is very poor, even on my Galaxy SIII. There are any methods to improve the performance? It is my code:
Mat mGray = new Mat();
capture.retrieve(mGray);
Bitmap bmp = Bitmap.createBitmap(mGray.cols(), mGray.rows(), Bitmap.Config.ARGB_8888);
tessBaseApi.setImage(bmp);
String recognizedText = tessBaseApi.getUTF8Text();
Log.i("Reg", recognizedText);
Will the speed of tesseract OCR be reduced by passing bitmap to the Tesseract API? What pre-processing should I perform before passing to the Tesseract API?
Use multithreading, but be aware to create one instance per thread for TessBaseAPI. Don't share them between different threads. Create N threads (N >= number of cores), and java will make sure that you speed up at least the number of cores times.
What I do is creating N threads which create TessBaseAPI objects in their own context (in the run method) and wait for OCR requests in a loop until interrupted.
You can see that the tessBaseApi object is local to the run method, hence absolutely not shared.
Some things that might make it faster are:
You can have Tesseract only do the recognition pass 1, so that it skips passes 2 through 9, when it calls recog_all_words().
Change the following line in baseapi.cpp and rebuild your Tesseract library project:
Change it to:
One thing to try is to binarize the image using adaptive thresholding (adaptiveThreshold in OpenCV).