|
| 1 | +--- |
| 2 | +title: Driver License OCR Node.js |
| 3 | +category: 622b805aaec68102ea7fcbc2 |
| 4 | +slug: nodejs-driver-license-ocr |
| 5 | +parentDoc: 609809574212d40077a040f1 |
| 6 | +--- |
| 7 | +The Node.js OCR SDK supports the [Driver License API](https://platform.mindee.com/mindee/driver_license). |
| 8 | + |
| 9 | +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. |
| 10 | + |
| 11 | + |
| 12 | +# Quick-Start |
| 13 | +```js |
| 14 | +const mindee = require("mindee"); |
| 15 | +// for TS or modules: |
| 16 | +// import * as mindee from "mindee"; |
| 17 | + |
| 18 | +// Init a new client |
| 19 | +const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); |
| 20 | + |
| 21 | +// Load a file from disk |
| 22 | +const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); |
| 23 | + |
| 24 | +// Parse the file |
| 25 | +const apiResponse = mindeeClient.enqueueAndParse( |
| 26 | + mindee.product.DriverLicenseV1, |
| 27 | + inputSource |
| 28 | +); |
| 29 | + |
| 30 | +// Handle the response Promise |
| 31 | +apiResponse.then((resp) => { |
| 32 | + // print a string summary |
| 33 | + console.log(resp.document.toString()); |
| 34 | +}); |
| 35 | +``` |
| 36 | + |
| 37 | +**Output (RST):** |
| 38 | +```rst |
| 39 | +######## |
| 40 | +Document |
| 41 | +######## |
| 42 | +:Mindee ID: fbdeae38-ada3-43ac-aa58-e01a3d47e474 |
| 43 | +:Filename: default_sample.jpg |
| 44 | +
|
| 45 | +Inference |
| 46 | +######### |
| 47 | +:Product: mindee/driver_license v1.0 |
| 48 | +:Rotation applied: Yes |
| 49 | +
|
| 50 | +Prediction |
| 51 | +========== |
| 52 | +:Country Code: USA |
| 53 | +:State: AZ |
| 54 | +:ID: D12345678 |
| 55 | +:Category: D |
| 56 | +:Last Name: Sample |
| 57 | +:First Name: Jelani |
| 58 | +:Date of Birth: 1957-02-01 |
| 59 | +:Place of Birth: |
| 60 | +:Expiry Date: 2018-02-01 |
| 61 | +:Issued Date: 2013-01-10 |
| 62 | +:Issuing Authority: |
| 63 | +:MRZ: |
| 64 | +:DD Number: DD1234567890123456 |
| 65 | +``` |
| 66 | + |
| 67 | +# Field Types |
| 68 | +## Standard Fields |
| 69 | +These fields are generic and used in several products. |
| 70 | + |
| 71 | +### Basic Field |
| 72 | +Each prediction object contains a set of fields that inherit from the generic `Field` class. |
| 73 | +A typical `Field` object will have the following attributes: |
| 74 | + |
| 75 | +* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. |
| 76 | +* **confidence** (`number`): the confidence score of the field prediction. |
| 77 | +* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. |
| 78 | +* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. |
| 79 | +* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. |
| 80 | +* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). |
| 81 | + |
| 82 | +> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). |
| 83 | +
|
| 84 | + |
| 85 | +Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. |
| 86 | + |
| 87 | +### Date Field |
| 88 | +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: |
| 89 | + |
| 90 | +* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. |
| 91 | + |
| 92 | +### String Field |
| 93 | +The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). |
| 94 | + |
| 95 | +# Attributes |
| 96 | +The following fields are extracted for Driver License V1: |
| 97 | + |
| 98 | +## Category |
| 99 | +**category** ([StringField](#string-field)): The category or class of the driver license. |
| 100 | + |
| 101 | +```js |
| 102 | +console.log(result.document.inference.prediction.category.value); |
| 103 | +``` |
| 104 | + |
| 105 | +## Country Code |
| 106 | +**countryCode** ([StringField](#string-field)): The alpha-3 ISO 3166 code of the country where the driver license was issued. |
| 107 | + |
| 108 | +```js |
| 109 | +console.log(result.document.inference.prediction.countryCode.value); |
| 110 | +``` |
| 111 | + |
| 112 | +## Date of Birth |
| 113 | +**dateOfBirth** ([DateField](#date-field)): The date of birth of the driver license holder. |
| 114 | + |
| 115 | +```js |
| 116 | +console.log(result.document.inference.prediction.dateOfBirth.value); |
| 117 | +``` |
| 118 | + |
| 119 | +## DD Number |
| 120 | +**ddNumber** ([StringField](#string-field)): The DD number of the driver license. |
| 121 | + |
| 122 | +```js |
| 123 | +console.log(result.document.inference.prediction.ddNumber.value); |
| 124 | +``` |
| 125 | + |
| 126 | +## Expiry Date |
| 127 | +**expiryDate** ([DateField](#date-field)): The expiry date of the driver license. |
| 128 | + |
| 129 | +```js |
| 130 | +console.log(result.document.inference.prediction.expiryDate.value); |
| 131 | +``` |
| 132 | + |
| 133 | +## First Name |
| 134 | +**firstName** ([StringField](#string-field)): The first name of the driver license holder. |
| 135 | + |
| 136 | +```js |
| 137 | +console.log(result.document.inference.prediction.firstName.value); |
| 138 | +``` |
| 139 | + |
| 140 | +## ID |
| 141 | +**id** ([StringField](#string-field)): The unique identifier of the driver license. |
| 142 | + |
| 143 | +```js |
| 144 | +console.log(result.document.inference.prediction.id.value); |
| 145 | +``` |
| 146 | + |
| 147 | +## Issued Date |
| 148 | +**issuedDate** ([DateField](#date-field)): The date when the driver license was issued. |
| 149 | + |
| 150 | +```js |
| 151 | +console.log(result.document.inference.prediction.issuedDate.value); |
| 152 | +``` |
| 153 | + |
| 154 | +## Issuing Authority |
| 155 | +**issuingAuthority** ([StringField](#string-field)): The authority that issued the driver license. |
| 156 | + |
| 157 | +```js |
| 158 | +console.log(result.document.inference.prediction.issuingAuthority.value); |
| 159 | +``` |
| 160 | + |
| 161 | +## Last Name |
| 162 | +**lastName** ([StringField](#string-field)): The last name of the driver license holder. |
| 163 | + |
| 164 | +```js |
| 165 | +console.log(result.document.inference.prediction.lastName.value); |
| 166 | +``` |
| 167 | + |
| 168 | +## MRZ |
| 169 | +**mrz** ([StringField](#string-field)): The Machine Readable Zone (MRZ) of the driver license. |
| 170 | + |
| 171 | +```js |
| 172 | +console.log(result.document.inference.prediction.mrz.value); |
| 173 | +``` |
| 174 | + |
| 175 | +## Place of Birth |
| 176 | +**placeOfBirth** ([StringField](#string-field)): The place of birth of the driver license holder. |
| 177 | + |
| 178 | +```js |
| 179 | +console.log(result.document.inference.prediction.placeOfBirth.value); |
| 180 | +``` |
| 181 | + |
| 182 | +## State |
| 183 | +**state** ([StringField](#string-field)): Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. |
| 184 | + |
| 185 | +```js |
| 186 | +console.log(result.document.inference.prediction.state.value); |
| 187 | +``` |
| 188 | + |
| 189 | +# Questions? |
| 190 | +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) |
0 commit comments