|
| 1 | +--- |
| 2 | +title: EU EU Driver License OCR Ruby |
| 3 | +--- |
| 4 | +The Ruby OCR SDK supports the [EU Driver License API](https://platform.mindee.com/mindee/eu_driver_license). |
| 5 | + |
| 6 | +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/eu_driver_license/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. |
| 7 | + |
| 8 | + |
| 9 | +# Quick-Start |
| 10 | +```rb |
| 11 | +require 'mindee' |
| 12 | + |
| 13 | +# Init a new client |
| 14 | +mindee_client = Mindee::Client.new(api_key: 'my-api-key') |
| 15 | + |
| 16 | +# Load a file from disk |
| 17 | +input_source = mindee_client.source_from_path('/path/to/the/file.ext') |
| 18 | + |
| 19 | +# Parse the file |
| 20 | +result = mindee_client.parse( |
| 21 | + input_source, |
| 22 | + Mindee::Product::EU::DriverLicense::DriverLicenseV1 |
| 23 | +) |
| 24 | + |
| 25 | +# Print a full summary of the parsed data in RST format |
| 26 | +puts result.document |
| 27 | + |
| 28 | +# Print the document-level parsed data |
| 29 | +# puts result.document.inference.prediction |
| 30 | +``` |
| 31 | + |
| 32 | +**Output (RST):** |
| 33 | +```rst |
| 34 | +######## |
| 35 | +Document |
| 36 | +######## |
| 37 | +:Mindee ID: b19cc32e-b3e6-4ff9-bdc7-619199355d54 |
| 38 | +:Filename: default_sample.jpg |
| 39 | +
|
| 40 | +Inference |
| 41 | +######### |
| 42 | +:Product: mindee/eu_driver_license v1.0 |
| 43 | +:Rotation applied: Yes |
| 44 | +
|
| 45 | +Prediction |
| 46 | +========== |
| 47 | +:Country Code: FR |
| 48 | +:Document ID: 13AA00002 |
| 49 | +:Driver License Category: AM A1 B1 B D BE DE |
| 50 | +:Last Name: MARTIN |
| 51 | +:First Name: PAUL |
| 52 | +:Date Of Birth: 1981-07-14 |
| 53 | +:Place Of Birth: Utopiacity |
| 54 | +:Expiry Date: 2018-12-31 |
| 55 | +:Issue Date: 2013-01-01 |
| 56 | +:Issue Authority: 99999UpiaCity |
| 57 | +:MRZ: D1FRA13AA000026181231MARTIN<<9 |
| 58 | +:Address: |
| 59 | +
|
| 60 | +Page Predictions |
| 61 | +================ |
| 62 | +
|
| 63 | +Page 0 |
| 64 | +------ |
| 65 | +:Photo: Polygon with 4 points. |
| 66 | +:Signature: Polygon with 4 points. |
| 67 | +:Country Code: FR |
| 68 | +:Document ID: 13AA00002 |
| 69 | +:Driver License Category: AM A1 B1 B D BE DE |
| 70 | +:Last Name: MARTIN |
| 71 | +:First Name: PAUL |
| 72 | +:Date Of Birth: 1981-07-14 |
| 73 | +:Place Of Birth: Utopiacity |
| 74 | +:Expiry Date: 2018-12-31 |
| 75 | +:Issue Date: 2013-01-01 |
| 76 | +:Issue Authority: 99999UpiaCity |
| 77 | +:MRZ: D1FRA13AA000026181231MARTIN<<9 |
| 78 | +:Address: |
| 79 | +``` |
| 80 | + |
| 81 | +# Field Types |
| 82 | +## Standard Fields |
| 83 | +These fields are generic and used in several products. |
| 84 | + |
| 85 | +### Basic Field |
| 86 | +Each prediction object contains a set of fields that inherit from the generic `Field` class. |
| 87 | +A typical `Field` object will have the following attributes: |
| 88 | + |
| 89 | +* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. |
| 90 | +* **confidence** (Float, nil): the confidence score of the field prediction. |
| 91 | +* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. |
| 92 | +* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. |
| 93 | +* **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level. |
| 94 | +* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). |
| 95 | + |
| 96 | + |
| 97 | +Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string. |
| 98 | + |
| 99 | +### Date Field |
| 100 | +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: |
| 101 | + |
| 102 | +* **date_object** (`Date`): an accessible representation of the value as a JavaScript object. |
| 103 | + |
| 104 | + |
| 105 | +### Position Field |
| 106 | +The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, **polygon** and **page_id**. On top of these, it has access to: |
| 107 | + |
| 108 | +* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond canvas). |
| 109 | +* **quadrangle** (`Mindee::Geometry::Quadrilateral`): a free polygon made up of four points. |
| 110 | + |
| 111 | +### String Field |
| 112 | +The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`). |
| 113 | + |
| 114 | +## Page-Level Fields |
| 115 | +Some fields are constrained to the page level, and so will not be retrievable to through the document. |
| 116 | + |
| 117 | +# Attributes |
| 118 | +The following fields are extracted for EU Driver License V1: |
| 119 | + |
| 120 | +## Address |
| 121 | +**address** ([StringField](#string-field)): EU driver license holders address |
| 122 | + |
| 123 | +```rb |
| 124 | +puts result.document.inference.prediction.address.value |
| 125 | +``` |
| 126 | + |
| 127 | +## Driver License Category |
| 128 | +**category** ([StringField](#string-field)): EU driver license holders categories |
| 129 | + |
| 130 | +```rb |
| 131 | +puts result.document.inference.prediction.category.value |
| 132 | +``` |
| 133 | + |
| 134 | +## Country Code |
| 135 | +**country_code** ([StringField](#string-field)): Country code extracted as a string. |
| 136 | + |
| 137 | +```rb |
| 138 | +puts result.document.inference.prediction.country_code.value |
| 139 | +``` |
| 140 | + |
| 141 | +## Date Of Birth |
| 142 | +**date_of_birth** ([DateField](#date-field)): The date of birth of the document holder |
| 143 | + |
| 144 | +```rb |
| 145 | +puts result.document.inference.prediction.date_of_birth.value |
| 146 | +``` |
| 147 | + |
| 148 | +## Document ID |
| 149 | +**document_id** ([StringField](#string-field)): ID number of the Document. |
| 150 | + |
| 151 | +```rb |
| 152 | +puts result.document.inference.prediction.document_id.value |
| 153 | +``` |
| 154 | + |
| 155 | +## Expiry Date |
| 156 | +**expiry_date** ([DateField](#date-field)): Date the document expires |
| 157 | + |
| 158 | +```rb |
| 159 | +puts result.document.inference.prediction.expiry_date.value |
| 160 | +``` |
| 161 | + |
| 162 | +## First Name |
| 163 | +**first_name** ([StringField](#string-field)): First name(s) of the driver license holder |
| 164 | + |
| 165 | +```rb |
| 166 | +puts result.document.inference.prediction.first_name.value |
| 167 | +``` |
| 168 | + |
| 169 | +## Issue Authority |
| 170 | +**issue_authority** ([StringField](#string-field)): Authority that issued the document |
| 171 | + |
| 172 | +```rb |
| 173 | +puts result.document.inference.prediction.issue_authority.value |
| 174 | +``` |
| 175 | + |
| 176 | +## Issue Date |
| 177 | +**issue_date** ([DateField](#date-field)): Date the document was issued |
| 178 | + |
| 179 | +```rb |
| 180 | +puts result.document.inference.prediction.issue_date.value |
| 181 | +``` |
| 182 | + |
| 183 | +## Last Name |
| 184 | +**last_name** ([StringField](#string-field)): Last name of the driver license holder. |
| 185 | + |
| 186 | +```rb |
| 187 | +puts result.document.inference.prediction.last_name.value |
| 188 | +``` |
| 189 | + |
| 190 | +## MRZ |
| 191 | +**mrz** ([StringField](#string-field)): Machine-readable license number |
| 192 | + |
| 193 | +```rb |
| 194 | +puts result.document.inference.prediction.mrz.value |
| 195 | +``` |
| 196 | + |
| 197 | +## Photo |
| 198 | +[📄](#page-level-fields "This field is only present on individual pages.")**photo** ([PositionField](#position-field)): Has a photo of the EU driver license holder |
| 199 | + |
| 200 | +```rb |
| 201 | +for photo_elem in result.document.photo do |
| 202 | + puts photo_elem.polygon |
| 203 | +end |
| 204 | +``` |
| 205 | + |
| 206 | +## Place Of Birth |
| 207 | +**place_of_birth** ([StringField](#string-field)): Place where the driver license holder was born |
| 208 | + |
| 209 | +```rb |
| 210 | +puts result.document.inference.prediction.place_of_birth.value |
| 211 | +``` |
| 212 | + |
| 213 | +## Signature |
| 214 | +[📄](#page-level-fields "This field is only present on individual pages.")**signature** ([PositionField](#position-field)): Has a signature of the EU driver license holder |
| 215 | + |
| 216 | +```rb |
| 217 | +for signature_elem in result.document.signature do |
| 218 | + puts signature_elem.polygon |
| 219 | +end |
| 220 | +``` |
| 221 | + |
| 222 | +# Questions? |
| 223 | +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw) |
0 commit comments