|
| 1 | +--- |
| 2 | +title: Business Card OCR Java |
| 3 | +category: 622b805aaec68102ea7fcbc2 |
| 4 | +slug: java-business-card-ocr |
| 5 | +parentDoc: 631a062c3718850f3519b793 |
| 6 | +--- |
| 7 | +The Java 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 | +```java |
| 14 | +import com.mindee.MindeeClient; |
| 15 | +import com.mindee.input.LocalInputSource; |
| 16 | +import com.mindee.parsing.common.AsyncPredictResponse; |
| 17 | +import com.mindee.product.businesscard.BusinessCardV1; |
| 18 | +import java.io.File; |
| 19 | +import java.io.IOException; |
| 20 | + |
| 21 | +public class SimpleMindeeClient { |
| 22 | + |
| 23 | + public static void main(String[] args) throws IOException, InterruptedException { |
| 24 | + String apiKey = "my-api-key"; |
| 25 | + String filePath = "/path/to/the/file.ext"; |
| 26 | + |
| 27 | + // Init a new client |
| 28 | + MindeeClient mindeeClient = new MindeeClient(apiKey); |
| 29 | + |
| 30 | + // Load a file from disk |
| 31 | + LocalInputSource inputSource = new LocalInputSource(new File(filePath)); |
| 32 | + |
| 33 | + // Parse the file asynchronously |
| 34 | + AsyncPredictResponse<BusinessCardV1> response = mindeeClient.enqueueAndParse( |
| 35 | + BusinessCardV1.class, |
| 36 | + inputSource |
| 37 | + ); |
| 38 | + |
| 39 | + // Print a summary of the response |
| 40 | + System.out.println(response.toString()); |
| 41 | + |
| 42 | + // Print a summary of the predictions |
| 43 | +// System.out.println(response.getDocumentObj().toString()); |
| 44 | + |
| 45 | + // Print the document-level predictions |
| 46 | +// System.out.println(response.getDocumentObj().getInference().getPrediction().toString()); |
| 47 | + |
| 48 | + // Print the page-level predictions |
| 49 | +// response.getDocumentObj().getInference().getPages().forEach( |
| 50 | +// page -> System.out.println(page.toString()) |
| 51 | +// ); |
| 52 | + } |
| 53 | + |
| 54 | +} |
| 55 | + |
| 56 | +``` |
| 57 | + |
| 58 | +**Output (RST):** |
| 59 | +```rst |
| 60 | +######## |
| 61 | +Document |
| 62 | +######## |
| 63 | +:Mindee ID: 6f9a261f-7609-4687-9af0-46a45156566e |
| 64 | +:Filename: default_sample.jpg |
| 65 | +
|
| 66 | +Inference |
| 67 | +######### |
| 68 | +:Product: mindee/business_card v1.0 |
| 69 | +:Rotation applied: Yes |
| 70 | +
|
| 71 | +Prediction |
| 72 | +========== |
| 73 | +:Firstname: Andrew |
| 74 | +:Lastname: Morin |
| 75 | +:Job Title: Founder & CEO |
| 76 | +:Company: RemoteGlobal |
| 77 | +:Email: amorin@remoteglobalconsulting.com |
| 78 | +:Phone Number: +14015555555 |
| 79 | +:Mobile Number: +13015555555 |
| 80 | +:Fax Number: +14015555556 |
| 81 | +:Address: 178 Main Avenue, Providence, RI 02111 |
| 82 | +:Website: www.remoteglobalconsulting.com |
| 83 | +:Social Media: https://www.linkedin.com/in/johndoe |
| 84 | + https://twitter.com/johndoe |
| 85 | +``` |
| 86 | + |
| 87 | +# Field Types |
| 88 | +## Standard Fields |
| 89 | +These fields are generic and used in several products. |
| 90 | + |
| 91 | +### BaseField |
| 92 | +Each prediction object contains a set of fields that inherit from the generic `BaseField` class. |
| 93 | +A typical `BaseField` object will have the following attributes: |
| 94 | + |
| 95 | +* **confidence** (`Double`): the confidence score of the field prediction. |
| 96 | +* **boundingBox** (`Polygon`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. |
| 97 | +* **polygon** (`Polygon`): contains the relative vertices coordinates (`polygon` extends `List<Point>`) of a polygon containing the field in the image. |
| 98 | +* **pageId** (`Integer`): the ID of the page, always `null` when at document-level. |
| 99 | + |
| 100 | +> **Note:** A `Point` simply refers to a List of `Double`. |
| 101 | +
|
| 102 | + |
| 103 | +Aside from the previous attributes, all basic fields have access to a custom `toString` method that can be used to print their value as a string. |
| 104 | + |
| 105 | +### StringField |
| 106 | +The text field `StringField` extends `BaseField`, but also implements: |
| 107 | +* **value** (`String`): corresponds to the field value. |
| 108 | +* **rawValue** (`String`): corresponds to the raw value as it appears on the document. |
| 109 | + |
| 110 | +# Attributes |
| 111 | +The following fields are extracted for Business Card V1: |
| 112 | + |
| 113 | +## Address |
| 114 | +**address**: The address of the person. |
| 115 | + |
| 116 | +```java |
| 117 | +System.out.println(result.getDocument().getInference().getPrediction().getAddress().value); |
| 118 | +``` |
| 119 | + |
| 120 | +## Company |
| 121 | +**company**: The company the person works for. |
| 122 | + |
| 123 | +```java |
| 124 | +System.out.println(result.getDocument().getInference().getPrediction().getCompany().value); |
| 125 | +``` |
| 126 | + |
| 127 | +## Email |
| 128 | +**email**: The email address of the person. |
| 129 | + |
| 130 | +```java |
| 131 | +System.out.println(result.getDocument().getInference().getPrediction().getEmail().value); |
| 132 | +``` |
| 133 | + |
| 134 | +## Fax Number |
| 135 | +**faxNumber**: The Fax number of the person. |
| 136 | + |
| 137 | +```java |
| 138 | +System.out.println(result.getDocument().getInference().getPrediction().getFaxNumber().value); |
| 139 | +``` |
| 140 | + |
| 141 | +## Firstname |
| 142 | +**firstname**: The given name of the person. |
| 143 | + |
| 144 | +```java |
| 145 | +System.out.println(result.getDocument().getInference().getPrediction().getFirstname().value); |
| 146 | +``` |
| 147 | + |
| 148 | +## Job Title |
| 149 | +**jobTitle**: The job title of the person. |
| 150 | + |
| 151 | +```java |
| 152 | +System.out.println(result.getDocument().getInference().getPrediction().getJobTitle().value); |
| 153 | +``` |
| 154 | + |
| 155 | +## Lastname |
| 156 | +**lastname**: The lastname of the person. |
| 157 | + |
| 158 | +```java |
| 159 | +System.out.println(result.getDocument().getInference().getPrediction().getLastname().value); |
| 160 | +``` |
| 161 | + |
| 162 | +## Mobile Number |
| 163 | +**mobileNumber**: The mobile number of the person. |
| 164 | + |
| 165 | +```java |
| 166 | +System.out.println(result.getDocument().getInference().getPrediction().getMobileNumber().value); |
| 167 | +``` |
| 168 | + |
| 169 | +## Phone Number |
| 170 | +**phoneNumber**: The phone number of the person. |
| 171 | + |
| 172 | +```java |
| 173 | +System.out.println(result.getDocument().getInference().getPrediction().getPhoneNumber().value); |
| 174 | +``` |
| 175 | + |
| 176 | +## Social Media |
| 177 | +**socialMedia**: The social media profiles of the person or company. |
| 178 | + |
| 179 | +```java |
| 180 | +for (socialMediaElem : result.getDocument().getInference().getPrediction().getSocialMedia()) |
| 181 | +{ |
| 182 | + System.out.println(socialMediaElem.value); |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +## Website |
| 187 | +**website**: The website of the person or company. |
| 188 | + |
| 189 | +```java |
| 190 | +System.out.println(result.getDocument().getInference().getPrediction().getWebsite().value); |
| 191 | +``` |
| 192 | + |
| 193 | +# Questions? |
| 194 | +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) |
0 commit comments