|
| 1 | +--- |
| 2 | +title: Driver License OCR Ruby |
| 3 | +category: 622b805aaec68102ea7fcbc2 |
| 4 | +slug: ruby-driver-license-ocr |
| 5 | +parentDoc: 6294d97ee723f1008d2ab28e |
| 6 | +--- |
| 7 | +The Ruby OCR SDK supports the [Driver License API](https://platform.mindee.com/mindee/driver_license). |
| 8 | + |
| 9 | +The [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg) can be used for testing purposes. |
| 10 | + |
| 11 | + |
| 12 | +# Quick-Start |
| 13 | +```rb |
| 14 | +require 'mindee' |
| 15 | + |
| 16 | +# Init a new client |
| 17 | +mindee_client = Mindee::Client.new(api_key: 'my-api-key') |
| 18 | + |
| 19 | +# Load a file from disk |
| 20 | +input_source = mindee_client.source_from_path('/path/to/the/file.ext') |
| 21 | + |
| 22 | +# Parse the file |
| 23 | +result = mindee_client.enqueue_and_parse( |
| 24 | + input_source, |
| 25 | + Mindee::Product::DriverLicense::DriverLicenseV1 |
| 26 | +) |
| 27 | + |
| 28 | +# Print a full summary of the parsed data in RST format |
| 29 | +puts result.document |
| 30 | + |
| 31 | +# Print the document-level parsed data |
| 32 | +# puts result.document.inference.prediction |
| 33 | + |
| 34 | +``` |
| 35 | +# Field Types |
| 36 | +## Standard Fields |
| 37 | +These fields are generic and used in several products. |
| 38 | + |
| 39 | +### Basic Field |
| 40 | +Each prediction object contains a set of fields that inherit from the generic `Field` class. |
| 41 | +A typical `Field` object will have the following attributes: |
| 42 | + |
| 43 | +* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. |
| 44 | +* **confidence** (Float, nil): the confidence score of the field prediction. |
| 45 | +* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. |
| 46 | +* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. |
| 47 | +* **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. |
| 48 | +* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). |
| 49 | + |
| 50 | + |
| 51 | +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. |
| 52 | + |
| 53 | +### Date Field |
| 54 | +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: |
| 55 | + |
| 56 | +* **date_object** (`Date`): an accessible representation of the value as a JavaScript object. |
| 57 | + |
| 58 | +### String Field |
| 59 | +The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`). |
| 60 | + |
| 61 | +# Attributes |
| 62 | +The following fields are extracted for Driver License V1: |
| 63 | + |
| 64 | +## Category |
| 65 | +**category** ([StringField](#string-field)): The category or class of the driver license. |
| 66 | + |
| 67 | +```rb |
| 68 | +puts result.document.inference.prediction.category.value |
| 69 | +``` |
| 70 | + |
| 71 | +## Country Code |
| 72 | +**country_code** ([StringField](#string-field)): The alpha-3 ISO 3166 code of the country where the driver license was issued. |
| 73 | + |
| 74 | +```rb |
| 75 | +puts result.document.inference.prediction.country_code.value |
| 76 | +``` |
| 77 | + |
| 78 | +## Date of Birth |
| 79 | +**date_of_birth** ([DateField](#date-field)): The date of birth of the driver license holder. |
| 80 | + |
| 81 | +```rb |
| 82 | +puts result.document.inference.prediction.date_of_birth.value |
| 83 | +``` |
| 84 | + |
| 85 | +## DD Number |
| 86 | +**dd_number** ([StringField](#string-field)): The DD number of the driver license. |
| 87 | + |
| 88 | +```rb |
| 89 | +puts result.document.inference.prediction.dd_number.value |
| 90 | +``` |
| 91 | + |
| 92 | +## Expiry Date |
| 93 | +**expiry_date** ([DateField](#date-field)): The expiry date of the driver license. |
| 94 | + |
| 95 | +```rb |
| 96 | +puts result.document.inference.prediction.expiry_date.value |
| 97 | +``` |
| 98 | + |
| 99 | +## First Name |
| 100 | +**first_name** ([StringField](#string-field)): The first name of the driver license holder. |
| 101 | + |
| 102 | +```rb |
| 103 | +puts result.document.inference.prediction.first_name.value |
| 104 | +``` |
| 105 | + |
| 106 | +## ID |
| 107 | +**id** ([StringField](#string-field)): The unique identifier of the driver license. |
| 108 | + |
| 109 | +```rb |
| 110 | +puts result.document.inference.prediction.id.value |
| 111 | +``` |
| 112 | + |
| 113 | +## Issued Date |
| 114 | +**issued_date** ([DateField](#date-field)): The date when the driver license was issued. |
| 115 | + |
| 116 | +```rb |
| 117 | +puts result.document.inference.prediction.issued_date.value |
| 118 | +``` |
| 119 | + |
| 120 | +## Issuing Authority |
| 121 | +**issuing_authority** ([StringField](#string-field)): The authority that issued the driver license. |
| 122 | + |
| 123 | +```rb |
| 124 | +puts result.document.inference.prediction.issuing_authority.value |
| 125 | +``` |
| 126 | + |
| 127 | +## Last Name |
| 128 | +**last_name** ([StringField](#string-field)): The last name of the driver license holder. |
| 129 | + |
| 130 | +```rb |
| 131 | +puts result.document.inference.prediction.last_name.value |
| 132 | +``` |
| 133 | + |
| 134 | +## MRZ |
| 135 | +**mrz** ([StringField](#string-field)): The Machine Readable Zone (MRZ) of the driver license. |
| 136 | + |
| 137 | +```rb |
| 138 | +puts result.document.inference.prediction.mrz.value |
| 139 | +``` |
| 140 | + |
| 141 | +## Place of Birth |
| 142 | +**place_of_birth** ([StringField](#string-field)): The place of birth of the driver license holder. |
| 143 | + |
| 144 | +```rb |
| 145 | +puts result.document.inference.prediction.place_of_birth.value |
| 146 | +``` |
| 147 | + |
| 148 | +## State |
| 149 | +**state** ([StringField](#string-field)): Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. |
| 150 | + |
| 151 | +```rb |
| 152 | +puts result.document.inference.prediction.state.value |
| 153 | +``` |
| 154 | + |
| 155 | +# Questions? |
| 156 | +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) |
0 commit comments