Find file History
Latest commit 20be8fd Jan 29, 2017 @piotr277 piotr277 committed with saudet Add `linux-arm64` platform to the `` script of Leptonica a…
…nd Tesseract (pull #370)

JavaCPP Presets for Tesseract


This directory contains the JavaCPP Presets module for:

Please refer to the parent file for more detailed information about the JavaCPP Presets.


Java API documentation is available here:

Sample Usage

Here is a simple example of Tesseract ported to Java from this C++ source file and for this data:

We can use Maven 3 to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the pom.xml and src/main/java/ source files below, simply execute on the command line:

 $ mvn compile exec:java -Dexec.args="path/to/image/file"

The pom.xml build file


The src/main/java/ source file

import org.bytedeco.javacpp.*;
import static org.bytedeco.javacpp.lept.*;
import static org.bytedeco.javacpp.tesseract.*;

public class BasicExample {
    public static void main(String[] args) {
        BytePointer outText;

        TessBaseAPI api = new TessBaseAPI();
        // Initialize tesseract-ocr with English, without specifying tessdata path
        if (api.Init(null, "eng") != 0) {
            System.err.println("Could not initialize tesseract.");

        // Open input image with leptonica library
        PIX image = pixRead(args.length > 0 ? args[0] : "/usr/src/tesseract/testing/phototest.tif");
        // Get OCR result
        outText = api.GetUTF8Text();
        System.out.println("OCR output:\n" + outText.getString());

        // Destroy used object and release memory