Detect and scan MRZ
You can use this feature to detect and scan a Machine Readable Zone (MRZ). All official ID cards and Passports complying with ICAO 9303 standard contain this section from which it is possible to retrieve most of personal data without the need to indicate the particular ID type or issuing state beforehand. By using this method, we will be able to scan and get information from worldwide documents.
This option is included on the SDK so no extra configuration is required apart from the basic MobbScan configuration.
MRZ detection and scan
This mode will detect the MRZ of a document, validate it to confirm it is a valid MRZ, extract the information of the MRZ and return the image of the document. Follow the next steps in order to correctly perform the process.
Note: To start the MRZ detection and scan, you should have done the
startScan
method to get thescanId
previously. If you don't know how to do this, please visit the getting started guide. Keep in mind that the document type you have to use now is aIDDocumentMRZ
.
1. Create the ScanOperation method
In order to scan information based on the MRZ of the document you will have to create a ScanOperation
instance. This class has a builder with all the information required for the scan that is going to be performed.
val validations: arrayListOf(ResultIDCard.FIELD_VALIDATION_MRZ_MANDATORY_DATA_VALIDATION)
val scanOperation = ScanOperationMRZ.Builder()
.scanId(YOUR_SCAN_ID)
.timeout(TIMEOUT)
.scanMrzMode(ScanOperationMRZ.SCAN_MRZ_MODE.FORCE_CROPPED_DOCUMENT)
.listValidation(validations)
.build()
List<String> validations = new ArrayList<>();
validations.add(ResultIDCard.FIELD_VALIDATION_MRZ_MANDATORY_DATA_VALIDATION);
ScanOperation scanOperation = new ScanOperationMRZ.Builder()
.scanId(YOUR_SCAN_ID)
.timeout(TIMEOUT)
.scanMrzMode(ScanOperationMRZ.SCAN_MRZ_MODE.FORCE_CROPPED_DOCUMENT)
.listValidation(validations)
.build();
This object if composed by the following attributes:
Attribute | Description |
---|---|
ScanID | Scan identifier obtained from the start scan method. |
Timeout | After the detection and validation of the MRZ of the document, the process will obtain the image of the document. There is a chance that the system might not be able to validate the MRZ of the document. Tf this is the case, you can set a timeout to stop trying to validate the MRZ and return the document image without the validation of the MRZ. |
ScanMRZMode | After the validation has been completed or the timeout has been reached, an image of the document will be returned. This mode sets the way the document is returned. Check the differences here. |
ListValidations | List of validations to perform over the MRZ of the document to consider it a valid MRZ. You can check the possibilites here. |
2. Make the MobbScanAPI call with the ScanOperation
Once we have the ScanOperation instance that will configure the process, we can perform the MobbScanAPI call as follows:
MobbScanAPI.getInstance().scan(scanOperation, { result, resultData, error ->
// Your document detection listener code here
}) { result, resultData, error ->
// Your document scan listener code here
}
MobbScanAPI.getInstance().scan(scanOperation, new IDDocumentDetectionListener() {
@Override
public void onIDDocumentDetected(MobbScanDetectionResult result, MobbScanDetectionResultData resultData, MobbScanAPIError error) {
// Your document detection listener code here
}
}, new IDDocumentScanListener() {
@Override
public void onIDDocumentScanned(MobbScanScanResult result, MobbScanScanResultData resultData, MobbScanAPIError error) {
// Yous document scan listener code here
}
});
Note: If you want extra information about the listeners used in this method, you can take a look to the ones used on the default document scan, as they are the same ones.
Document detection with MRZ validation
If in your use case you only want to detect the document and you do not want to perform a scan, this option will return an image of the document with the MRZ validation performed.
1. Create the ScanOperation method
As seen at MRZ detection and scan you have to create the ScanOperation method to configure the process. Please check the previous create the ScanOperation method.
2. Make the MobbScanAPI call with the ScanOperation
In this case, the method you have to use is the one that follows:
MobbScanAPI.getInstance().scan(scanOperation, { result, resultData, error ->
// Your document detection listener code here
})
MobbScanAPI.getInstance().scan(scanOperation, new IDDocumentDetectionListener() {
@Override
public void onIDDocumentDetected(MobbScanDetectionResult result, MobbScanDetectionResultData resultData, MobbScanAPIError error) {
// Your document detection listener code here
}
});
Note: If you want extra information about the listeners used in this method, you can take a look at the ones used on the default document scan, since they are the same ones.
Scan MRZ Modes
This mode will configure how the image of the document will be returned. The options are:
Scan mrz mode | description |
---|---|
SCAN_MRZ_MODE.DEFAULT | The document in not cropped in any way, it will return the whole camera frame. |
SCAN_MRZ_MODE.WITH_CROPPED_DOCUMENT | MobbScan will try to crop the document from the frame where the MRZ was detected. If the action was not successful, it will return the whole camera frame. |
SCAN_MRZ_MODE.FORCE_CROPPED_DOCUMENT | MobbScan will force the document detection. This will always return a cropped document. |
MRZ validations
It is possible to setup customized conditions for the MRZ scan depending on the kind of data required. By default, these are the fields that must be validated before stopping the MRZ scanning process and notify this situation back:
Note: the MRZ detection process will always check that both name and surname are not null.
Here is the list (listValidations
) with all required fields that the scanning process will validate before returning a succesful result. By default, the name and the surname will always be checked and validated as non null values. All these validations are accesible from the ScanOperationMRZ class.
The optional validations are the following ones:
validation | description |
---|---|
VALIDATION_MRZ_CHECK_DATE_OF_BIRTH | Checks that the date of birth is correct according to the checkdigit |
VALIDATION_MRZ_CHECK_DATE_OF_EXPIRY | Checks that the document's date of expiry is correct according to the checkdigit |
VALIDATION_MRZ_CHECK_DOCUMENT_NUMBER | Checks that the document number is correct according to the checkdigit |
VALIDATION_MRZ_CHECK_PERSONAL_NUMBER | Checks that the personal number is correct according to the checkdigit if it is available |
VALIDATION_GENDER | Checks that the gender has a correct value |
VALIDATION_ISSUING_STATE | Checks that the issuing state is correct according to the ISO 3166-1 Alpha-3 |
VALIDATION_NATIONALITY | Checks that the issuing state is correct according to the ISO 3166-1 Alpha-3 |
VALIDATION_PERSONAL_NUMBER_FORMAT | Checks that the format of the personal number is correct according to the ISO 3166-1 Alpha-3 |
VALIDATION_DOCUMENT_NUMBER_FORMAT | Checks that the format of the document number is correct according to the ISO 3166-1 Alpha-3 |
VALIDATION_DATE_OF_BIRTH | Checks that the date of birth is correct according to the checkdigit |
VALIDATION_DATE_OF_EXPIRY | Checks that the date of expiry is correct according to the checkdigit |
Scan only mandatory data
The MRZ is structured in mandatory and optional areas. The optional ones can be used by each issuing state to include customized information (personal number, SSN code...)m and non-standar checkdigit calculation methods are also allowed. If you want to obviate optional areas while performing a scan, add to listValidations
this validation:
ResultIDCard.FIELD_VALIDATION_MRZ_MANDATORY_DATA_VALIDATION