Code Samples
The following code example shows common usage of the library. Make
sure tessdata
folder are in the search path, and the .jar
files are in the classpath.
package net.sourceforge.tess4j.example; import java.io.File; import net.sourceforge.tess4j.*; public class TesseractExample { public static void main(String[] args) { File imageFile = new File("eurotext.tif"); ITesseract instance = new Tesseract(); // JNA Interface Mapping // ITesseract instance = new Tesseract1(); // JNA Direct Mapping instance.setDatapath("tessdata"); // path to tessdata directory try { String result = instance.doOCR(imageFile); System.out.println(result); } catch (TesseractException e) { System.err.println(e.getMessage()); } } }
More can be found under UnitTest package.
Tutorial: Development with Tess4J in NetBeans, Eclipse, and Command-line