From a3d5fbebe1fdf61138b54f52f5cbd815b6931632 Mon Sep 17 00:00:00 2001 From: gitee-bot Date: Fri, 19 Jun 2026 00:22:22 +0000 Subject: [PATCH] Add README.md --- README.en.md | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 280 insertions(+) create mode 100644 README.en.md create mode 100644 README.md diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..f185a3a --- /dev/null +++ b/README.en.md @@ -0,0 +1,139 @@ +# Card Correction System + +## Project Overview + +This project is a card/ticket image detection and correction system implemented with a hybrid architecture combining a Python FastAPI backend and a Java ONNX inference engine. The system supports uploading images containing multiple tickets, automatically detecting, locating, and correcting each ticket, and returning corrected image files. + +## Technical Architecture + +- **Backend Framework**: Python FastAPI +- **Machine Learning Inference**: Java + ONNX Runtime +- **Model**: Deep learning model in ONNX format (ResNet18-based) +- **Image Processing**: OpenCV (Java) + +## Features + +- 📤 Support for batch uploading ticket images +- 🔍 Automatic detection of multiple tickets within an image +- ✨ Automatic cropping and angle correction of tickets +- 📦 Returns a ZIP archive containing all corrected tickets +- 🏥 Health check endpoint + +## Directory Structure + +``` +├── api/ # API routing module +│ ├── routes/ +│ │ └── cards.py # Ticket processing routes +│ └── schemas.py # Data models +├── cardcorrection1/ # Java inference module +│ ├── CardCorrectionDetector.java # ONNX detector +│ ├── CardCorrectionResult.java # Detection result data model +│ ├── CardCorrectionUtils.java # Image processing utility class +│ └── TicketDetectionService.java # Ticket detection service +├── services/ +│ └── card_service.py # Python ticket service +├── utils/ +│ └── logger.py # Logging utility +├── main.py # FastAPI application entry point +├── config.py # Configuration management +├── dependencies.py # Dependency injection +└── pyproject.toml # Python project configuration +``` + +## API Endpoints + +### 1. Ticket Processing Endpoint + +**Endpoint**: `POST /api/process` + +**Description**: Upload ticket images, detect and correct multiple tickets, return a compressed archive. + +**Request**: +- `files`: List of image files (supports multiple files) + +**Response**: +- ZIP archive containing all corrected tickets + +### 2. Health Check + +**Endpoint**: `GET /health` + +**Response**: +```json +{ + "status": "ok" +} +``` + +## Quick Start + +### Prerequisites + +- Python 3.9+ +- Java 11+ +- ONNX Runtime (via Maven dependency) + +### Install Dependencies + +```bash +# Python dependencies +pip install -r requirements.txt + +# Java dependencies (using Maven) +mvn dependency:resolve +``` + +### Configuration + +Copy and modify the configuration sample file: + +```bash +cp .env.example .env +``` + +Key configuration items: +- `CARD_MODEL_PATH`: Path to the ONNX model +- `JAVA_CLASS_PATH`: Java classpath +- `DETECTION_TOP_K`: Number of top detections to return +- `DETECTION_OBJ_SCORE`: Detection confidence threshold + +### Start the Service + +```bash +uvicorn main:app --reload --port 8000 +``` + +## Model Details + +The system uses a ResNet18-based ONNX model for ticket detection. Model outputs include: +- Ticket location heatmap +- Regression offsets +- Width and height information +- Angle class (0–3) +- Document type + +## Detection Pipeline + +1. **Image Preprocessing**: Resize and normalize the input image +2. **ONNX Inference**: Perform detection using the Java inference engine +3. **Post-processing**: + - Non-Maximum Suppression (NMS) + - Bounding box decoding + - Affine transformation correction +4. **Image Cropping**: Crop and correct tickets based on detection results +5. **Result Delivery**: Package corrected images into a ZIP file for return + +## Technology Stack + +| Component | Technology | +|---------|------------| +| Web Framework | FastAPI | +| Inference Engine | ONNX Runtime (Java) | +| Image Processing | OpenCV (Java) | +| Asynchronous Tasks | asyncio | +| Build Tools | Maven (Java) / uv (Python) | + +## License + +For specific licensing details, please refer to the LICENSE file. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9911930 --- /dev/null +++ b/README.md @@ -0,0 +1,141 @@ +Based on the code map provided, I can see this is a hybrid Python + Java project for card/ticket detection and correction. Let me analyze the structure and write a comprehensive README. + +# 票据校正系统 (Card Correction) + +## 项目简介 + +本项目是一个票据/证件图像检测与校正系统,采用 Python FastAPI 后端结合 Java ONNX 推理引擎的混合架构实现。系统支持上传包含多张票据的图像,自动检测、定位并校正每张票据,返回矫正后的图像文件。 + +## 技术架构 + +- **后端框架**: Python FastAPI +- **机器学习推理**: Java + ONNX Runtime +- **模型**: ONNX 格式的深度学习模型 (ResNet18-based) +- **图像处理**: OpenCV (Java) + +## 功能特性 + +- 📤 支持批量上传票据图像 +- 🔍 自动检测图像中的多张票据 +- ✨ 自动裁剪和校正票据角度 +- 📦 返回 ZIP 压缩文件(包含所有校正后的票据) +- 🏥 健康检查接口 + +## 目录结构 + +``` +├── api/ # API 路由模块 +│ ├── routes/ +│ │ └── cards.py # 票据处理路由 +│ └── schemas.py # 数据模型 +├── cardcorrection1/ # Java 推理模块 +│ ├── CardCorrectionDetector.java # ONNX 检测器 +│ ├── CardCorrectionResult.java # 检测结果数据模型 +│ ├── CardCorrectionUtils.java # 图像处理工具类 +│ └── TicketDetectionService.java # 票据检测服务 +├── services/ +│ └── card_service.py # Python 票据服务 +├── utils/ +│ └── logger.py # 日志工具 +├── main.py # FastAPI 应用入口 +├── config.py # 配置管理 +├── dependencies.py # 依赖注入 +└── pyproject.toml # Python 项目配置 +``` + +## API 接口 + +### 1. 票据处理接口 + +**端点**: `POST /api/process` + +**描述**: 上传票据图像,检测并矫正多张票据,返回压缩文件 + +**请求**: +- `files`: 图像文件列表(支持多张) + +**响应**: +- 包含所有矫正后票据的 ZIP 压缩文件 + +### 2. 健康检查 + +**端点**: `GET /health` + +**响应**: +```json +{ + "status": "ok" +} +``` + +## 快速开始 + +### 环境要求 + +- Python 3.9+ +- Java 11+ +- ONNX Runtime (通过 Maven 依赖) + +### 安装依赖 + +```bash +# Python 依赖 +pip install -r requirements.txt + +# Java 依赖 (使用 Maven) +mvn dependency:resolve +``` + +### 配置 + +复制配置示例文件并修改: + +```bash +cp .env.example .env +``` + +主要配置项: +- `CARD_MODEL_PATH`: ONNX 模型路径 +- `JAVA_CLASS_PATH`: Java 类路径 +- `DETECTION_TOP_K`: 检测TOP K数量 +- `DETECTION_OBJ_SCORE`: 检测置信度阈值 + +### 启动服务 + +```bash +uvicorn main:app --reload --port 8000 +``` + +## 模型说明 + +系统使用基于 ResNet18 的 ONNX 模型进行票据检测,模型输出: +- 票据位置热力图 (Heatmap) +- 回归偏移量 (Regression) +- 宽高信息 (Width-Height) +- 角度类别 (0-3) +- 证件类型 + +## 检测流程 + +1. **图像预处理**: 调整图像大小并进行归一化 +2. **ONNX 推理**: 使用 Java 推理引擎进行检测 +3. **后处理**: + - 非极大值抑制 (NMS) + - 边界框解码 + - 仿射变换校正 +4. **图像裁剪**: 根据检测结果裁剪并校正票据 +5. **结果返回**: 打包为 ZIP 文件返回 + +## 技术栈 + +| 组件 | 技术 | +|------|------| +| Web 框架 | FastAPI | +| 推理引擎 | ONNX Runtime (Java) | +| 图像处理 | OpenCV (Java) | +| 异步任务 | asyncio | +| 构建工具 | Maven (Java) / uv (Python) | + +## 许可证 + +本项目具体许可证请查看 LICENSE 文件。 \ No newline at end of file -- Gitee