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:
- Pure Java: No
JNI, noEXE/DLL, no Python runtime. A single JAR does it all, and you can add it via Maven directly into a Spring project. - CPU-first: The official recommendation is "CPU". It does not depend on
GPU/CUDA, runs on ordinary servers, and has very low deployment cost. - Cross-platform + Xinchuang: Supports
x86_64andARM, coveringWindows / Linux / macOS, and can also run on domestic systems such as Kylin and UOS. - Lazy loading: Models are loaded on demand; only the functionality you use is loaded, so startup is fast and memory is saved.
- Embedded models: Models are packaged directly into the JAR, so it works out of the box. You can also use
-Djiajia.model.dirto specify an external model directory (supports hot updates). - Thread-safe: A single instance can handle concurrent batch recognition; sharing one instance across multiple threads is enough.
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:
- General recognition: Mixed Chinese/English/numbers/symbols, returns text, confidence, and 8-point coordinates.
- Handwriting recognition: Optimized for Chinese handwriting, with 92%+ accuracy on standard datasets. Much stronger than Tesseract's handwriting capability.
- Text line detection: Only locates text line positions (does not recognize content), convenient for layout preprocessing.
- Layout detection: Recognizes titles, paragraphs, images, tables, and gives coordinates.
- Table detection: Locates table regions with confidence.
- Table recognition: Parses table structure into HTML + structured JSON (row/column level), directly connecting to your backend form/database logic.
- PDF recognition: Multi-page PDFs are automatically converted to images then batch OCR'd.
- Task cancellation: Long tasks can pass a
CancellationToken, and another thread callscancel()to interrupt. - Multithreaded batch: After a single instance is warmed up, multiple threads can concurrently call the shared instance; no need to create a new one per thread.
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.