Get Started With ID Capture

Quick overview

ID Capture provides the capability to scan personal identification documents, such as identity cards, passports or visas. In this guide you will learn step by step how to add ID Capture to your application. Roughly, the steps are:

Note

Using ID Capture at the same time as other modes (e.g. Barcode Capture or Text Capture) is currently not supported.

Prerequisites

Before starting with adding a capture mode, make sure that you have a valid Scandit Data Capture SDK license key and that you added the necessary dependencies. If you have not done that yet, check out this guide.

Note

You can retrieve your Scandit Data Capture SDK license key, by signing in to your account at ssl.scandit.com.

Initialize the id plugin

Warning

Without initializing the id plugin, runtime crashes will occur. However, you don’t have to initialize the core plugin, as initializing the id plugin already does that for you, as presented in the snippet below.

Before accessing anything of the Scandit Data Capture SDK functionality. You have to initialize the id plugin.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await ScanditFlutterDataCaptureId.initialize();
  runApp(MyApp());
}

Internal dependencies

Some of the Scandit Data Capture SDK modules depend on others to work:

Module

Dependencies

ScanditCaptureCore

No dependencies

ScanditBarcodeCapture

  • ScanditCaptureCore

ScanditParser

  • ScanditCaptureCore

ScanditTextCapture

  • ScanditCaptureCore

ScanditIdCapture

  • ScanditCaptureCore

  • native iOS and Android libraries: ScanditOCR and ScanditTextCaptureBase (VIZ documents)

  • native iOS and Android libraries: ScanditTextCapture (MRZ and VIZ documents)

When adding ScanditIdCapture to a Flutter project, certain native dependencies need to be added manually to your project, depending on the documents you want to scan.

If you’re only scanning barcode based documents, you only need to add the ScanditIdCapture Flutter plugin.

If you’re also scanning VIZ documents, you also need to add the ScanditOCR and ScanditTextCaptureBase native dependencies, as described in our iOS and Android documentation.

If you’re also scanning MRZ documents, you also need the native ScanditTextCapture dependency. You can add this as well as described in our iOS and Android documentation.

Alternatively, if you’re scanning both VIZ and MRZ documents, you can add the ScanditTextCapture Flutter (scandit-datacapture-flutter-text) plugin, which includes the native dependencies for both VIZ and MRZ documents.

Please note that your license may support only a subset of ID Capture features. If you would like to use additional features please contact us at support@scandit.com.

Create the Data Capture Context

The first step to add capture capabilities to your application is to create a new data capture context. The context expects a valid Scandit Data Capture SDK license key during construction.

var context = DataCaptureContext.forLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --");

Add the Camera

You need to also create the Camera:

Camera? camera = Camera.defaultCamera;

if (camera != null) {
  // Use the settings recommended by id capture.
  camera.applySettings(IdCapture.recommendedCameraSettings);
  context.setFrameSource(camera);
}

Create ID Capture Settings

Use IdCaptureSettings to configure the types of documents that you’d like to scan. Check IdDocumentType for all the available options.

var settings = IdCaptureSettings();
settings.supportedDocuments.addAll(
    [IdDocumentType.idCardViz, IdDocumentType.dlViz, IdDocumentType.aamvaBarcode]);

Implement the Listener

To receive scan results, implement IdCaptureListener. A result is delivered as CapturedId. This class contains data common for all kinds of personal identification documents. For more specific information use its non-null result properties (for example CapturedId.aamvaBarcode).

@override
void didCaptureId(IdCapture idCapture, IdCaptureSession session) {
    CapturedId? capturedId = session.newlyCapturedId;
    // Do something in case the capturedId is not null.
}

Create a new ID Capture mode with the chosen settings. Then register the listener:

idCapture = IdCapture.forContext(context, settings);
idCapture.addListener(this)

Use a Capture View to Visualize the Scan Process

When using the built-in camera as frame source, you will typically want to display the camera preview on the screen together with UI elements that guide the user through the capturing process. To do that, add a DataCaptureView to your view hierarchy:

var dataCaptureView = DataCaptureView.forContext(dataCaptureContext);
// Add the dataCaptureView to your widget tree

Then create an instance of IdCaptureOverlay attached to the view:

overlay =  IdCaptureOverlay.withIdCaptureForView(idCapture, dataCaptureView);

