How to Recognize US Driver’s License on Android Mobile Apps

According to the American Association of Motor Vehicle Administrators (AAMVA) specification, PDF417 symbology is used for storing personal information on US driver’s license. In this article, I will use Google mobile vision APIs to recognize a driver’s license. Besides, I will create a similar Android barcode reader app to extract information from PDF417 symbology by Dynamsoft Barcode Reader SDK.

Driver’s License Recognition on Android

Here is a forged driver’s license used for testing.

Google Barcode Detection

Mobile Vision APIs are capable of detecting some mainstream barcode symbologies. There is a DriverLicense class that defines common fields existing on all barcode standards.

To quickly verify Google’s API, I downloaded the sample code of Android Vision.

Create a file for displaying the information of a driver’s license:

Find the onBarcodeDetected(Barcode barcode) function in, and then add the following code to start the ResultActivity class when a barcode format is detected as PDF417:

Configure the activity in AndroidManifest.xml:

<activity android:name=".ResultActivity" />

Build and launch the app.

Dynamsoft Barcode Detection

Create an Android camera project using fotoapparat:

implementation 'io.fotoapparat.fotoapparat:library:2.3.1'

Get camera frames in the callback function process(Frame frame):

Decode barcodes from the frame by calling decodeBuffer() function. The image data format is NV21:

Frame frame = (Frame) msg.obj;PointResult pointResult = new PointResult();pointResult.textResults = reader.decodeBuffer(frame.getImage(), frame.getSize().width, frame.getSize().height, frame.getSize().width, EnumImagePixelFormat.IPF_NV21, "");

Dynamsoft Barcode Reader SDK does not provide a driver’s license class yet. We can create a custom class by referring to the AAMVA standard and Google’s Mobile Vision.

Create a class named DriverLicense:

Create a DBRDriverLicenseUtil class to define the common AAMVA fields:

public static final String CITY = "DAI";public static final String STATE = "DAJ";public static final String STREET = "DAG";public static final String ZIP = "DAK";public static final String BIRTH_DATE = "DBB";public static final String EXPIRY_DATE = "DBA";public static final String FIRST_NAME = "DAC";public static final String GENDER = "DBC";public static final String ISSUE_DATE = "DBD";public static final String ISSUING_COUNTRY = "DCG";public static final String LAST_NAME = "DCS";public static final String LICENSE_NUMBER = "DAQ";public static final String MIDDLE_NAME = "DAD";

Check whether the string recognized from PDF417 complying with the AAMVA standard:

Fetch the driver’s license information and save data to a HashMap:

Create an instance of DriverLicense class and send it to ResultActivity :

HashMap<String, String> resultMaps = DBRDriverLicenseUtil.readUSDriverLicense(result.barcodeText);Intent intent = new Intent(MainActivity.this, ResultActivity.class);DriverLicense driverLicense = new DriverLicense();driverLicense.documentType = "DL";driverLicense.firstName = resultMaps.get(DBRDriverLicenseUtil.FIRST_NAME);driverLicense.middleName = resultMaps.get(DBRDriverLicenseUtil.MIDDLE_NAME);driverLicense.lastName = resultMaps.get(DBRDriverLicenseUtil.LAST_NAME);driverLicense.gender = resultMaps.get(DBRDriverLicenseUtil.GENDER);driverLicense.addressStreet = resultMaps.get(DBRDriverLicenseUtil.STREET);driverLicense.addressCity = resultMaps.get(DBRDriverLicenseUtil.CITY);driverLicense.addressState = resultMaps.get(DBRDriverLicenseUtil.STATE);driverLicense.addressZip = resultMaps.get(DBRDriverLicenseUtil.ZIP);driverLicense.licenseNumber = resultMaps.get(DBRDriverLicenseUtil.LICENSE_NUMBER);driverLicense.issueDate = resultMaps.get(DBRDriverLicenseUtil.ISSUE_DATE);driverLicense.expiryDate = resultMaps.get(DBRDriverLicenseUtil.EXPIRY_DATE);driverLicense.birthDate = resultMaps.get(DBRDriverLicenseUtil.BIRTH_DATE);driverLicense.issuingCountry = resultMaps.get(DBRDriverLicenseUtil.ISSUING_COUNTRY);intent.putExtra("DriverLicense", driverLicense);startActivity(intent);

After launching the app, I could get the same results as Google’s.

One More Thing: Google vs. Dynamsoft

Since I have implemented two Android barcode reader apps, why not make a comparison?

The left one is based on Google Mobile Vision SDK and the right one is based on Dynamsoft Barcode Reader SDK.

Source Code

Originally published at on June 1, 2020.

Manager of Dynamsoft Open Source Projects | Tech Lover