LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Recognize and Extract Data from passport in Java
#1
Posted
:
Friday, January 11, 2019 12:07:16 PM(UTC)
Groups: Registered, Manager, Tech Support, Administrators
Posts: 14
Below you will find a Java code snippet of how you can read and extract data from a passport.
Remember, in order to retrieve the most accurate results, you will want to have a very crisp and clear image so the engine will not have trouble during the process.
Code:
// Set your license
RasterSupport.setLicense(licenseFile, developerKey);
try {
if (RasterSupport.getKernelExpired()) {
System.out.println("License NOT Set Successfully");
}
else {
System.out.println("License Set Successfully");
}
RasterCodecs rasterCodecs = new RasterCodecs();
MRTDReader mrtdReader = new MRTDReader();
String stream = "PASSPORT_IMAGE.jpg";
RasterImage rasterImage = rasterCodecs.load(stream);
IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false);
ocrEngine.startup(RasterCodecs, null, null, null);
mrtdReader.setOcrEngine(ocrEngine);
mrtdReader.processImage(rasterImage);
mrtdReader.setImproveResults(true);
HashMap < MRTDField, MRTDDataElement > ar = new HashMap<>();
ar = mrtdReader.getResults();
String[] string = mrtdReader.getLines();
for (String string2 : string) {
System.out.println(string2);
}
for (Map.Entry < MRTDField, MRTDDataElement > map : ar.entrySet()) {
MRTDField key = map.getKey();
System.out.println(key);
MRTDDataElement value = map.getValue();
System.out.println(value.getReadableValue());
}
ocrEngine.shutdown();
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception(e);
}
Passport being recognized:Output:Pawel Lyko
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Recognize and Extract Data from passport in Java
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.