High Performance ยท Rust-based OCR Service
Image text recognition service based on Paddle OCR onnx models, compatible with OpenAI's chat/completions API.
Features โข Quick Start โข CLI Tool โข API Service โข Performance
Languages: English | ็ฎไฝไธญๆ
- ๐ Extreme Performance - Native Rust implementation with memory safety and zero-copy optimization
- ๐ฏ High Accuracy Recognition - Supports the latest Paddle OCR v5 models
- ๐ง Flexible Configuration - Rich parameter configuration to adapt to different scenarios
- ๐ฆ Ready to Use - Simple CLI tool, no programming required
- ๐ API Service - Built-in HTTP API server compatible with OpenAI interface format
- ๐ Concurrent Processing - Multi-threading support for efficient batch request handling
- ๐ Detailed Output - Support for JSON/text formats with confidence information
# Clone the project git clone https://github.com/go-restream/pp-ocr-rs.git cd pp-ocr-rs # Build CLI tool cargo build --release # Build API service (with server feature) cargo build --release --features server# Recognize a single image ./target/release/ocr image.png # Batch recognize images in directory ./target/release/ocr /path/to/images/ # Start API service ./target/release/ocr serve -c config.yamlOCR Engine - Image text recognition using Paddle OCR Usage: ocr [OPTIONS] <INPUT> Arguments: <INPUT> Image file or directory containing images Options: -c, --config <FILE> YAML configuration file path -f, --format <FORMAT> Output format [text|json] [default: text] -o, --output <FILE> Output file path --append Append mode (when outputting to file) -r, --recursive Process subdirectories recursively -q, --quiet Quiet mode -v, --verbose Verbose mode --pretty-json Pretty JSON output --include-confidence Include confidence information --include-processing-time Include processing time information -h, --help Print help informationCreate config.yaml:
# Model paths det_model_path: "./models/ch_PP-OCRv5_mobile_det.onnx" cls_model_path: "./models/ch_ppocr_mobile_v2.0_cls_infer.onnx" rec_model_path: "./models/ch_PP-OCRv5_rec_mobile_infer.onnx" # Feature switches use_angle_cls: false use_direction_cls: false # Detection parameters detection: box_limit: 50 box_thresh: 0.5 min_box_size: 0.3 unclip_ratio: 1.6 # Output settings output: include_confidence: true pretty_json: true include_processing_time: true# Use default configuration (listen on 0.0.0.0:8080) ./target/release/ocr serve # Use configuration file ./target/release/ocr serve --config config.yaml # Custom bind address and thread count ./target/release/ocr serve --bind 127.0.0.1:9000 --threads 8curl http://localhost:8080/v1/healthcurl http://localhost:8080/v1/modelscurl -X POST http://localhost:8080/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "ch_pp_ocr_v5_mobile", "messages": [{ "role": "user", "content": [{ "type": "image_url", "image_url": { "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB..." } }] }] }'import base64 import requests # Read image with open('image.png', 'rb') as f: image_data = base64.b64encode(f.read()).decode('utf-8') # Send OCR request response = requests.post( 'http://localhost:8080/v1/chat/completions', json={ 'model': 'ch_pp_ocr_v5_mobile', 'messages': [{ 'role': 'user', 'content': [{ 'type': 'image_url', 'image_url': { 'url': f'data:image/png;base64,{image_data}' } }] }] } ) # Parse result result = response.json() text = result['choices'][0]['message']['content'][0]['text'] print(f"Recognition result: {text}")| Test Image | Recognition Result | Confidence |
|---|---|---|
![]() | Use Rust to call Paddle OCR models through ONNX Runtime for image text recognition. | 95.27% |
![]() | ๆฏๅฉด็จๅ่ฟ้ | 99.71% |
- Processing Speed: Mobile model < 100ms/image (CPU)
- Memory Usage: < 200MB (single instance)
- Concurrent Capacity: Support multi-threaded concurrent processing
- Accuracy: > 95% in Chinese scenarios
| Model Name | Type | Features | Use Cases |
|---|---|---|---|
| ch_pp_ocr_v5_mobile | Mobile | Fast speed, small size | Real-time processing, mobile devices |
| ch_pp_ocr_v5_server | Server | High accuracy, better results | Batch processing, high-precision requirements |
- Rust 1.84+
- ONNX Runtime 2.0+
# Install dependencies cargo build # Run tests cargo test # Run examples cargo run --example ocr_demoIssues and Pull Requests are welcome!
- Fork this project
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the Apache License 2.0.
- Rapid OCR - Excellent OCR model framework
- Paddle-ocr-rs - Paddle OCR Rust model library
If this project helps you, please give it a โญ๏ธ!
GitHub โข Documentation โข Examples
Languages: English | ็ฎไฝไธญๆ

