|
| 1 | +--- |
| 2 | +title: International ID OCR Ruby |
| 3 | +--- |
| 4 | +The Ruby OCR SDK supports the [International ID API](https://platform.mindee.com/mindee/international_id). |
| 5 | + |
| 6 | +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/international_id/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.enqueue_and_parse( |
| 21 | + input_source, |
| 22 | + Mindee::Product::InternationalId::InternationalIdV2 |
| 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 | + |
| 36 | +# Field Types |
| 37 | +## Standard Fields |
| 38 | +These fields are generic and used in several products. |
| 39 | + |
| 40 | +### Basic Field |
| 41 | +Each prediction object contains a set of fields that inherit from the generic `Field` class. |
| 42 | +A typical `Field` object will have the following attributes: |
| 43 | + |
| 44 | +* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. |
| 45 | +* **confidence** (Float, nil): the confidence score of the field prediction. |
| 46 | +* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. |
| 47 | +* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. |
| 48 | +* **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level. |
| 49 | +* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). |
| 50 | + |
| 51 | + |
| 52 | +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. |
| 53 | + |
| 54 | + |
| 55 | +### Classification Field |
| 56 | +The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **page_id**. |
| 57 | + |
| 58 | +> Note: a classification field's `value is always a `String`. |
| 59 | +
|
| 60 | +### Date Field |
| 61 | +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: |
| 62 | + |
| 63 | +* **date_object** (`Date`): an accessible representation of the value as a JavaScript object. |
| 64 | + |
| 65 | +### String Field |
| 66 | +The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`). |
| 67 | + |
| 68 | +# Attributes |
| 69 | +The following fields are extracted for International ID V2: |
| 70 | + |
| 71 | +## Address |
| 72 | +**address** ([StringField](#string-field)): The physical address of the document holder. |
| 73 | + |
| 74 | +```rb |
| 75 | +puts result.document.inference.prediction.address.value |
| 76 | +``` |
| 77 | + |
| 78 | +## Birth Date |
| 79 | +**birth_date** ([DateField](#date-field)): The date of birth of the document holder. |
| 80 | + |
| 81 | +```rb |
| 82 | +puts result.document.inference.prediction.birth_date.value |
| 83 | +``` |
| 84 | + |
| 85 | +## Birth Place |
| 86 | +**birth_place** ([StringField](#string-field)): The place of birth of the document holder. |
| 87 | + |
| 88 | +```rb |
| 89 | +puts result.document.inference.prediction.birth_place.value |
| 90 | +``` |
| 91 | + |
| 92 | +## Country of Issue |
| 93 | +**country_of_issue** ([StringField](#string-field)): The country where the document was issued. |
| 94 | + |
| 95 | +```rb |
| 96 | +puts result.document.inference.prediction.country_of_issue.value |
| 97 | +``` |
| 98 | + |
| 99 | +## Document Number |
| 100 | +**document_number** ([StringField](#string-field)): The unique identifier assigned to the document. |
| 101 | + |
| 102 | +```rb |
| 103 | +puts result.document.inference.prediction.document_number.value |
| 104 | +``` |
| 105 | + |
| 106 | +## Document Type |
| 107 | +**document_type** ([ClassificationField](#classification-field)): The type of personal identification document. |
| 108 | + |
| 109 | +```rb |
| 110 | +puts result.document.inference.prediction.document_type.value |
| 111 | +``` |
| 112 | + |
| 113 | +## Expiration Date |
| 114 | +**expiry_date** ([DateField](#date-field)): The date when the document becomes invalid. |
| 115 | + |
| 116 | +```rb |
| 117 | +puts result.document.inference.prediction.expiry_date.value |
| 118 | +``` |
| 119 | + |
| 120 | +## Given Names |
| 121 | +**given_names** (Array<[StringField](#string-field)>): The list of the document holder's given names. |
| 122 | + |
| 123 | +```rb |
| 124 | +for given_names_elem in result.document.inference.prediction.given_names do |
| 125 | + puts given_names_elem.value |
| 126 | +end |
| 127 | +``` |
| 128 | + |
| 129 | +## Issue Date |
| 130 | +**issue_date** ([DateField](#date-field)): The date when the document was issued. |
| 131 | + |
| 132 | +```rb |
| 133 | +puts result.document.inference.prediction.issue_date.value |
| 134 | +``` |
| 135 | + |
| 136 | +## MRZ Line 1 |
| 137 | +**mrz_line1** ([StringField](#string-field)): The Machine Readable Zone, first line. |
| 138 | + |
| 139 | +```rb |
| 140 | +puts result.document.inference.prediction.mrz_line1.value |
| 141 | +``` |
| 142 | + |
| 143 | +## MRZ Line 2 |
| 144 | +**mrz_line2** ([StringField](#string-field)): The Machine Readable Zone, second line. |
| 145 | + |
| 146 | +```rb |
| 147 | +puts result.document.inference.prediction.mrz_line2.value |
| 148 | +``` |
| 149 | + |
| 150 | +## MRZ Line 3 |
| 151 | +**mrz_line3** ([StringField](#string-field)): The Machine Readable Zone, third line. |
| 152 | + |
| 153 | +```rb |
| 154 | +puts result.document.inference.prediction.mrz_line3.value |
| 155 | +``` |
| 156 | + |
| 157 | +## Nationality |
| 158 | +**nationality** ([StringField](#string-field)): The country of citizenship of the document holder. |
| 159 | + |
| 160 | +```rb |
| 161 | +puts result.document.inference.prediction.nationality.value |
| 162 | +``` |
| 163 | + |
| 164 | +## Personal Number |
| 165 | +**personal_number** ([StringField](#string-field)): The unique identifier assigned to the document holder. |
| 166 | + |
| 167 | +```rb |
| 168 | +puts result.document.inference.prediction.personal_number.value |
| 169 | +``` |
| 170 | + |
| 171 | +## Sex |
| 172 | +**sex** ([StringField](#string-field)): The biological sex of the document holder. |
| 173 | + |
| 174 | +```rb |
| 175 | +puts result.document.inference.prediction.sex.value |
| 176 | +``` |
| 177 | + |
| 178 | +## State of Issue |
| 179 | +**state_of_issue** ([StringField](#string-field)): The state or territory where the document was issued. |
| 180 | + |
| 181 | +```rb |
| 182 | +puts result.document.inference.prediction.state_of_issue.value |
| 183 | +``` |
| 184 | + |
| 185 | +## Surnames |
| 186 | +**surnames** (Array<[StringField](#string-field)>): The list of the document holder's family names. |
| 187 | + |
| 188 | +```rb |
| 189 | +for surnames_elem in result.document.inference.prediction.surnames do |
| 190 | + puts surnames_elem.value |
| 191 | +end |
| 192 | +``` |
| 193 | + |
| 194 | +# Questions? |
| 195 | +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw) |
0 commit comments