| title | IND Passport - India OCR Java |
|---|---|
| category | 622b805aaec68102ea7fcbc2 |
| slug | java-ind-passport---india-ocr |
| parentDoc | 631a062c3718850f3519b793 |
The Java OCR SDK supports the Passport - India API.
Using the sample below, we are going to illustrate how to extract the data that we want using the OCR SDK.

import com.mindee.MindeeClient;
import com.mindee.input.LocalInputSource;
import com.mindee.parsing.common.AsyncPredictResponse;
import com.mindee.product.ind.indianpassport.IndianPassportV1;
import java.io.File;
import java.io.IOException;
public class SimpleMindeeClient {
public static void main(String[] args) throws IOException, InterruptedException {
String apiKey = "my-api-key";
String filePath = "/path/to/the/file.ext";
// Init a new client
MindeeClient mindeeClient = new MindeeClient(apiKey);
// Load a file from disk
LocalInputSource inputSource = new LocalInputSource(new File(filePath));
// Parse the file asynchronously
AsyncPredictResponse<IndianPassportV1> response = mindeeClient.enqueueAndParse(
IndianPassportV1.class,
inputSource
);
// Print a summary of the response
System.out.println(response.toString());
// Print a summary of the predictions
// System.out.println(response.getDocumentObj().toString());
// Print the document-level predictions
// System.out.println(response.getDocumentObj().getInference().getPrediction().toString());
// Print the page-level predictions
// response.getDocumentObj().getInference().getPages().forEach(
// page -> System.out.println(page.toString())
// );
}
}Output (RST):
########
Document
########
:Mindee ID: cf88fd43-eaa1-497a-ba29-a9569a4edaa7
:Filename: default_sample.jpg
Inference
#########
:Product: mindee/ind_passport v1.2
:Rotation applied: Yes
Prediction
==========
:Page Number: 1
:Country: IND
:ID Number: J8369854
:Given Names: JOCELYN MICHELLE
:Surname: DOE
:Birth Date: 1959-09-23
:Birth Place: GUNDUGOLANU
:Issuance Place: HYDERABAD
:Gender: F
:Issuance Date: 2011-10-11
:Expiry Date: 2021-10-10
:MRZ Line 1: P<DOE<<JOCELYNMICHELLE<<<<<<<<<<<<<<<<<<<<<
:MRZ Line 2: J8369854<4IND5909234F2110101<<<<<<<<<<<<<<<8
:Legal Guardian:
:Name of Spouse:
:Name of Mother:
:Old Passport Date of Issue:
:Old Passport Number:
:Old Passport Place of Issue:
:Address Line 1:
:Address Line 2:
:Address Line 3:
:File Number:These fields are generic and used in several products.
Each prediction object contains a set of fields that inherit from the generic BaseField class.
A typical BaseField object will have the following attributes:
- confidence (
Double): the confidence score of the field prediction. - boundingBox (
Polygon): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. - polygon (
Polygon): contains the relative vertices coordinates (polygonextendsList<Point>) of a polygon containing the field in the image. - pageId (
Integer): the ID of the page, alwaysnullwhen at document-level.
Note: A
Pointsimply refers to a List ofDouble.
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.
The classification field ClassificationField extends BaseField, but also implements:
- value (
strong): corresponds to the field value. - confidence (
double): the confidence score of the field prediction.
Note: a classification field's
value is always aString`.
The text field StringField extends BaseField, but also implements:
- value (
String): corresponds to the field value. - rawValue (
String): corresponds to the raw value as it appears on the document.
The date field DateField extends BaseField, but also implements:
- value (
LocalDate): an accessible representation of the value as a Java object. Can benull.
The following fields are extracted for Passport - India V1:
address1: The first line of the address of the passport holder.
System.out.println(result.getDocument().getInference().getPrediction().getAddress1().value);address2: The second line of the address of the passport holder.
System.out.println(result.getDocument().getInference().getPrediction().getAddress2().value);address3: The third line of the address of the passport holder.
System.out.println(result.getDocument().getInference().getPrediction().getAddress3().value);birthDate: The birth date of the passport holder, ISO format: YYYY-MM-DD.
System.out.println(result.getDocument().getInference().getPrediction().getBirthDate().value);birthPlace: The birth place of the passport holder.
System.out.println(result.getDocument().getInference().getPrediction().getBirthPlace().value);country: ISO 3166-1 alpha-3 country code (3 letters format).
System.out.println(result.getDocument().getInference().getPrediction().getCountry().value);expiryDate: The date when the passport will expire, ISO format: YYYY-MM-DD.
System.out.println(result.getDocument().getInference().getPrediction().getExpiryDate().value);fileNumber: The file number of the passport document.
System.out.println(result.getDocument().getInference().getPrediction().getFileNumber().value);gender: The gender of the passport holder.
- 'M'
- 'F'
System.out.println(result.getDocument().getInference().getPrediction().getGender().value);givenNames: The given names of the passport holder.
System.out.println(result.getDocument().getInference().getPrediction().getGivenNames().value);idNumber: The identification number of the passport document.
System.out.println(result.getDocument().getInference().getPrediction().getIdNumber().value);issuanceDate: The date when the passport was issued, ISO format: YYYY-MM-DD.
System.out.println(result.getDocument().getInference().getPrediction().getIssuanceDate().value);issuancePlace: The place where the passport was issued.
System.out.println(result.getDocument().getInference().getPrediction().getIssuancePlace().value);legalGuardian: The name of the legal guardian of the passport holder (if applicable).
System.out.println(result.getDocument().getInference().getPrediction().getLegalGuardian().value);mrz1: The first line of the machine-readable zone (MRZ) of the passport document.
System.out.println(result.getDocument().getInference().getPrediction().getMrz1().value);mrz2: The second line of the machine-readable zone (MRZ) of the passport document.
System.out.println(result.getDocument().getInference().getPrediction().getMrz2().value);nameOfMother: The name of the mother of the passport holder.
System.out.println(result.getDocument().getInference().getPrediction().getNameOfMother().value);nameOfSpouse: The name of the spouse of the passport holder (if applicable).
System.out.println(result.getDocument().getInference().getPrediction().getNameOfSpouse().value);oldPassportDateOfIssue: The date of issue of the old passport (if applicable), ISO format: YYYY-MM-DD.
System.out.println(result.getDocument().getInference().getPrediction().getOldPassportDateOfIssue().value);oldPassportNumber: The number of the old passport (if applicable).
System.out.println(result.getDocument().getInference().getPrediction().getOldPassportNumber().value);oldPassportPlaceOfIssue: The place of issue of the old passport (if applicable).
System.out.println(result.getDocument().getInference().getPrediction().getOldPassportPlaceOfIssue().value);pageNumber: The page number of the passport document.
- '1'
- '2'
System.out.println(result.getDocument().getInference().getPrediction().getPageNumber().value);surname: The surname of the passport holder.
System.out.println(result.getDocument().getInference().getPrediction().getSurname().value);