|
| 1 | +--- |
| 2 | +title: Business Card OCR Python |
| 3 | +category: 622b805aaec68102ea7fcbc2 |
| 4 | +slug: python-business-card-ocr |
| 5 | +parentDoc: 609808f773b0b90051d839de |
| 6 | +--- |
| 7 | +The Python 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 | +```py |
| 14 | +from mindee import Client, product, AsyncPredictResponse |
| 15 | + |
| 16 | +# Init a new client |
| 17 | +mindee_client = Client(api_key="my-api-key") |
| 18 | + |
| 19 | +# Load a file from disk |
| 20 | +input_doc = mindee_client.source_from_path("/path/to/the/file.ext") |
| 21 | + |
| 22 | +# Load a file from disk and enqueue it. |
| 23 | +result: AsyncPredictResponse = mindee_client.enqueue_and_parse( |
| 24 | + product.BusinessCardV1, |
| 25 | + input_doc, |
| 26 | +) |
| 27 | + |
| 28 | +# Print a brief summary of the parsed data |
| 29 | +print(result.document) |
| 30 | + |
| 31 | +``` |
| 32 | + |
| 33 | +**Output (RST):** |
| 34 | +```rst |
| 35 | +######## |
| 36 | +Document |
| 37 | +######## |
| 38 | +:Mindee ID: 6f9a261f-7609-4687-9af0-46a45156566e |
| 39 | +:Filename: default_sample.jpg |
| 40 | +
|
| 41 | +Inference |
| 42 | +######### |
| 43 | +:Product: mindee/business_card v1.0 |
| 44 | +:Rotation applied: Yes |
| 45 | +
|
| 46 | +Prediction |
| 47 | +========== |
| 48 | +:Firstname: Andrew |
| 49 | +:Lastname: Morin |
| 50 | +:Job Title: Founder & CEO |
| 51 | +:Company: RemoteGlobal |
| 52 | +:Email: amorin@remoteglobalconsulting.com |
| 53 | +:Phone Number: +14015555555 |
| 54 | +:Mobile Number: +13015555555 |
| 55 | +:Fax Number: +14015555556 |
| 56 | +:Address: 178 Main Avenue, Providence, RI 02111 |
| 57 | +:Website: www.remoteglobalconsulting.com |
| 58 | +:Social Media: https://www.linkedin.com/in/johndoe |
| 59 | + https://twitter.com/johndoe |
| 60 | +``` |
| 61 | + |
| 62 | +# Field Types |
| 63 | +## Standard Fields |
| 64 | +These fields are generic and used in several products. |
| 65 | + |
| 66 | +### BaseField |
| 67 | +Each prediction object contains a set of fields that inherit from the generic `BaseField` class. |
| 68 | +A typical `BaseField` object will have the following attributes: |
| 69 | + |
| 70 | +* **value** (`Union[float, str]`): corresponds to the field value. Can be `None` if no value was extracted. |
| 71 | +* **confidence** (`float`): the confidence score of the field prediction. |
| 72 | +* **bounding_box** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. |
| 73 | +* **polygon** (`List[Point]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. |
| 74 | +* **page_id** (`int`): the ID of the page, always `None` when at document-level. |
| 75 | +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). |
| 76 | + |
| 77 | +> **Note:** A `Point` simply refers to a List of two numbers (`[float, float]`). |
| 78 | +
|
| 79 | + |
| 80 | +Aside from the previous attributes, all basic fields have access to a custom `__str__` method that can be used to print their value as a string. |
| 81 | + |
| 82 | +### StringField |
| 83 | +The text field `StringField` only has one constraint: its **value** is an `Optional[str]`. |
| 84 | + |
| 85 | +# Attributes |
| 86 | +The following fields are extracted for Business Card V1: |
| 87 | + |
| 88 | +## Address |
| 89 | +**address** ([StringField](#stringfield)): The address of the person. |
| 90 | + |
| 91 | +```py |
| 92 | +print(result.document.inference.prediction.address.value) |
| 93 | +``` |
| 94 | + |
| 95 | +## Company |
| 96 | +**company** ([StringField](#stringfield)): The company the person works for. |
| 97 | + |
| 98 | +```py |
| 99 | +print(result.document.inference.prediction.company.value) |
| 100 | +``` |
| 101 | + |
| 102 | +## Email |
| 103 | +**email** ([StringField](#stringfield)): The email address of the person. |
| 104 | + |
| 105 | +```py |
| 106 | +print(result.document.inference.prediction.email.value) |
| 107 | +``` |
| 108 | + |
| 109 | +## Fax Number |
| 110 | +**fax_number** ([StringField](#stringfield)): The Fax number of the person. |
| 111 | + |
| 112 | +```py |
| 113 | +print(result.document.inference.prediction.fax_number.value) |
| 114 | +``` |
| 115 | + |
| 116 | +## Firstname |
| 117 | +**firstname** ([StringField](#stringfield)): The given name of the person. |
| 118 | + |
| 119 | +```py |
| 120 | +print(result.document.inference.prediction.firstname.value) |
| 121 | +``` |
| 122 | + |
| 123 | +## Job Title |
| 124 | +**job_title** ([StringField](#stringfield)): The job title of the person. |
| 125 | + |
| 126 | +```py |
| 127 | +print(result.document.inference.prediction.job_title.value) |
| 128 | +``` |
| 129 | + |
| 130 | +## Lastname |
| 131 | +**lastname** ([StringField](#stringfield)): The lastname of the person. |
| 132 | + |
| 133 | +```py |
| 134 | +print(result.document.inference.prediction.lastname.value) |
| 135 | +``` |
| 136 | + |
| 137 | +## Mobile Number |
| 138 | +**mobile_number** ([StringField](#stringfield)): The mobile number of the person. |
| 139 | + |
| 140 | +```py |
| 141 | +print(result.document.inference.prediction.mobile_number.value) |
| 142 | +``` |
| 143 | + |
| 144 | +## Phone Number |
| 145 | +**phone_number** ([StringField](#stringfield)): The phone number of the person. |
| 146 | + |
| 147 | +```py |
| 148 | +print(result.document.inference.prediction.phone_number.value) |
| 149 | +``` |
| 150 | + |
| 151 | +## Social Media |
| 152 | +**social_media** (List[[StringField](#stringfield)]): The social media profiles of the person or company. |
| 153 | + |
| 154 | +```py |
| 155 | +for social_media_elem in result.document.inference.prediction.social_media: |
| 156 | + print(social_media_elem.value) |
| 157 | +``` |
| 158 | + |
| 159 | +## Website |
| 160 | +**website** ([StringField](#stringfield)): The website of the person or company. |
| 161 | + |
| 162 | +```py |
| 163 | +print(result.document.inference.prediction.website.value) |
| 164 | +``` |
| 165 | + |
| 166 | +# Questions? |
| 167 | +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) |
0 commit comments