跪拜 Guibai
← All articles
Backend · Java · Programmer

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

By SimonKing ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Java backend teams get an OCR option that avoids Python sidecars and GPU provisioning; the single-JAR model packaging and thread-safe API make it a drop-in for Spring services, including on restricted or domestic OS environments.

Summary

JiaJiaOCR is a pure Java OCR engine built on ONNX Runtime and OpenCV, with no JNI, no EXE/DLL, and no Python runtime. It runs on CPU, officially recommended over GPU, and ships models inside the JAR with lazy loading; a single instance is thread-safe for concurrent batch recognition. Beyond general text recognition, it handles Chinese handwriting with a claimed 92%+ accuracy on standard datasets, layout detection, table detection and recognition that outputs HTML and structured JSON, and multi-page PDF OCR.

Installation requires building the project yourself because it's not on Maven Central: run mvn clean package -DskipTests, add onnxruntime, opencv, pdfbox and commons-lang3 dependencies, then download models from the GitHub releases page and place them on the classpath. A sample test calls recognizeGeneralText with try-with-resources and prints recognized text. The GitHub repo has other examples, and the project sits at 105 stars.

Takeaways
— Pure Java OCR engine with no JNI, EXE/DLL, or Python runtime.
— CPU is the recommended runtime; no GPU/CUDA dependency.
— Supports x86_64 and ARM on Windows, Linux, macOS, plus Kylin and UOS.
— Models are embedded in the JAR and load lazily; external models can be set via -Djiajia.model.dir with hot updates.
— A single thread-safe instance handles concurrent batch recognition.
— Features: general text, Chinese handwriting, text line detection, layout detection, table detection and recognition, PDF OCR, task cancellation, and multithreaded batch.
— Handwriting recognition claims 92%+ accuracy on standard Chinese datasets.
— Table recognition outputs HTML and structured JSON at row/column level.
— Not published to Maven Central; requires local build with mvn clean package -DskipTests.
— Dependencies: onnxruntime 1.19.0, opencv 4.9.0-0, pdfbox 3.0.2 (for PDF), commons-lang3 3.17.0.
— Models download from GitHub releases and go on the classpath under models.
— The project has 105 stars on GitHub.
Conclusions

The 92%+ handwriting accuracy claim against Tesseract arrives without benchmark methodology, so it reads as a marketing number rather than a verified result.

Bundling ONNX Runtime and OpenCV as Maven dependencies sidesteps the native-library setup that usually trips up Java OCR, but a 105-star project absent from Maven Central demands a build-and-test pass before any production commitment.

CPU-first operation and lazy model loading match the reality of most Java backend deployments, where GPU access is rare and startup memory is a real constraint.

Source: juejin.cn ↗ Google Translate ↗ Backup ↗