|
| 1 | +--- |
| 2 | +title: Business Card OCR Ruby |
| 3 | +category: 622b805aaec68102ea7fcbc2 |
| 4 | +slug: ruby-business-card-ocr |
| 5 | +parentDoc: 6294d97ee723f1008d2ab28e |
| 6 | +--- |
| 7 | +The Ruby OCR SDK supports the [Business Card API](https://platform.mindee.com/mindee/business_card). |
| 8 | + |
| 9 | +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/business_card/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 | +```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::BusinessCard::BusinessCardV1 |
| 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 | + |
| 36 | +**Output (RST):** |
| 37 | +```rst |
| 38 | +######## |
| 39 | +Document |
| 40 | +######## |
| 41 | +:Mindee ID: 6f9a261f-7609-4687-9af0-46a45156566e |
| 42 | +:Filename: default_sample.jpg |
| 43 | +
|
| 44 | +Inference |
| 45 | +######### |
| 46 | +:Product: mindee/business_card v1.0 |
| 47 | +:Rotation applied: Yes |
| 48 | +
|
| 49 | +Prediction |
| 50 | +========== |
| 51 | +:Firstname: Andrew |
| 52 | +:Lastname: Morin |
| 53 | +:Job Title: Founder & CEO |
| 54 | +:Company: RemoteGlobal |
| 55 | +:Email: amorin@remoteglobalconsulting.com |
| 56 | +:Phone Number: +14015555555 |
| 57 | +:Mobile Number: +13015555555 |
| 58 | +:Fax Number: +14015555556 |
| 59 | +:Address: 178 Main Avenue, Providence, RI 02111 |
| 60 | +:Website: www.remoteglobalconsulting.com |
| 61 | +:Social Media: https://www.linkedin.com/in/johndoe |
| 62 | + https://twitter.com/johndoe |
| 63 | +``` |
| 64 | + |
| 65 | +# Field Types |
| 66 | +## Standard Fields |
| 67 | +These fields are generic and used in several products. |
| 68 | + |
| 69 | +### Basic Field |
| 70 | +Each prediction object contains a set of fields that inherit from the generic `Field` class. |
| 71 | +A typical `Field` object will have the following attributes: |
| 72 | + |
| 73 | +* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. |
| 74 | +* **confidence** (Float, nil): the confidence score of the field prediction. |
| 75 | +* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. |
| 76 | +* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. |
| 77 | +* **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. |
| 78 | +* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). |
| 79 | + |
| 80 | + |
| 81 | +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. |
| 82 | + |
| 83 | +### String Field |
| 84 | +The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`). |
| 85 | + |
| 86 | +# Attributes |
| 87 | +The following fields are extracted for Business Card V1: |
| 88 | + |
| 89 | +## Address |
| 90 | +**address** ([StringField](#string-field)): The address of the person. |
| 91 | + |
| 92 | +```rb |
| 93 | +puts result.document.inference.prediction.address.value |
| 94 | +``` |
| 95 | + |
| 96 | +## Company |
| 97 | +**company** ([StringField](#string-field)): The company the person works for. |
| 98 | + |
| 99 | +```rb |
| 100 | +puts result.document.inference.prediction.company.value |
| 101 | +``` |
| 102 | + |
| 103 | +## Email |
| 104 | +**email** ([StringField](#string-field)): The email address of the person. |
| 105 | + |
| 106 | +```rb |
| 107 | +puts result.document.inference.prediction.email.value |
| 108 | +``` |
| 109 | + |
| 110 | +## Fax Number |
| 111 | +**fax_number** ([StringField](#string-field)): The Fax number of the person. |
| 112 | + |
| 113 | +```rb |
| 114 | +puts result.document.inference.prediction.fax_number.value |
| 115 | +``` |
| 116 | + |
| 117 | +## Firstname |
| 118 | +**firstname** ([StringField](#string-field)): The given name of the person. |
| 119 | + |
| 120 | +```rb |
| 121 | +puts result.document.inference.prediction.firstname.value |
| 122 | +``` |
| 123 | + |
| 124 | +## Job Title |
| 125 | +**job_title** ([StringField](#string-field)): The job title of the person. |
| 126 | + |
| 127 | +```rb |
| 128 | +puts result.document.inference.prediction.job_title.value |
| 129 | +``` |
| 130 | + |
| 131 | +## Lastname |
| 132 | +**lastname** ([StringField](#string-field)): The lastname of the person. |
| 133 | + |
| 134 | +```rb |
| 135 | +puts result.document.inference.prediction.lastname.value |
| 136 | +``` |
| 137 | + |
| 138 | +## Mobile Number |
| 139 | +**mobile_number** ([StringField](#string-field)): The mobile number of the person. |
| 140 | + |
| 141 | +```rb |
| 142 | +puts result.document.inference.prediction.mobile_number.value |
| 143 | +``` |
| 144 | + |
| 145 | +## Phone Number |
| 146 | +**phone_number** ([StringField](#string-field)): The phone number of the person. |
| 147 | + |
| 148 | +```rb |
| 149 | +puts result.document.inference.prediction.phone_number.value |
| 150 | +``` |
| 151 | + |
| 152 | +## Social Media |
| 153 | +**social_media** (Array<[StringField](#string-field)>): The social media profiles of the person or company. |
| 154 | + |
| 155 | +```rb |
| 156 | +for social_media_elem in result.document.inference.prediction.social_media do |
| 157 | + puts social_media_elem.value |
| 158 | +end |
| 159 | +``` |
| 160 | + |
| 161 | +## Website |
| 162 | +**website** ([StringField](#string-field)): The website of the person or company. |
| 163 | + |
| 164 | +```rb |
| 165 | +puts result.document.inference.prediction.website.value |
| 166 | +``` |
| 167 | + |
| 168 | +# Questions? |
| 169 | +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) |
0 commit comments