Extract Driver's License AAMVA Barcode - Python

This tutorial shows how to perform data extraction from a PDF417 barcode that follows the AAMVA specification in a Python Console application using the LEADTOOLS SDK.

Summary This tutorial covers how to use LEADTOOLS AAMVA PDF417 SDK technology in a Python Console application.
Completion Time 30 minutes
Visual Studio Project Download tutorial project (1 KB)
Platform Python Console Application
IDE Visual Studio 2022
Runtime Target Python 3.10 or higher
Development License Download LEADTOOLS
Try it in another language

Required Knowledge

Before working on the Extract Driver's License AAMVA Barcode - Python tutorial, get familiar with the basic steps of creating a project by reviewing the Add References and Set a License and Load and Save Images tutorials. Saving the image is not necessary in this tutorial, so comment out or remove the saving code.

Create the Project and Add the LEADTOOLS References

Start with a copy of the project created in the Load and Save Images tutorial. If you do not have that project, follow the steps in that tutorial to create it.

This tutorial requires the following .net DLLs:

For a complete list of which DLLs are required for specific barcode features, refer to Barcode Support.

Set the License File

The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.

There are two types of runtime licenses:

Add the AAMVA PDF417 Extraction Code

With the project created, the references added, the license set, and the load image code added, coding can begin.

In the Solution Explorer, open Project-Name.py and place the following references below the "Add references to LEADTOOLS" comment

# Add references to LEADTOOLS 
from leadtools import LibraryLoader 
from Leadtools import * 
from Leadtools.Codecs import * 
from Leadtools.Barcode import * 
from System.IO import * 

Add a new method called extract_pdf417_data(image). Call the new method in the main() method below the load_image(r"C:\LEADTOOLS22\Resources\Images\license_sample_rear_aamva.png") call.

def main(): 
    Support.set_license(os.path.join(DemosTools.get_root(), "C:/LEADTOOLS22/Support/Common/License")) 
    image = load_image(r"C:\LEADTOOLS22\Resources\Images\license_sample_rear_aamva.png") 

The method's parameter will be the RasterImage loaded in the load_image() method. This tutorial uses this AAMVA PDF417 sample image. Add the below PDF417 AAMVA extraction code inside the new method.

def extract_pdf417_data(image): 
    engine = BarcodeEngine() 
    data = engine.Reader.ReadBarcode(image, LeadRect.Empty, BarcodeSymbology.PDF417) 
    if (data.Value != None and data.Symbology == BarcodeSymbology.PDF417): 
        id = BarcodeData.ParseAAMVAData(data.GetData(), False) 
        if (id != None): 
            print("AAMVA PDF417 Barcode Found!\n" +  
            print(f"Issuer Identification Number: {id.IssuerIdentificationNumber}\n" +  
               f"First Name: {id.FirstName.Value}\n" +  
               f"Last Name: {id.LastName.Value}\n" +  
               f"Over 21? {id.Over21}\n")  
            print("Does not meet AAMVA specifications") 
        print("PDF417 Barcode Not Found!") 


There are more properties inside the AAMVAID class, the snippet above showcases a few commonly used properties.

Run the Project

Run the project by pressing F5, or by selecting Debug -> Start Debugging.

If the steps were followed correctly, the application runs and displays the data inside the PDF417 Barcode.

Extracted PDF417 barcode data displayed to the console.


This tutorial showed how to use the BarcodeData and AAMVAID classes.

See Also

Help Version 22.0.2024.3.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.