Skip to main content

Classic UI for the Android Document Data Extractor Module

Overview

To integrate the Document Data Extractor using the SDK's Classic UI Components, you can take a look at our examples for live detection and auto-snapping or check the following step-by-step integration instructions.

DocumentDataExtractor can be used both in conjunction with ScanbotCameraXView (e.g., live detection for preview) and by itself for detection on a Bitmap or JPEG byte array. Let's have a look at an example with ScanbotCameraXView.

Integration

Adding the feature as a dependency

DocumentDataExtractor is included in Scanbot SDK package 3. Therefore, add the dependency io.scanbot:sdk-package-3 or higher in your build.gradle:

implementation("io.scanbot:sdk-package-3:$latestSdkVersion")
implementation("io.scanbot:sdk-documentdata-assets:$latestSdkVersion")
caution

Do not use multiple scanners (e.g., MRZ Scanner and Credit Card Scanner) at the same time.

Each scanner instance requires a lot of memory, GPU, and processor resources. Using multiple scanners will lead to performance issues for the entire application.

Initializing the SDK

The Scanbot SDK must be initialized before use. Add the following code snippet to your Application class:

Initialize SDK
loading...
caution

Unfortunately, we have noticed that all devices using a Cortex A53 processor DO NOT SUPPORT GPU acceleration. If you encounter any problems, please disable GPU acceleration for these devices.

ScanbotSDKInitializer()
.allowGpuAcceleration(false)

Adding ScanbotCameraXView to the layout

<io.scanbot.sdk.ui.camera.ScanbotCameraXView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Getting the DocumentDataExtractor instance from ScanbotSDK, setting the required document types and blurriness acceptance score, and attaching it to ScanbotCameraXView

Get DocumentDataExtractor instance and attach it to ScanbotCameraXView
loading...

Excluding fields from scanning

It is also possible to exclude certain fields from the scanning process altogether. When implemented, these excluded fields will not even be attempted to be recognized.

This can be useful for security and privacy reasons. All other fields will be scanned as usual. Fields should be set ONLY as normalized field names.

Exclude fields from being recognized
loading...

Adding a result handler for DocumentDataExtractorFrameHandler

Add a frame handler which, for example, observes consecutive successful recognition statuses and shows a toast notification whenever two or more such statuses are received.

Add a frame handler for DocumentDataExtractor
loading...

Method handle(result: FrameHandlerResult<DocumentDataExtractionResult, SdkLicenseError>) will be triggered every time DocumentDataExtractor detects a document in the camera preview frame or if a license error has occurred.

If the result of the scanning was successful, the user gets the DocumentDataExtractionResult object, which contains a cropped document image and a GenericDocument object. Each field is represented by the Field class, holding the field's type, cropped visual source, recognized text and confidence level value.

You can now run your app and should see a simple camera preview that can scan your documents.

Passing a snapped picture to DocumentDataExtractor and processing the results

First, decode the image ByteArray obtained from the camera's callback, taking into account the image orientation. Our ImageProcessor component can be used for this:

Rotate image
loading...

Next, we perform a recognition:

Extract data from the image
loading...

As an example of further application, set the obtained extraction results to a TextView:

Set the obtained extraction results to a TextView
loading...

It is also possible to use the GenericDocumentWrapper successors to use strongly typed objects and conveniently get access to the fields of the corresponding document.

As for how to receive an instance of the scanned document wrapper, take a look at our examples for live detection and auto-snapping.

Adding a finder overlay

In addition, it is recommended to add a finder overlay. This feature allows you to predefine a document area over the ScanbotCameraXView screen. By using this overlay, the Document Data Extractor skips the time-consuming step of searching for the document area and performs the recognition directly in the specified area. By using this approach, the Document Data Extractor finds and extracts the document content much faster.

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

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get free trial license