Deprecation warning

Please note that this is outdated documentation for an older release of the Scandit Barcode Scanner SDK.

We are deprecating the 5.x API on all platforms (except Linux). Release 5.19 in April 2021 will be our final. Applications running 5.x will continue to work, and we will continue to release critical bug fixes and security patches only, for one year. We encourage you to migrate to 6.x and take advantage of our latest / advanced features and improved performance.

You'll find the updated documentation at: Data Capture SDK Documentation for iOS

Configure OCR

Motivation

OCR enables text recognition for your mobile scanning apps. This means you can add text recognition to your organization’s mobile data capture workflows. As a result, you can seamlessly switch between reading barcodes and text with the touch of a button.

License Key

A dedicated OCR License key and SDK should be used. Please contact us (https://support.scandit.com/hc/en-us/requests/new) for more details.

Implementing OCR

To integrate the OCR into your iOS app, follow the simple steps below:

Objective-C:

#import <ScanditBarcodeScanner/SBSTextRecognition.h>
- (SBSBarcodePickerState)barcodePicker:(SBSBarcodePicker *)picker didRecognizeText:(SBSRecognizedText *)text {
// This callback is called whenever a text is read
}

Swift:

extension TextRecognitionViewController: SBSTextRecognitionDelegate {
func barcodePicker(_ picker: SBSBarcodePicker, didRecognizeText text: SBSRecognizedText) -> SBSBarcodePickerState {
// This callback is called whenever a text is read
}
}
}
  • Create a Scan Settings and Text Recognition Settings
  • Set the recognition mode to “Text”
  • Specify the format/structure of the text to be scanned: regular expression which matches your text and white list of recognizable characters.
  • Set the area in which text is to be recognised

Objective-C:

// Set the text recognition settings
SBSTextRecognitionSettings *textRecognition = [[SBSTextRecognitionSettings alloc] init];
// Set the area in which text is to be recognized.
textRecognition.areaPortrait = CGRectMake(0, 0.45, 1, 0.1);
textRecognition.areaLandscape = CGRectMake(0, 0.45, 1, 0.55)
//Set Regular Expression (i.e: VIN code)
NSError *error = NULL;
textRecognition.regex = [NSRegularExpression regularExpressionWithPattern:@"([A-Z0-9]{17})"
options:NSRegularExpressionCaseInsensitive
error:&error];
// Create the scan settings
SBSScanSettings* settings = [SBSScanSettings defaultSettings];
// Set the text recognition settings
settings.textRecognitionSettings = textRecognition;
// Set the recognize mode to recognize text
settings.recognitionMode = SBSRecognitionModeText;
  • Instantiate the barcode picker
// Instantiate the barcode picker by using the settings defined above.
SBSBarcodePicker *picker = [[SBSBarcodePicker alloc] initWithSettings:settings];

Swift:

// Set the text recognition settings
let textRecognitionSettings = SBSTextRecognitionSettings()
// Set the area in which text is to be recognized
textRecognitionSettings.areaPortrait = CGRect(x: 0, y: 0.45, width: 1, height: 0.1);
textRecognitionSettings.areaLandscape = CGRect(x: 0, y: 0.45, width: 1, height: 0.55);
//Set Regular Expression (i.e: VIN code)
textRecognitionSettings.regex = try! NSRegularExpression(pattern: "([A-Z0-9]{17}))", options: .caseInsensitive)
// Create the scan settings
let scanSettings = SBSScanSettings.default()
// Set the text recognition settings
scanSettings.textRecognitionSettings = textRecognitionSettings
// Set the recognize mode to recognize text
scanSettings.recognitionMode = .text
  • Instantiate the barcode picker
// Initialize picker
fileprivate var barcodePicker: SBSBarcodePicker?
// Instantiate the barcode picker by using the settings defined above.
let barcodePicker = SBSBarcodePicker(settings: settings)
// Set the delegate to receive recognize text event callbacks
barcodePicker.textRecognitionDelegate = self