The overlay chooses the displayed UI automatically, based on the selected IdCaptureSettings. If you prefer to show a different UI or to temporarily hide it, use IdCaptureOverlay.setIdLayout().

Turn on the Camera

Finally, turn on the camera to start scanning:

camera.switchToDesiredState(FrameSourceState.on);

And this is it. You can now scan documents.

Capture both the front and the back side of documents

By default, when IdDocumentType.dlViz or IdDocumentType.idCardViz are selected, Id Capture scans only the front side of documents. Sometimes however, you may be interested in extracting combined information from both the front and the back side.

Warning

Capturing combined information from both sides of documents is possible only for their parts intended to be read by humans (for example Visual Inspection Zone (VIZ) of a Machine-Readable Travel Document (MRTD)). It is currently not possible to obtain a single result that would additionally contain the information parsed from Machine-Readable Zones (MRZ) or barcodes, such as PDF417.

First, enable scanning of both sides of documents in IdCaptureSettings:

settings.supportedDocuments.addAll([IdDocumentType.idCardViz, IdDocumentType.dlViz]);
settings.supportedSides = SupportedSides.frontAndBack;

Start by scanning the front side of a document. After you receive the result in IdCaptureListener, inspect VizResult.isBackSideCaptureSupported. If scanning of the back side of your document is supported, flip the document and capture the back side as well. The next result that you receive is a combined result that contains the information from both sides. You may verify this by checking VizResult.capturedSides. After both sides of the document are scanned, you may proceed with another document.

Sometimes, you may not be interested in scanning the back side of a document, after you completed the front scan. For example, your user may decide to cancel the process. Internally, Id Capture maintains the state of the scan, that helps it to provide better combined results. To abandon capturing the back of a document, reset this state by calling:

idCapture.reset();

Otherwise, Id Capture may assume that the front side of a new document is actually the back side of an old one, and provide you with nonsensical results.

Detect Tampered or Fake Documents

Id Capture helps to detect tampered or fake documents. This feature is currently limited to documents that follow the Driver License/Identification specification by American Association of Motor Vehicle Administrators (AAMVA).

Use AamvaVizBarcodeComparisonVerifier to perform basic, on-device document verification by comparing the human-readable data from the front side with the data encoded in the barcode.

This verifier may permit minor data divergence to compensate, for example, for a single character misread by OCR. While this verifier automatically detects many fraudulent documents, a failed check does not necessarily mean that the document is invalid. It is up to the user to subject such documents to additional scrutiny.

The verification is performed in the front & back scanning mode. Create the verifier and initialize IdCapture with the following settings:

DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey('-- ENTER YOUR SCANDIT LICENSE KEY HERE --');

AamvaVizBarcodeComparisonVerifier verifier = AamvaVizBarcodeComparisonVerifier.create()

IdCaptureSettings settings = new IdCaptureSettings()
settings.supportedDocuments = [IdDocumentType.dlViz]
settings.supportedSides = SupportedSides.FrontAndBack

IdCapture idCapture = IdCapture.forContext(dataCaptureContext, settings)

Then proceed to capture the front side & the back side of a document as usual. After you capture the back side and receive the combined result for both sides, you may run the verifier as follows:

@override
void didCaptureId(IdCapture idCapture, IdCaptureSession session) {
    if (session.newlyCapturedId == null) {
      return;
    }
    idCapture.isEnabled = false;

    CapturedId capturedId = session.newlyCapturedId!;
    var vizResult = capturedId.viz;

    if (vizResult != null && vizResult.capturedSides == SupportedSides.frontAndBack) {
      AamvaVizBarcodeComparisonVerifier verifier = AamvaVizBarcodeComparisonVerifier.create();
      verifier.verify(capturedId).then((result) => {
            if (result.checksPassed)
            {
                // Nothing suspicious was detected.
            }
            else
            {
                //  You may inspect the results of individual checks, if you wish:
                if (result.datesOfBirthMatch.checkResult == ComparisonCheckResult.failed)
                {
                    // The holder's date of birth from the front side does not match the one encoded in the barcode.
                }
            }
          });
    }
}

The returned value allows you to query both the overall result of the verification and the results of individual checks. See AamvaVizBarcodeComparisonResult for details.

Supported documents

You can find the list of supported documents here.

What’s next?

To dive further into the Scandit Data Capture SDK we recommend the following articles: