Recognize Handwritten Text From Images With ICR - Java

This tutorial shows how to create a Java application that runs ICR to recognize handwritten text on a given image using the LEADTOOLS SDK.

Overview
Summary This tutorial covers how to use LEADTOOLS Recognition SDK technology in a Java application.
Completion Time 30分钟
Eclipse Project Download tutorial project (2 KB)
Platform Java Application
IDE Eclipse
Development License Download LEADTOOLS
Try it in another language

Required Knowledge

Get familiar with the basic steps of creating a project by reviewing theAdd References and Set a Licensetutorial, before working on theRecognize Handwritten Text From Images With ICR - Javatutorial.

Create the Project and Add the LEADTOOLS References

Start with a copy of the project created in theAdd References and Set a Licensetutorial. If that project is unavailable, follow the steps in that tutorial to create it.

The references needed depend upon the purpose of the project. References can be added by local.jarfiles located at\LEADTOOLS21\Bin\Java.

For this project, the following references are needed:

For a complete list of which JAR files are required for your application, refer toFiles to be Included with your Java Application

Set the License File

The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer toSetting a Runtime License.

There are two types of runtime licenses:

Note

Adding LEADTOOLS local references and setting a license are covered in more detail in theAdd References and Set a Licensetutorial.

Initialize OCR Engine and Recognize Hand-written Text

With the project created, the references added, and the license set, coding can begin.

Open the_Main.javaclass in theProject Explorer. Add the following statements to theimportblock at the top.

Java
// Import block at the topimportjava.io.IOException;importjava.nio.file.*;importleadtools.*;importleadtools.document.writer.*;importleadtools.ocr.*;

Inside themain()method, add the following code to set the library path to where the C DLL files are located, and load the LEADTOOLS libraries that were previously imported.

Java
publicstaticvoidmain(String[] args)throwsIOException{Platform.setLibPath("C:\\LEADTOOLS21\\Bin\\CDLL\\x64");Platform.loadLibrary(LTLibrary.LEADTOOLS);Platform.loadLibrary(LTLibrary.OCR);SetLicense();RunICR();}

Add a new method to the_Mainclass calledRunICR(). Call this method inside themain()method below the call to theSetLicense()method, as shown above. Add the code below to run Intelligent Character Recognition on the loaded image and export the results to a searchable PDF. For the purposes of this tutorial the sample image located in the following file path will be used:C:\LEADTOOLS21\Resources\Images\demoicr2.tif.

Java
staticvoidRunICR(){String _file ="C:\\LEADTOOLS21\\Resources\\Images\\demoicr2.tif";OcrEngine _ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD);_ocrEngine.startup(null,null,null,"C:\\LEADTOOLS21\\Bin\\Common\\OcrLEADRuntime");// Create an OCR documentOcrDocument _ocrDocument = _ocrEngine.getDocumentManager().createDocument();ILeadStream _fileStream =newLeadFileStream(_file);OcrPage _ocrPage = _ocrDocument.getPages().addPage(_fileStream,null);_ocrPage.autoZone(null);for(inti = 0; i < _ocrPage.getZones().size(); i++){OcrZone _zone = _ocrPage.getZones().get(i);_zone.setZoneType(OcrZoneType.ICR);}_ocrPage.recognize(null);_ocrDocument.save("C:\\LEADTOOLS21\\Resources\\Images\\icr.pdf", DocumentFormat.PDF,null);_ocrDocument.dispose();_ocrEngine.dispose();}

Run the Project

Run the project by pressingCtrl + F11, or by selectingRun->Run.

如果是正确的步骤,应用ion will auto-zone the loaded image, run ICR, then output the recognized image to a searchable PDF.

Wrap-up

This tutorial showed how to run ICR on an image and output to a searchable PDF. It also covered how to use theOcrZonestructure.

See Also

iOS
188金宝搏的网址客服|Support|Contact Us|Intellectual Property Notices
© 1991-2021LEAD Technologies, Inc.All Rights Reserved.