SBSDKOpticalCharacterRecognizer

@interface SBSDKOpticalCharacterRecognizer : NSObject

A class recognizing characters (text) on an image (OCR). Since this is a CPU-intensive task, the recognition methods are asynchronous and run on a dedicated concurrent queue. The completion blocks are dispatched to the main thread.

  • The configuration of the receiver. Used to configure the languages and the recognition mode.

    Declaration

    Objective-C

    @property (nonatomic, readonly) SBSDKOpticalCharacterRecognizerConfiguration *_Nonnull configuration;

    Swift

    var configuration: SBSDKOpticalCharacterRecognizerConfiguration { get }
  • Standard initializer. Initializes the optical character with its default settings: ML mode and no languages.

    Declaration

    Objective-C

    - (nonnull instancetype)init;

    Swift

    init()

    Return Value

    A new instance of the optical character recognizer.

  • Designated initializer.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithConfiguration:
        (nullable SBSDKOpticalCharacterRecognizerConfiguration *)configuration;

    Swift

    init(configuration: SBSDKOpticalCharacterRecognizerConfiguration?)

    Parameters

    configuration

    The configuration object used to configure the optical character recognizer.

    Return Value

    A new instance of the optical character recognizer.

  • Recognizes characters on the given image and passes the result, or the error, to the completion handler. The recognition runs on a dedicated concurrent queue and the completion handler is called on the main thread.

    Declaration

    Objective-C

    - (void)recognizeOnImage:(nonnull UIImage *)image
              withCompletion:(nonnull void (^)(SBSDKOCRResult *_Nullable,
                                               NSError *_Nullable))completion;

    Swift

    func recognize(on image: UIImage) async throws -> SBSDKOCRResult

    Parameters

    image

    The image to recognize text on.

    completion

    The completion handler that is called once the operation finished. Passes the recognition result or, in case of an error, the error object as parameters.

  • Recognizes characters on the image at the specified URL and passes the result, or the error, to the completion handler. The recognition runs on a dedicated concurrent queue and the completion handler is called on the main thread.

    Declaration

    Objective-C

    - (void)recognizeOnImageURL:(nonnull NSURL *)imageURL
                 withCompletion:(nonnull void (^)(SBSDKOCRResult *_Nullable,
                                                  NSError *_Nullable))completion;

    Swift

    func recognize(onImageURL imageURL: URL) async throws -> SBSDKOCRResult

    Parameters

    imageURL

    The file URL of the image to recognize text on.

    completion

    The completion handler that is called once the operation finished. Passes the recognition result or, in case of an error, the error object as parameters.

  • Recognizes characters on all images of an image storage and passes the result, or the error, to the completion handler. The recognition runs on a dedicated concurrent queue and the completion handler is called on the main thread.

    Declaration

    Objective-C

    - (nullable SBSDKProgress *)
        recognizeText:(nonnull id<SBSDKImageStoring>)storage
           completion:(nonnull void (^)(SBSDKOCRResult *_Nullable,
                                        NSError *_Nullable))completion;

    Swift

    func recognizeText(_ storage: SBSDKImageStoring, completion: @escaping (SBSDKOCRResult?, Error?) -> Void) -> SBSDKProgress?

    Parameters

    storage

    The image storage containing all the images to recognize text on.

    completion

    The completion handler that is called once the operation finished. Passes the recognition result or, in case of an error, the error object as parameters.

    Return Value

    An SBSDKProgress object that can be used to observe the progress and to cancel the operation.