Get Started With Scandit 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 with other modes (e.g. Barcode Capture or Text Capture) is 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.

External dependencies#

The Scandit Data Capture SDK modules depend on a few standard libraries that you can find listed below. If you are including the Scandit Data Capture SDK through Gradle or Maven, all of these dependencies are automatically pulled in and there is no need for you to do anything further. If on the other hand you are directly adding the AAR files to the project, you will have to add these dependencies yourself.

Module

Dependencies

ScanditCaptureCore.aar

  • org.jetbrains.kotlin:kotlin-stdlib:[version]

  • androidx.annotation:annotation:[version]

  • com.squareup.okhttp3:okhttp:3.12.10

ScanditBarcodeCapture.aar

  • org.jetbrains.kotlin:kotlin-stdlib:[version]

  • androidx.annotation:annotation:[version]

ScanditParser.aar

No dependencies

ScanditTextCaptureBase.aar

No dependencies

ScanditTextCapture.aar

  • org.jetbrains.kotlin:kotlin-stdlib:[version]

  • androidx.annotation:annotation:[version]

ScanditIdCapture.aar

  • org.jetbrains.kotlin:kotlin-stdlib:[version]

  • androidx.annotation:annotation:[version]

Internal dependencies#

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

Module

Dependencies

ScanditCaptureCore

No dependencies

ScanditBarcodeCapture

  • ScanditCaptureCore

ScanditParser

No dependencies

ScanditTextCaptureBase

No dependencies

ScanditTextCapture

  • ScanditCaptureCore

  • ScanditTextCaptureBase

ScanditIdCapture

  • ScanditCaptureCore

  • ScanditTextCaptureBase (MRZ or VIZ documents)

  • ScanditTextCapture (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 barcode 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.

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

Add the Camera#

You need to also create Camera:

camera = Camera.getDefaultCamera(IdCapture.createRecommendedCameraSettings());

if (camera == null) {
    throw new IllegalStateException("Failed to init camera!");
}

dataCaptureContext.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.

IdCaptureSettings settings = new IdCaptureSettings();
settings.setSupportedDocuments(
        IdDocumentType.ID_CARD_VIZ,
        IdDocumentType.DL_VIZ,
        IdDocumentType.AAMVA_BARCODE
);

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).

class MyListener implements IdCaptureListener {
    @Override
    public void onIdCaptured(
            @NotNull IdCapture mode,
            @NotNull IdCaptureSession session,
            @NotNull FrameData data
    ) {
        CapturedId capturedId = session.getNewlyCapturedId();

        // The recognized fields of the captured Id can vary based on the type.
        if (capturedId.getMrz() != null) {
            // Handle the information extracted.
        } else if (capturedId.getViz() != null) {
            // Handle the information extracted.
        } else if (capturedId.getAamvaBarcode() != null) {
            // Handle the information extracted.
        } else if (capturedId.getUsUniformedServicesBarcode() != null) {
            // Handle the information extracted.
        }
    }

    @Override
    public void onErrorEncountered(
            @NotNull IdCapture mode,
            @NotNull Throwable error,
            @NotNull IdCaptureSession session,
            @NotNull FrameData data
    ) {
      // Handle the error
    }
}

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

idCapture = IdCapture.forDataCaptureContext(dataCaptureContext, 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:

DataCaptureView dataCaptureView = DataCaptureView.newInstance(this, dataCaptureContext);
setContentView(dataCaptureView);

Then create an instance of IdCaptureOverlay attached to the view:

IdCaptureOverlay overlay = IdCaptureOverlay.newInstance(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, set the appropriate IdCaptureOverlay.idLayout.

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.DL_VIZ or IdDocumentType.ID_CARD_VIZ 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.setSupportedDocuments(IdDocumentType.ID_CARD_VIZ, IdDocumentType.DL_VIZ);
settings.setSupportedSides(SupportedSides.FRONT_AND_BACK);

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 it. 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 the back scan, 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.

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: