Configure OCR (text recognition)

Motivation

OCR (Optical Character Recognition) 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 Android app, follow the simple steps below:

  • Specify that your class implements the TextRecognitionListener interface to handle the successful text decoding and implement the callback method.
    public class DemoActivity extends Activity implements TextRecognitionListener {
    @Override
    public int didRecognizeText(final RecognizedText text) {
    // This callback is called whenever a text is read.
    }
    }
  • Create a ScanSettings and TextRecognitionSettings
  • 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 recognized
    // Create ScanSettings
    ScanSettings settings = ScanSettings.create();
    // Set Text recognition mode to "Text"
    settings.setRecognitionMode(settings.RECOGNITION_MODE_TEXT);
    // Create TextRecognitionSettings
    TextRecognitionSettings ocrSettings = new TextRecognitionSettings();
    //Set Regular Expression (i.e: VIN code)
    ocrSettings.regex = Pattern.compile("([A-Z0-9]{17})");
    // Adjust the active scan area according to the desired scan position.
    ocrSettings.areaPortrait = new RectF(0, 0.45f, 1, 0.55f);
    ocrSettings.areaLandscape = new RectF(0, 0.45f, 1, 0.55f);
  • Instantiate the barcode picker
    // Set the text recognition settings
    settings.setTextRecognitionSettings(ocrSettings);
    // Instantiate the barcode picker by using the settings defined above.
    BarcodePicker picker = new BarcodePicker(this, settings);
    picker.setTextRecognitionListener(this);