跪拜 Guibai
← Back to the summary

JiaJiaOCR: Pure Java OCR Skips Python and GPU, Packs Models Into the JAR

Found Another Pure Java OCR Project with Many Recognition Formats

01 Introduction

A couple of days ago I shared a RapidOCR project, and today I found another OCR project. It has zero Python dependency, is a pure Java project, and can run without a GPU. Isn't this tailor-made for Java backends like us? Java backend developers now have one more OCR option!

02 Overview

JiaJiaOCR is a pure Java OCR engine. On top of general text recognition, it adds handwriting OCR, layout detection, table detection and recognition, covering printed text, handwriting, and document structure parsing in all scenarios.

Its core advantages:

GitHub URL: https://github.com/jiangnanboy/JiaJiaOCR

03 Installation

JiaJiaOCR is not uploaded to the central repository, so you need to build it yourself.

3.1 Build

mvn clean package -DskipTests

3.2 Add auxiliary dependencies

Add these core dependencies to pom.xml (pdfbox is only needed for PDF recognition):

<dependencies>
    <dependency>
        <groupId>com.microsoft.onnxruntime</groupId>
        <artifactId>onnxruntime</artifactId>
        <version>1.19.0</version>
    </dependency>
    <dependency>
        <groupId>org.openpnp</groupId>
        <artifactId>opencv</artifactId>
        <version>4.9.0-0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.pdfbox</groupId>
        <artifactId>pdfbox</artifactId>
        <version>3.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.17.0</version>
    </dependency>
</dependencies>

3.3 Models need to be loaded

Models are available at https://github.com/jiangnanboy/JiaJiaOCR/releases/tag/models, and you need to download them in advance.

You can simply place them under models in the project's classpath.

04 Testing

JiaJiaOCR provides multiple recognition modes:

Let's test with general recognition:

public class TestjiajiaOcr {

    String imagePath = "src/main/images/u.jpeg";

    @Test
    void test01() throws OrtException {
        try (JiaJiaOCR ocr = JiaJiaOCR.builder()) {
            List<Pair<Text, Box>> results = ocr.recognizeGeneralText(imagePath);
            String content = "";
            for (Pair<Text, Box> item : results) {
                content += item.getLeft().getText();
            }
            System.out.println(content);
        }
    }
}

Recognition target:

Recognition result:

The GitHub repo provides other examples, so interested folks can test them.

05 Summary

JiaJiaOCR offers another OCR option for pure Java teams. Although its GitHub star count is only 105, that does not prevent it from being a usable tool for us.