How to Implement Text Capture Processing
Note: Before you begin, see How to Add the Library to Your Android Studio Project.
To implement the real-time text capture scenario during Android OCR development, follow these steps:
- Begin with the Callback interface implementation. Its methods will be used to pass the data to and from the recognition service. Here are the brief recommendations on what the methods should do:
- The onRequestLatestFrame method should retrieve the image from the camera and pass it on to the ITextCaptureService.submitRequestedFrame method.
- The onFrameProcessed method is where you work with the results, display them to the user, etc.
- The onError method is for handling processing errors.
- Call the Engine.load method on the UI thread to create an engine object via which all other objects may be created. This object should be reused for every new operation and should not be created again in the same activity.
- Use the createTextCaptureService method of the Engine object to create a background recognition service (implementing the ITextCaptureService interface) on the UI thread. Only one instance of the service per application is necessary: multiple threads will be started internally.
- Set up the processing parameters, according to the kind of text you expect to capture.
The default text language is English; if you need other languages, specify them using the setRecognitionLanguage method. - When the camera is ready, call the start method of the ITextCaptureService interface. Required input parameters are the size and orientation of the video frame and the rectangular area of interest (e.g. if your application displays a highlighted rectangle in the center of the image, this rectangle should be specified as the "area of interest").
The service will then start up several working threads and continue interacting with your application via the Callback interface. - Whenever the Callback.onRequestLatestFrame method is called, request for the current video frame from the camera and provide it to the service by callling ITextCaptureService.submitRequestedFrame.
- The Callback.onFrameProcessed method is called on the UI thread to return the result when a frame is recognized.
It also reports the result stability status, which indicates if the result is available and if it is likely to be improved by adding further frames (see the resultStatus parameter). Use it to determine whether the application should stop processing and display the result to the user. We do not recommend using the result until the stability level has reached at least Available.
The result consists of one or more text lines represented by objects of the TextLine class. Each TextLine contains information about the bounding quadrangle for a single line of text and the recognized text as a string.
Work with the results on your side. - When the appropriate result was get, as well as on pausing or quitting the application, call the ITextCaptureService.stop method to terminate the processing threads.
See the description of classes and methods in the API Reference section.
3/2/2022 12:59:15 PM