Skip to content
Branch: master
Find file History
saudet * Add packages missing from TensorFlow (issue #773)
 * Fix JPMS module name for Tesseract (issue #772)
Latest commit 8c5ca2b Jul 30, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
platform Update version in the `pom.xml` files to 1.5.2-SNAPSHOT Jul 10, 2019
samples
src * Add packages missing from TensorFlow (issue #773) Jul 30, 2019
COPYING * Upgrade presets for Tesseract 4.0.0-beta.1 (issue #385) Apr 12, 2018
README.md
cppbuild.sh Release version 1.5.1 Jul 9, 2019
pom.xml Update version in the `pom.xml` files to 1.5.2-SNAPSHOT Jul 10, 2019
tesseract-android.patch * Upgrade presets for Tesseract 4.1.0-rc4, MXNet 1.5.0.rc1, TensorFl… Jun 21, 2019
tesseract-configure.patch * Upgrade presets for Tesseract 4.1.0-rc4, MXNet 1.5.0.rc1, TensorFl… Jun 21, 2019
tesseract-openmp.patch Add .m2 to cache, enable ccache, and use build stages for TensorFlow … Oct 7, 2018

README.md

JavaCPP Presets for Tesseract

Introduction

This directory contains the JavaCPP Presets module for:

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

Documentation

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 BasicExample.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

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.bytedeco.tesseract</groupId>
    <artifactId>BasicExample</artifactId>
    <version>1.5.1</version>
    <properties>
        <exec.mainClass>BasicExample</exec.mainClass>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>tesseract-platform</artifactId>
            <version>4.1.0-1.5.1</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>.</sourceDirectory>
    </build>
</project>

The BasicExample.java source file

import org.bytedeco.javacpp.*;
import org.bytedeco.leptonica.*;
import org.bytedeco.tesseract.*;
import static org.bytedeco.leptonica.global.lept.*;
import static org.bytedeco.tesseract.global.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.");
            System.exit(1);
        }

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

        // Destroy used object and release memory
        api.End();
        outText.deallocate();
        pixDestroy(image);
    }
}
You can’t perform that action at this time.