How to Implement Text Capture with User Interface
Note: Before you begin, see Build your application with the library for Android.
Below you can find description of a basic text capture scenario with user interface components.
- Before you start, add the CaptureView class to the XML layout of your Activity or Fragment with default parameters. If you are implementing a non-English app, you can override the string resources of the user interface, using the attributes' IDs (see CaptureView attributes for details).
Note: Please make sure, that you are using the Theme.AppCompat theme. Data capture scenario requires this theme for user interface implementation. - Receive the CaptureView class object from your layout inside the onCreate Activity or onViewCreated Fragment.
- Override the onResume and onPause methods, embedding the UI components methods:
- add startCamera method to the onResume method;
- add stopCamera method to the onPause method.
- Call the Engine.load method on the UI thread to create an engine object, required for all recognition mechanisms to work. This object should be reused for every new operation and should not be created again in the same application.
- Create the DataCaptureScenario object, passing the created Engine object to its constructor, to connect the user interface and recognition parts. Configure the capture scenario using the DataCaptureScenario object methods. I.e., you can enable or disable buttons visibility, localize source strings, etc.
- Configure capture process, using ImageCaptureSettings and DataCaptureSettings interface objects.
- Create the ImageCaptureSettings object and configure the capture of an image. I.e. you can set a document size and a minimum document to view ratio.
- Create the DataCaptureSettings object to configure the text capture process.
Call the setProfile method and pass a "Text" String value as a parameter to set the scenario type. The parameter is case sensitive.
You may skip this step because a text capture scenario is a default scenario type. It will be performed if no profile is set.
Tune necessary text capture settings using methods of the DataCaptureSettings object. I.e., you can set recognition languages and an area of interest. All settings are optional.
Call the checkAndApply method of the DataCaptureSettings object to checks consistence of the properties' value and apply the settings to a capture scenario. - Tune necessary scenario settings using methods of the DataCaptureScenario object. All settings are optional.
- Implement the Callback interface. Create the Callback object and set it to the scenario with the DataCaptureScenario.setCallback method. The methods of the callback will be used to get the result and monitor errors. Here are brief recommendations on what the methods should do:
- the onDataCaptured method returns the Result object, providing access to a captured image with detected document boundary on it, to the recognized data and to additional information about the data;
- the onError method is for handling processing errors.
- Use the CaptureView.setCaptureScenario method to set the capture scenario.
- The scenario will start automatically. If you want to delay the start, call the stop method. The start method of the DataCaptureScenario object will resume the scenario.
- Wait for the response or an error in the callback.
See the description of classes and methods in the User Interface API Reference section.
3/2/2022 12:59:15 PM