Passport OCR Java

The Java client library supports the passport API for extracting data from passports.

Using this sample passport below, we are going to illustrate how to extract the data that we want using the client library.
sample passportsample passport

Quick Start

// Init a new client
Client mindeeClient = new Client("<YOUR_MINDEE_API_KEY>");

// Load a file from disk and parse it
PassportResponse passportResponse = mindeeClient.loadDocument("./4a16b1d-passport_pic.jpg").parse(ReceiptResponse.class);

// Print a summary of the parsed data
logger.info(passportResponse.documentSummary());

Output:

-----Passport data-----
Filename: passport.jpeg
Full name: HENERT PUDARSAN
Given names: HENERT
Surname: PUDARSAN
Country: GBR
ID Number: 707797979
Issuance date: 2012-04-22
Birth date: 1995-05-20
Expiry date: 2017-04-22
MRZ 1: P<GBRPUDARSAN<<HENERT<<<<<<<<<<<<<<<<<<<<<<<
MRZ 2: 7077979792GBR9505209M1704224<<<<<<<<<<<<<<00
MRZ: P<GBRPUDARSAN<<HENERT<<<<<<<<<<<<<<<<<<<<<<<7077979792GBR9505209M1704224<<<<<<<<<<<<<<00
----------------------

Extracted Fields

Depending on the field type specified, additional attributes can be extracted from the Passport object.

Using the above passport example, the following are the basic fields that can be extracted.

ID/Passport Document Information

Country

logger.info(passportResponse.getPassport().getCountry().getValue()));

Id Number

  • id_number of type Field : Passport/ID Number from the image
logger.info(passportResponse.getPassport().getId_number().getValue()));

Issuance Date

  • issuanceDate of type Date : Date of issue for the ID
LocalDate issuanceDate = passportResponse.getPassport().getIssuanceDate().getValue();

Expiry Date

  • expiryDate of type Date : Date of expiry for the ID
LocalDate exDate = passportResponse.getPassport().getExpiryDate().getValue();

Passport Owner Information

Surname

  • surname of type Field : Passport Owner's Surname
logger.info(passportResponse.getPassport().getSurname().getValue()));

Given Names

  • givenNames of type List< Field > : a list of given names of the passport owner
logger.info(passportResponse.getPassport().getGivenNames().stream()
        .map(Field::getValue)
        .collect(Collectors.joining()));

Gender

  • gender of type Field : Passport Owner's gender (M/F)
logger.info(passportResponse.getPassport().getGender().getValue()));

Full Name

  • fullName of type Field : Passport Owner's calculated Full Name from their First and Last Name
logger.info(passportResponse.getPassport().getFullName().getValue()));

Birth Place

  • birthPlace of type Field : Passport Owner's place of birth
logger.info(passportResponse.getPassport().getBirthPlace().getValue()));

Date of Birth

  • birthDate of type Date : Passport Owner's place of birth
LocalDate birthDate = passportResponse.getPassport().getBirthDate().getValue();

Machine Readable Zone

MRZ1

  • mrz1 of type Field : First line of the machine readable zone
logger.info(passportResponse.getPassport().getMrz1.getValue()));

MRZ2

  • mrz2 of type Field : Second line of the machine readable zone
logger.info(passportResponse.getPassport().getMrz2.getValue()));

MRZ

  • mrz2 of type Field : Reconstructed MRZ from MRZ1 and MRZ2
logger.info(passportResponse.getPassport().getMrz.getValue()));

 

Questions?
Slack Logo IconSlack Logo Icon  Join our Slack


Did this page help you?