Developer's Documentation for free mobile OCR SDK

Documentation Menu

How to Capture Text from Camera: Android

The purpose of Real-Time Recognition SDK for Android OCR development is to enable your application to capture information directly from the smartphone camera preview frames, without actually snapping a picture.

Important! With common licenses, your Android OCR application needs an Internet connection to gather the information about the library current state. Include the following line into your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />

If the application was not able to connect to the Internet for 90 days, the library will not be available until the connection is reinstated. To remove this limitation, please contact sales.

This section walks you through a simple text capture scenario, in which the user points the camera at the text which should be recognized.

To implement this scenario during Android OCR development, perform the following steps:

  1. Implement the Callback interface which will be used to pass the data to and from the recognition service. Here are the recommendations on what the interface‘s methods should do:
  2. 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 not created again in the same activity.
  3. 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.
  4. 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 by the call to the setRecognitionLanguage method.
  5. When the camera is ready call the start method of the ITextCaptureService interface. It requires as input parameters the size and orientation of the video frame and the rectangular area where the text is to be found (e.g. if your application displays a highlighted rectangle in the center of the image, that 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.
  6. Whenever the Callback.onRequestLatestFrame method is called, provide the current video frame from the camera by calling ITextCaptureService.submitRequestedFrame.
  7. The Callback.onFrameProcessed method will be called on the UI thread to return the result when the 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 resultStatus parameter). Use it to determine if processing should be stopped and the result displayed to the user.

    The result consists of one or more text lines represented by objects of the TextLine class. Each TextLine contains information about the enclosing quadrangle of a single line of text and the recognized text as a string.

    Work with the results on your side.
  8. When pausing or quitting the application, call the ITextCaptureService.stop method to terminate the processing threads.

See the description of classes and methods for Android OCR development further in this section.