EU Driver License OCR Java

The Java OCR SDK supports the Driver License API.

Using the sample below, we are going to illustrate how to extract the data that we want using the OCR SDK.
Driver License sample

Quick-Start

import com.mindee.MindeeClient;
import com.mindee.input.LocalInputSource;
import com.mindee.parsing.common.PredictResponse;
import com.mindee.product.eu.driverlicense.DriverLicenseV1;
import java.io.File;
import java.io.IOException;

public class SimpleMindeeClient {

  public static void main(String[] args) throws IOException {
    String apiKey = "my-api-key";
    String filePath = "/path/to/the/file.ext";

    // Init a new client
    MindeeClient mindeeClient = new MindeeClient(apiKey);

    // Load a file from disk
    LocalInputSource inputSource = new LocalInputSource(filePath);

    // Parse the file
    PredictResponse<DriverLicenseV1> response = mindeeClient.parse(
        DriverLicenseV1.class,
        inputSource
    );

    // Print a summary of the response
    System.out.println(response.toString());

    // Print a summary of the predictions
//  System.out.println(response.getDocument().toString());

    // Print the document-level predictions
//    System.out.println(response.getDocument().getInference().getPrediction().toString());

    // Print the page-level predictions
//    response.getDocument().getInference().getPages().forEach(
//        page -> System.out.println(page.toString())
//    );
  }

}

Output (RST):

########
Document
########
:Mindee ID: b19cc32e-b3e6-4ff9-bdc7-619199355d54
:Filename: default_sample.jpg

Inference
#########
:Product: mindee/eu_driver_license v1.0
:Rotation applied: Yes

Prediction
==========
:Country Code: FR
:Document ID: 13AA00002
:Driver License Category: AM A1 B1 B D BE DE
:Last Name: MARTIN
:First Name: PAUL
:Date Of Birth: 1981-07-14
:Place Of Birth: Utopiacity
:Expiry Date: 2018-12-31
:Issue Date: 2013-01-01
:Issue Authority: 99999UpiaCity
:MRZ: D1FRA13AA000026181231MARTIN<<9
:Address:

Page Predictions
================

Page 0
------
:Photo: Polygon with 4 points.
:Signature: Polygon with 4 points.
:Country Code: FR
:Document ID: 13AA00002
:Driver License Category: AM A1 B1 B D BE DE
:Last Name: MARTIN
:First Name: PAUL
:Date Of Birth: 1981-07-14
:Place Of Birth: Utopiacity
:Expiry Date: 2018-12-31
:Issue Date: 2013-01-01
:Issue Authority: 99999UpiaCity
:MRZ: D1FRA13AA000026181231MARTIN<<9
:Address:

Field Types

Standard Fields

These fields are generic and used in several products.

BaseField

Each prediction object contains a set of fields that inherit from the generic BaseField class.
A typical BaseField object will have the following attributes:

  • confidence (Double): the confidence score of the field prediction.
  • boundingBox (Polygon): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
  • polygon (Polygon): contains the relative vertices coordinates (polygon extends List<Point>) of a polygon containing the field in the image.
  • pageId (Integer): the ID of the page, always null when at document-level.

Note: A Point simply refers to a List of Double.

Aside from the previous attributes, all basic fields have access to a custom toString method that can be used to print their value as a string.

StringField

The text field StringField extends BaseField, but also implements:

  • value (String): corresponds to the field value.
  • rawValue (String): corresponds to the raw value as it appears on the document.

DateField

The date field DateField extends BaseField, but also implements:

  • value (LocalDate): an accessible representation of the value as a Java object. Can be null.

PositionField

The position field PositionField implements:

  • boundingBox (Polygon): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
  • polygon (Polygon): contains the relative vertices coordinates (polygon extends List<Point>) of a polygon containing the field in the image.
  • rectangle (Polygon): a polygon with four points that may be oriented (even beyond canvas).
  • quadrangle (Polygon): a free polygon made up of four points.

Page-Level Fields

Some fields are constrained to the page level, and so will not be retrievable at document level.

Attributes

The following fields are extracted for Driver License V1:

Address

address: EU driver license holders address

System.out.println(result.getDocument().getInference().getPrediction().getAddress().value);

Driver License Category

category: EU driver license holders categories

System.out.println(result.getDocument().getInference().getPrediction().getCategory().value);

Country Code

countryCode: Country code extracted as a string.

System.out.println(result.getDocument().getInference().getPrediction().getCountryCode().value);

Date Of Birth

dateOfBirth: The date of birth of the document holder

System.out.println(result.getDocument().getInference().getPrediction().getDateOfBirth().value);

Document ID

documentId: ID number of the Document.

System.out.println(result.getDocument().getInference().getPrediction().getDocumentId().value);

Expiry Date

expiryDate: Date the document expires

System.out.println(result.getDocument().getInference().getPrediction().getExpiryDate().value);

First Name

firstName: First name(s) of the driver license holder

System.out.println(result.getDocument().getInference().getPrediction().getFirstName().value);

Issue Authority

issueAuthority: Authority that issued the document

System.out.println(result.getDocument().getInference().getPrediction().getIssueAuthority().value);

Issue Date

issueDate: Date the document was issued

System.out.println(result.getDocument().getInference().getPrediction().getIssueDate().value);

Last Name

lastName: Last name of the driver license holder.

System.out.println(result.getDocument().getInference().getPrediction().getLastName().value);

MRZ

mrz: Machine-readable license number

System.out.println(result.getDocument().getInference().getPrediction().getMrz().value);

Photo

📄photo: Has a photo of the EU driver license holder

for (PositionField photoElem : result.getDocument().getInference().getPrediction().getPhoto())
{
    System.out.println(photoElem).polygon;
}

Place Of Birth

placeOfBirth: Place where the driver license holder was born

System.out.println(result.getDocument().getInference().getPrediction().getPlaceOfBirth().value);

Signature

📄signature: Has a signature of the EU driver license holder

for (PositionField signatureElem : result.getDocument().getInference().getPrediction().getSignature())
{
    System.out.println(signatureElem).polygon;
}

Questions?

Join our Slack