Skip to main content

Using MRZ Scanner | Android Document Scanner

The Scanbot SDK provides the ability to find and extract Machine Readable Zone (MRZ) content from ID cards, passports and travel documents.

Depending on the type of document, the following fields can be extracted:

  • document code
  • first name
  • last name
  • issuing state or organization
  • department of issuance
  • nationality
  • date of birth
  • gender
  • date of expiry
  • personal number
  • optional fields
  • discreet issuing state or organization
  • valid check digits count
  • check digits count
  • travel document type

Try our MRZ Scanner Example Apps or check the following step by step integration instructions.

Step 1 - Add MRZ Feature as a Dependency#

MRZScanner is available with the SDK Package 2. You have to add the following dependency for it:

api "io.scanbot:sdk-package-2:$latestVersion"

MRZ Scanner can be used in conjunction with ScanbotCameraView or separately. Let's have a look at an example with ScanbotCameraView.

Step 2 - Prepare the MRZ specific OCR blob files on initialization of the SDK#

import io.scanbot.sdk.ScanbotSDKInitializer
    ...
    ScanbotSDKInitializer()        .prepareMRZBlobs(true)        ...        .initialize(this)

Step 3 - Get MRZScanner instance from ScanbotSDK and attach it to ScanbotCameraView#

val scanbotSDK = ScanbotSDK(this)val mrzScanner: MRZScanner = scanbotSDK.createMrzScanner()val mrzScannerFrameHandler: MRZScannerFrameHandler = MRZScannerFrameHandler.attach(cameraView, mrzScanner)

Step 4 - Add result handler for MRZScannerFrameHandler#

mrzScannerFrameHandler.addResultHandler { result ->    when (result) {        is FrameHandlerResult.Success -> {            if (result.value.recognitionSuccessful) {                //to do something with result here            }        }        is FrameHandlerResult.Failure -> {            //handle license error here        }    }    false}

handle(FrameHandlerResult<? extends MRZRecognitionResult, ? extends SdkLicenseError> result) will be triggered every time MRZScanner detects an MRZ area in the camera preview frame or if a license error has occurred.

When an MRZ area is detected you will get an MRZRecognitionResult object as a result which contains all extracted data fields like result.documentCode, result.firstName, etc.

You can now run your app and should see a simple camera preview that can scan MRZ data from your document.

Adding a Finder Overlay#

In addition, it is recommended to add a "Finder Overlay". This feature allows you to predefine an MRZ area over the ScanbotCameraView screen. By using this overlay the MRZ scanner can skip the time-consuming step "Search for MRZ area" and perform the recognition directly in the specified "Finder Overlay" area. By using this approach the MRZ scanner recognizes and extracts the MRZ content much faster.

Details about applying finder view logic in the layout and in the code can be found here.