Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, July 25, 2017 2:36:03 PM(UTC)
Nick Villalobos

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:

Passport Sample

Output:

output
Nick Villalobos
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Friday, February 1, 2019 5:07:15 PM(UTC)
Josh Clark

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:
File Attachment(s):
PassportReader.zip (3kb) downloaded 166 time(s).
Josh Clark
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.093 seconds.