| title | FR Carte Nationale d'Identité OCR Java |
|---|---|
| category | 622b805aaec68102ea7fcbc2 |
| slug | java-fr-carte-nationale-didentite-ocr |
| parentDoc | 631a062c3718850f3519b793 |
The Java OCR SDK supports the Carte Nationale d'Identité 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.PredictResponse;
import com.mindee.product.fr.idcard.IdCardV2;
import java.io.File;
import java.io.IOException;
public class SimpleMindeeClient {
public static void main(String[] args) throws IOException {
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(filePath);
// Parse the file
PredictResponse<IdCardV2> response = mindeeClient.parse(
IdCardV2.class,
inputSource
);
// Print a summary of the response
System.out.println(response.toString());
// Print a summary of the predictions
// System.out.println(response.getDocument().toString());
// Print the document-level predictions
// System.out.println(response.getDocument().getInference().getPrediction().toString());
// Print the page-level predictions
// response.getDocument().getInference().getPages().forEach(
// page -> System.out.println(page.toString())
// );
}
}Output (RST):
########
Document
########
:Mindee ID: d33828f1-ef7e-4984-b9df-a2bfaa38a78d
:Filename: default_sample.jpg
Inference
#########
:Product: mindee/idcard_fr v2.0
:Rotation applied: Yes
Prediction
==========
:Nationality:
:Card Access Number: 175775H55790
:Document Number:
:Given Name(s): Victor
Marie
:Surname: DAMBARD
:Alternate Name:
:Date of Birth: 1994-04-24
:Place of Birth: LYON 4E ARRONDISSEM
:Gender: M
:Expiry Date: 2030-04-02
:Mrz Line 1: IDFRADAMBARD<<<<<<<<<<<<<<<<<<075025
:Mrz Line 2: 170775H557903VICTOR<<MARIE<9404246M5
:Mrz Line 3:
:Date of Issue: 2015-04-03
:Issuing Authority: SOUS-PREFECTURE DE BELLE (02)
Page Predictions
================
Page 0
------
:Document Type: OLD
:Document Sides: RECTO & VERSO
:Nationality:
:Card Access Number: 175775H55790
:Document Number:
:Given Name(s): Victor
Marie
:Surname: DAMBARD
:Alternate Name:
:Date of Birth: 1994-04-24
:Place of Birth: LYON 4E ARRONDISSEM
:Gender: M
:Expiry Date: 2030-04-02
:Mrz Line 1: IDFRADAMBARD<<<<<<<<<<<<<<<<<<075025
:Mrz Line 2: 170775H557903VICTOR<<MARIE<9404246M5
:Mrz Line 3:
:Date of Issue: 2015-04-03
:Issuing Authority: SOUS-PREFECTURE DE BELLE (02)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.
Some fields are constrained to the page level, and so will not be retrievable at document level.
The following fields are extracted for Carte Nationale d'Identité V2:
alternateName: The alternate name of the card holder.
System.out.println(result.getDocument().getInference().getPrediction().getAlternateName().value);authority: The name of the issuing authority.
System.out.println(result.getDocument().getInference().getPrediction().getAuthority().value);birthDate: The date of birth of the card holder.
System.out.println(result.getDocument().getInference().getPrediction().getBirthDate().value);birthPlace: The place of birth of the card holder.
System.out.println(result.getDocument().getInference().getPrediction().getBirthPlace().value);cardAccessNumber: The card access number (CAN).
System.out.println(result.getDocument().getInference().getPrediction().getCardAccessNumber().value);documentNumber: The document number.
System.out.println(result.getDocument().getInference().getPrediction().getDocumentNumber().value);📄documentSide: The sides of the document which are visible.
- 'RECTO'
- 'VERSO'
- 'RECTO & VERSO'
for (ClassificationField documentSideElem : result.getDocument().getInference().getPrediction().getDocumentSide())
{
System.out.println(documentSideElem)
.value;
}📄documentType: The document type or format.
- 'NEW'
- 'OLD'
for (ClassificationField documentTypeElem : result.getDocument().getInference().getPrediction().getDocumentType())
{
System.out.println(documentTypeElem)
.value;
}expiryDate: The expiry date of the identification card.
System.out.println(result.getDocument().getInference().getPrediction().getExpiryDate().value);gender: The gender of the card holder.
System.out.println(result.getDocument().getInference().getPrediction().getGender().value);givenNames: The given name(s) of the card holder.
for (givenNamesElem : result.getDocument().getInference().getPrediction().getGivenNames())
{
System.out.println(givenNamesElem.value);
}issueDate: The date of issue of the identification card.
System.out.println(result.getDocument().getInference().getPrediction().getIssueDate().value);mrz1: The Machine Readable Zone, first line.
System.out.println(result.getDocument().getInference().getPrediction().getMrz1().value);mrz2: The Machine Readable Zone, second line.
System.out.println(result.getDocument().getInference().getPrediction().getMrz2().value);mrz3: The Machine Readable Zone, third line.
System.out.println(result.getDocument().getInference().getPrediction().getMrz3().value);nationality: The nationality of the card holder.
System.out.println(result.getDocument().getInference().getPrediction().getNationality().value);surname: The surname of the card holder.
System.out.println(result.getDocument().getInference().getPrediction().getSurname().value);