Passport OCR Node.js
The Node.js OCR SDK 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 OCR SDK.
Quick Start
const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";
// Init a new client
const mindeeClient = new mindee.Client({ apiKey: "my-api-key" });
// Load a file from disk and parse it
const doc = mindeeClient.docFromPath("/path/to/the/file.ext");
const respPromise = doc.parse(mindee.PassportV1);
// Print a summary of the parsed data
respPromise.then((resp) => {
if (resp.document === undefined) return;
console.log(resp.document.toString());
});
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
----------------------
Field Objects
Each Field
object contains at a minimum the following attributes:
value
(string or number depending on the field type):
Corresponds to the field value. Can benull
if no value was extracted.confidence
(Float):
The confidence score of the field prediction.bbox
(Array< Array< Float > >):
Contains exactly 4 relative vertices coordinates (points) of a right rectangle containing the field in the document.polygon
(Array< Array< Float > >):
Contains the relative vertices coordinates (points) of a polygon containing the field in the image.reconstructed
(Boolean):
True if the field was reconstructed or computed using other fields.
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.
- Orientation
- Birth Place
- Country
- Dates (Expiry, Issuance, Birth)
- Gender
- Given Names
- ID Number
- Machine Readable Zone
- Surname
Orientation
orientation
(Orientation): The orientation field is only available at the page level as it describes whether the page image should be rotated to be upright.
If the page requires rotation for correct display, the orientation field gives a prediction among these 3 possible outputs:
- 0 degrees: the page is already upright
- 90 degrees: the page must be rotated clockwise to be upright
- 270 degrees: the page must be rotated counterclockwise to be upright
// Show the orientation of each page
resp.pages.forEach((page) => {
console.log(page.orientation.value);
});
Birth Place
birthPlace
(Field): Passport owner birthplace.
const birthPlace = resp.document.birthPlace.value
Country
country
(Field): Passport country in ISO 3166-1 alpha-3 code format (3 letters code).
const country = resp.document.country.value
Dates
Date fields:
- contain the
date_object
attribute, which is a standard Ruby date object - can contain the
raw
attribute, which is the textual representation found on the document. - have a
value
attribute which is the ISO 8601 representation of the date, regardless of theraw
contents.
The following date fields are available:
expiry_date
: Passport expiry date.
const expiryDate = resp.document.expiryDate.value
issuance_date
: Passport date of issuance.
const issuanceDate = resp.document.issuanceDate.value
birth_date
: Passport's owner date of birth.
const birthDate = resp.document.birthDate.value
Gender
gender
(Field): Passport owner's gender (M / F).
const gender = resp.document.gender.value
Given Names
givenNames
(Array< Field >): List of passport owner's given names.
// To get the list of names
resp.document.givenNames.forEach((name) => {
console.log(name.value);
});
ID
id_number
(Field): Passport identification number.
const idNumber = resp.document.idNumber.value
Machine Readable Zone
mrz1
(Field): Passport first line of machine-readable zone.
const mrz1 = resp.document.mrz1.value
- mrz2 (Field): Passport second line of machine-readable zone.
const mrz2 = resp.document.mrz2.value
mrz
(Field): Reconstructed passport full machine-readable zone from mrz1 and mrz2.
const mrz = resp.document.mrz.value
Surname
surname
(Field): Passport's owner surname.
const surname = resp.document.surname.value
Questions?
Join our Slack
Updated 6 months ago