基于 RapidOCR/PaddleOCR 的智能 OCR 识别系统,支持 28 种行业文档的结构化解析。
- 🚀 双引擎支持: RapidOCR(默认,轻量快速)/ PaddleOCR(高精度)
- 📄 28 种行业模板: 发票、身份证、营业执照、合同、银行卡等
- 🔍 智能解析: 自动识别文档类型,提取结构化数据
- ⚡ 同步/异步模式: 支持实时识别和批量异步处理
- 🐳 Docker 部署: 一键启动,开箱即用
- 📊 置信度评估: 返回字段提取置信度分数
# AMD64 架构(Intel/AMD CPU)
docker pull ghcr.io/zxc321zxchb/ocr:latest
docker run -d --name ocr -p 18000:8000 ghcr.io/zxc321zxchb/ocr:latest
# ARM64 架构(Apple Silicon/树莓派)
docker pull ghcr.io/zxc321zxchb/ocr:latest-arm64
docker run -d --name ocr -p 18000:8000 ghcr.io/zxc321zxchb/ocr:latest-arm64# 克隆项目
git clone https://gitee.com/discoveringlife/ocr.git
cd ocr
# 启动服务(包含 PostgreSQL、Redis、Celery 等)
docker-compose up -d服务启动后访问:
- API 文档: http://localhost:18000/docs
- 健康检查: http://localhost:18000/health
# 安装依赖
cd backend
pip install -r requirements.txt
# 启动服务
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload# 图片识别(Base64)
curl -X POST http://localhost:18000/api/v1/ocr/recognize \
-H "Content-Type: application/json" \
-d '{"image": "data:image/png;base64,xxx", "mode": "sync"}'
# URL 识别
curl -X POST http://localhost:18000/api/v1/ocr/recognize \
-H "Content-Type: application/json" \
-d '{"image": "https://example.com/image.png", "mode": "sync"}'# 获取支持的模板列表
curl http://localhost:18000/api/v1/parser/templates
# 发票解析
curl -X POST http://localhost:18000/api/v1/parser/extract \
-H "Content-Type: application/json" \
-d '{
"text": "增值税专用发票\n发票代码:012345678901\n发票号码:12345678",
"template": "invoice"
}'
# 自动识别文档类型
curl -X POST http://localhost:18000/api/v1/parser/extract \
-H "Content-Type: application/json" \
-d '{"text": "中华人民共和国居民身份证\n姓名:张三\n公民身份号码:110101199001011234"}'{
"code": 200,
"message": "success",
"data": {
"doc_type": "invoice",
"structured_data": {
"invoice_code": "012345678901",
"invoice_number": "12345678",
"invoice_date": "2024年01月15日"
},
"confidence": 0.85,
"parse_method": "regex"
}
}| 类别 | 模板 |
|---|---|
| 证件类 | 身份证、护照、港澳通行证、驾驶证、行驶证、社保卡 |
| 票据类 | 增值税发票、医疗票据、火车票/机票 |
| 证书类 | 营业执照、房产证、学历证书、出生证明、结婚证、离婚证、完税证明 |
| 合同类 | 通用合同、购房合同、租房合同、劳动合同 |
| 金融类 | 银行卡、银行流水、征信报告、工资条 |
| 其他 | 户口本、快递单、名片、简历 |
ocr/
├── backend/ # 后端服务
│ ├── app/
│ │ ├── api/v1/ # API 路由
│ │ │ ├── ocr.py # OCR 识别接口
│ │ │ ├── parser.py # 智能解析接口
│ │ │ └── system.py # 系统接口
│ │ ├── core/ # 核心模块
│ │ │ └── engines/ # OCR 引擎
│ │ ├── services/ # 业务服务
│ │ │ ├── smart_parser.py # 智能解析
│ │ │ ├── regex_engine.py # 正则引擎
│ │ │ ├── template_manager.py # 模板管理
│ │ │ └── templates/ # 28 种行业模板
│ │ └── tasks/ # Celery 异步任务
│ └── requirements.txt
├── config/ # 配置文件
├── tests/ # 测试文件
├── docs/ # 文档
├── docker-compose.yml # Docker 编排
├── Dockerfile # 镜像构建
└── Makefile # 常用命令
# .env
APP_PORT=8000
DB_HOST=postgres
DB_PORT=5432
REDIS_HOST=redis
REDIS_PORT=6379# config/app_config.yaml
ocr:
engine: rapid # rapid 或 paddle
lang: ch
parser:
llm_enabled: false # 是否启用 LLM(预留)
default_template: auto # 自动识别文档类型
confidence_threshold: 0.6| 服务 | 端口 | 说明 |
|---|---|---|
| API | 18000 | FastAPI 主服务 |
| PostgreSQL | 15432 | 数据库 |
| Redis | 16379 | 缓存/消息队列 |
| Flower | 15555 | Celery 监控 |
| MinIO | 19000/19001 | 对象存储 |
# Docker
./start-docker.sh # 启动服务
./stop-docker.sh # 停止服务
docker-compose logs -f # 查看日志
# Makefile
make help # 查看帮助
make docker-up # 启动 Docker
make docker-down # 停止 Docker
make test-unit # 运行测试
make clean # 清理缓存MIT License