Skip to main content

Using License Plate Scanner | Android Document Scanner

The Scanbot SDK provides the ability to scan car license plates and parse data fields. Scanning is currently limited to common EU license plates (country code on blue background on the left side).

As a result of scanning, the user gets the LicensePlateScanResult class instance, which contains a cropped image of the recognized license plate area and a list of data fields. Fields represent license plate country code, license plate number, raw recognized text, scanning confidence value, etc.

Try our License Plate Scanner Example or check the following step by step integration instructions.

Step 1 - Add License Plate Scanner Feature as a Dependency#

LicensePlateScanner is available with the SDK Package 4. You have to add the following dependencies for it:

api "io.scanbot:sdk-package-4:$latestSdkVersion"api "io.scanbot:sdk-licenseplate-assets:$latestSdkVersion"

It can only be used in conjunction with ScanbotCameraView for live detection with preview.

Step 2 - Add desired blobs prefetching to SDK config#

The License Plate Scanner is based on the OCR feature of Scanbot SDK. Please check the Optical Character Recognition docs for more details.

In order to use the License Plate Scanner you need to prepare the English OCR language file. Place the file eng.traineddata in the assets sub-folder assets/ocr_blobs/ of your app.

Add a call to .prepareOCRLanguagesBlobs(true) method for ScanbotSDKInitializer in your Application class.

override fun onCreate() {    super.onCreate()
    ScanbotSDKInitializer()            .license(this, licenseKey)            // TODO: other configuration calls            .prepareOCRLanguagesBlobs(true)            .initialize(this)}

Step 3 - Add ScanbotCameraView to layout#

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

Step 4 - get LicensePlateScanner instance from ScanbotSDK, and attach it to ScanbotCameraView#

val scanbotSdk = ScanbotSDK(this)val licensePlateScanner = scanbotSdk.createLicensePlateScanner()val licensePlateScannerFrameHandler = LicensePlateScannerFrameHandler.attach(cameraView, licensePlateScanner)

Step 5 - Add result handler for LicensePlateScannerFrameHandler:#

Add frame handler which observes successful recognition status and, for example, sets scanned data to a properly formatted resultTextView.

licensePlateScannerFrameHandler.addResultHandler(LicensePlateScannerFrameHandler.ResultHandler { result ->    val resultText: String = when (result) {        is FrameHandlerResult.Success -> {            if (result.value.validationSuccessful) {                result.value.rawString            } else {                "License plate not found"            }        }        is FrameHandlerResult.Failure -> "Check your setup or license"    }
    // NOTE: 'handle' method runs in background thread - don't forget to switch to main before touching any Views    runOnUiThread { resultTextView.text = resultText }
    false})