LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Recognize and Extract Data From a Passport in Java
#1
Posted
:
Tuesday, July 25, 2017 2:36:03 PM(UTC)
Groups: Registered
Posts: 119
Was thanked: 4 time(s) in 4 post(s)
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);
OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.ADVANTAGE);
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:Nick Villalobos
Developer Support Engineer
LEAD Technologies, Inc.
#2
Posted
:
Friday, February 1, 2019 5:07:15 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 54
Thanks: 2 times
Was thanked: 10 time(s) in 10 post(s)
I have created a project using this code for version 20 of our toolkit. The code is essentially the same, however the OCR Advantage engine is now called LEAD. I have also disposed of the RasterCodecs, the RasterImage, as well as the OcrEngine to prevent memory leaks.
Note that you will have to set your license in the DemoUtilities.java file located in C:\LEADTOOLS 20\Examples\Java\Common.
You can find the project zip attached here:
Josh Clark
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Recognize and Extract Data From a 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.