Volver al ranking

DayBreak-u/chineseocr_lite

C++

超轻量级中文ocr,支持竖排文字识别, 支持ncnn、mnn、tnn推理 ( dbnet(1.8M) + crnn(2.5M) + anglenet(378KB)) 总模型仅4.7M

ncnnocrpytorch
Crecimiento de estrellas
Estrellas
12.3k
Forks
2.3k
Crecimiento semanal
Issues
250
5k10k
feb 2020mar 2022may 2024jul 2026
README

ChineseOCR Lite

CLI · Web Demo · Models · Multi-platform Demo

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

功能

  • 中文 OCR 文字检测与识别
  • ONNX Runtime CPU 推理
  • Tornado Web 服务与前端展示页面
  • Android、C++、JVM、.NET 多端参考 Demo
  • 附带轻量模型文件,便于本地快速试跑

环境

推荐环境:

  • Python 3.6
  • Windows、Linux 或 macOS
  • CPU 推理,无需 CUDA

安装依赖:

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

  • ONNX Runtime C++ Demo,支持 Windows、Linux、macOS,目前仅支持 CPU
  • NCNN C++ Demo,支持 Windows、Linux、macOS,包含 CPU 版与 Vulkan GPU 版
  • MNN C++ Demo,支持 Windows、Linux、macOS,目前仅支持 CPU

JVM Demo

目录:jvm_projects

  • ONNX Runtime JVM Demo,基于 ONNX Runtime C++ 编译 JNI 供 Java/Kotlin 调用
  • NCNN JVM Demo,基于 NCNN C++ 编译 JNI 供 Java/Kotlin 调用,包含 CPU 版与 GPU 版

Android Demo

目录:android_projects

  • ONNX Runtime Android Demo
  • NCNN Android Demo,包含 CPU 版与 GPU 版
  • MNN Android Demo,支持 CPU 版

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

.NET Demo

目录:dotnet_projects

  • ONNX Runtime C# Demo
  • ONNX Runtime VB.NET Demo

字符检测 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

Repositorios relacionados
Tencent/ncnn

ncnn is a high-performance neural network inference framework optimized for the mobile platform

C++Otherinferencehigh-preformance
23.6k4.5k
AaronFeng753/Waifu2x-Extension-GUI

Video, Image and GIF upscale/enlarge(Super-Resolution) and Video frame interpolation. Achieved with Waifu2x, Real-ESRGAN, Real-CUGAN, RTX Video Super Resolution VSR, SRMD, RealSR, Anime4K, RIFE, IFRNet, CAIN, DAIN, and ACNet.

C++Otherwaifu2xanime4k
patreon.com/aaronfeng
16.8k1k
Baiyuetribe/paper2gui

Convert AI papers to GUI,Make it easy and convenient for everyone to use artificial intelligence technology。让每个人都简单方便的使用前沿人工智能技术

Jupyter NotebookMIT Licensedainhuoshan-tts
xiaobaituai.com
10.7k878
Megvii-BaseDetection/YOLOX

YOLOX is a high-performance anchor-free YOLO, exceeding yolov3~v5 with MegEngine, ONNX, TensorRT, ncnn, and OpenVINO supported. Documentation: https://yolox.readthedocs.io/

PythonPyPIApache License 2.0yoloxyolov3
10.5k2.5k
Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB

💎1MB lightweight face detection model (1MB轻量级人脸检测模型)

PythonPyPIMIT Licenseface-detectionarm
7.5k1.5k
RangiLyu/nanodet

NanoDet-Plus⚡Super fast and lightweight anchor-free object detection model. 🔥Only 980 KB(int8) / 1.8MB (fp16) and run 97FPS on cellphone🔥

PythonPyPIApache License 2.0deep-neural-networksdeep-learning
6.2k1.1k
Tohrusky/Final2x

2^x Image Super-Resolution

TypeScriptnpmBSD 3-Clause "New" or "Revised" Licensecross-platformelectron
6.2k477
Tencent/TNN

TNN: developed by Tencent Youtu Lab and Guangying Lab, a uniform deep learning inference framework for mobile、desktop and server. TNN is distinguished by several outstanding features, including its cross-platform capability, high performance, model compression and code pruning. Based on ncnn and Rapidnet, TNN further strengthens the support and performance optimization for mobile devices, and also draws on the advantages of good extensibility and high performance from existed open source efforts. TNN has been deployed in multiple Apps from Tencent, such as Mobile QQ, Weishi, Pitu, etc. Contributions are welcome to work in collaborative with us and make TNN a better framework.

C++Otherdeep-learningmnn
4.6k772
xlite-dev/lite.ai.toolkit

🛠A lite C++ AI toolkit: 100+ models with MNN, ORT and TRT, including Det, Seg, Stable-Diffusion, Face-Fusion, etc.🎉

C++GNU General Public License v3.0yoloxonnxruntime
github.com/xlite-dev/lite.ai.toolkit
4.4k783
DefTruth/lite.ai.toolkit

🛠 A lite C++ toolkit of 100+ Awesome AI models, support ORT, MNN, NCNN, TNN and TensorRT. 🎉🎉

C++GNU General Public License v3.0yoloxonnxruntime
4k731
zjhellofss/KuiperInfer

校招、秋招、春招、实习好项目!带你从零实现一个高性能的深度学习推理库,支持大模型 llama2 、Unet、Yolov5、Resnet等模型的推理。Implement a high-performance deep learning inference library step by step

C++MIT Licenseinferenceinference-engine
3.5k369
nihui/waifu2x-ncnn-vulkan

waifu2x converter ncnn version, runs fast on intel / amd / nvidia / apple-silicon GPU with vulkan

C++MIT Licensewaifu2xncnn
3.4k239