chineseocr_lite README

The project's README from github.com/DayBreak-u/chineseocr_lite. As one markdown file: README.md.

ChineseOCR Lite

CLI · Web Demo · Models · Multi-platform Demo

轻量级中文 OCR 项目,当前分支以 ONNX Runtime 推理为主,包含 Web 服务、Python 推理代码,以及 C++、JVM、Android、.NET 等多端 Demo。

功能

环境

推荐环境:

安装依赖:

pip install -r requirements.txt

启动 Web 服务

cd chineseocr_lite
python backend/main.py

服务默认监听 8089 端口。启动后终端会输出类似:

server is running: 192.168.x.x:8089

在浏览器打开该地址即可使用 Web OCR 页面。

CLI 使用

当前项目也可以作为命令行 OCR 工具使用,适合被 agent、脚本或批处理任务调用。

本地开发安装:

pip install -e .

识别单张图片并输出 JSON:

chineseocr test_imgs/res.jpg

写入 JSON 文件:

chineseocr test_imgs/res.jpg --output result.json

同时输出带检测框的图片:

chineseocr test_imgs/res.jpg --output result.json --draw result.jpg

调整检测前的短边尺寸:

chineseocr test_imgs/res.jpg --compress 960

CLI 输出为稳定 JSON,便于 agent 解析:

{
  "text": "识别出的全文",
  "blocks": [
    {
      "text": "单个文本块",
      "score": 0.93,
      "box": [[12, 30], [210, 31], [209, 60], [11, 59]]
    }
  ],
  "elapsed": 1.24
}

也可以用 Python 模块方式运行:

python -m chineseocr_lite test_imgs/res.jpg

模型文件

当前仓库包含基础推理模型:

目录 文件 用途
models/ dbnet.onnx 文本检测
models/ crnn_lite_lstm.onnx 文本识别
models/ angle_net.onnx 文字方向分类
models_ncnn/ *.bin, *.param NCNN Demo 使用的模型

作为 Python CLI 包安装时,models/*.onnx 会随包一起安装,CLI 开箱即可使用。models_ncnn/ 和各端 Demo 不会作为 CLI 必需资源。

不要把训练权重、Python wheel、大型第三方库或构建产物直接提交到 Git。推荐放到 GitHub Releases、对象存储或 Git LFS。

项目结构

.
├── backend/             Web 服务与接口
├── models/              ONNX 模型
├── models_ncnn/         NCNN 模型
├── dbnet/               文本检测相关代码
├── crnn/                文本识别相关代码
├── angnet/              方向分类相关代码
├── cpp_projects/        C++ Demo
├── jvm_projects/        JVM Demo
├── android_projects/    Android Demo
├── dotnet_projects/     .NET Demo
├── test_imgs/           示例图片与效果图
├── config.py            模型与推理配置
├── model.py             OCR 推理入口
└── utils.py             通用工具函数

多端 Demo

以下 Demo 均为参考 Python 版本翻译或封装而来,彼此相互独立。

C++ Demo

目录:cpp_projects

JVM Demo

目录:jvm_projects

Android Demo

目录:android_projects

如果不想自行整合依赖库,完整源码工程可到 QQ 群共享中下载。

.NET Demo

目录:dotnet_projects

字符检测 OCR Demo

第三方项目:fanqie03/char-detection

根据本项目和 CRNN 原理推导每个字符的位置,并支持将字符组合成单词。

TNN 第三方 Demo

第三方项目:Tencent/TNN OCR 示例

基于本项目实现的轻量级中文 OCR Demo,支持 iOS 和 Android,使用 TNN 的 ARM CPU、OpenCL、Metal 后端加速模型计算。

效果展示

Web 识别

Web OCR result 1

Web OCR result 2

Android 识别

Android IMEI OCR

Android ID card OCR

Android plate OCR

.NET 识别

.NET OCR

字符检测 OCR

Character detection OCR

TNN 第三方 Demo

TNN camera OCR

TNN poster OCR 1

TNN poster OCR 2

chineseocr_lite (DayBreak-u/chineseocr_lite)

Searching Database…

What is this?An ultra-lightweight Chinese OCR engine: it finds and recognizes text in images, including vertical text. Detection, recognition and angle classification run on three tiny models that total only 4.7MB, entirely on CPU.
So what am I actually installing — a Python tool, a web app, or a mobile SDK?The main branch is Python: a CLI plus a Tornado web service with a browser page. The repo also carries independent reference demos for C++, JVM (Java/Kotlin), Android and .NET.
How do I get it running?Install it as a Python package — the .onnx models ship with it, so the CLI works out of the box. Or start the Tornado web service and open its address in a browser; it listens on port 8089 by default.
What does my machine need to run it — a GPU or just a normal laptop?Python 3.6 on Windows, Linux or macOS. The main branch infers on CPU, so no CUDA or GPU setup is needed; GPU builds exist only in the NCNN demo variants.
Is Chinese the only language it can read?It is built for Chinese text — the README claims no other languages. Also, the C++, JVM, Android and .NET demos are reference ports translated from the Python version, each maintained independently rather than as polished products.
Will it run on my phone?Android is covered by official demos: ONNX Runtime, NCNN (CPU and GPU) and MNN. iOS has no official demo — the third-party TNN demo adds iOS using ARM CPU, OpenCL or Metal backends.
If I feed it images, does everything stay on my machine?Yes — inference happens entirely on your machine's CPU with the bundled models; no external service is involved.
Can it handle vertical Chinese text, like columns in traditional layouts?Yes — vertical text recognition is called out as a core feature in the project's own description, alongside the ultra-small 4.7MB total model size.
I want the Android or C++ demo without wiring native deps myself — possible?Yes — the README says complete source projects are available in a QQ group's shared files if you don't want to integrate ONNX Runtime, NCNN or MNN yourself.
Can it give me the position of each individual character?There's a third-party project, fanqie03/char-detection, built on this repo and CRNN principles, that derives the position of each character and combines characters into words.
Creator
DayBreak-u
Size
241.4 MB
Stars
12.3K
Updated
CommitMay 18
Age
6y
Commits · 90 Days