How to Recognize Text on Photos

This guide explains how Mobile Capture SDK can be used as a common OCR solution, recognizing text on existing images.

How it Works

Mobile Capture SDK provides access to single image processing functions, enabling the generic OCR functionality. This scenario works with any image file you can load to memory. It does not require access to the camera on the device.

Implementation

 Note: Before you begin, see How to Add the Library to Your Xcode Project.

To implement the image recognition scenario, follow these steps:

  1. Create an RTREngine object using the sharedEngineWithLicenseData: method. The method requires an NSData object containing your license data. For example, you can use dataWithContentsOfFile: to create a data object, then pass this object to the sharedEngineWithLicenseData: method.
  2. Use the createCoreAPI method of the RTREngine object to create a recognizer object which conforms to the RTRCoreAPI protocol.
  3. If you want to change recognition settings, use the textRecognitionSettings property of the recognizer object (RTRCoreAPITextRecognitionSettings protocol).
    • If you are using a recognition language different from English, specify it using the setRecognitionLanguages: method. Multiple languages are also supported, although setting too many languages may decrease recognition performance.
    • It is also recommended to call the setAreaOfInterest: method to specify the rectangular area of the image where to search for text. For example, your application may provide controls that allow user to select a smaller part of image for recognition if needed. Also, best results are achieved when the area of interest does not cover the whole image but has a margin of at least half the size of a typical printed character.
  4. The processingSettings property of the recognizer object (RTRCoreAPIProcessingSettings protocol) allows you to set the number of processing threads.
  5. Recognition starts with a call to the recognizeTextOnImage:onProgress:onTextOrientationDetected:error: method. It requires you to implement the following callbacks (passed as arguments to this method):
    • A progress callback (onProgress) that receives estimated completion percentage and warnings. This callback should return a BOOL value. The return value can be used to interrupt processing: return TRUE to terminate the current operation, FALSE to continue.
    • A callback that informs you when the image orientation is detected (onTextOrientationDetected).
    • A callback to handle errors (error).

Please note, that the method is synchronous (blocking) and should not be used on UI thread.

  1. When finished, the recognizeTextOnImage:onProgress:onTextOrientationDetected:error: method will return an array of RTRTextBlock objects which contain the results of recognition for the text areas found on the image. Each RTRTextBlock is an array containing one or more text lines represented by RTRTextLine objects. Each RTRTextLine contains information about the bounding quadrangle for a single line of text and the recognized text.
    Work with the results on your side.

See the description of classes and methods in the API Reference section.

02.03.2022 12:59:15

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.