Search code examples
androidtesseracttess-two

Tesseract getutf8text performance


I have been working with an app that uses the Tesseract API in order to support OCR. This is done by using a Surfaceview which shows the camera output (Camera2 API) and a ImageReader instance which is used to get the images from the camera. The camera is setup to be of the type setRepeatingRequest so new images are available very frequent. When I make a call to the getutf8text() method to get the readable text in images it makes the preview of the camera which is showed on the Surfaceview lag. Are there any settings in the Tesseract API which can be set so it speeds up the getutf8text() method call or anything else I can do in order to get the preview Surfaceview to not lag?

Any help or guidance is appreciated!


Solution

  • Most of the things that you can do to speed up performance occur separately from the Tesseract API itself:

    1. Run the OCR on a separate, non-UI thread
    2. Grab a new image to start OCR on after OCR has finished on the last image. Try capture instead of setRepeatingRequest.
    3. Downsample the image before OCR, so that it's smaller
    4. Experiment with different Tesseract page segmentation modes to see what's the fastest on your data
    5. Re-train the Tesseract trained data file to use fewer characters and a smaller dictionary, depending on what your app is used for
    6. Modify Tesseract to perform only recognition pass #1
    7. Don't forget to consider OpenCV or other approaches altogether

    You didn't say what Tesseract API settings you're using now, and you didn't describe what your app does in a general sense, so it's hard to tell you where to start, but these points should get you started.