| Crates.io | ddddocr |
| lib.rs | ddddocr |
| version | 0.1.0 |
| created_at | 2026-01-15 10:13:32.109171+00 |
| updated_at | 2026-01-15 10:13:32.109171+00 |
| description | Rust implementation of OCR for captcha recognition, ported from Python ddddocr |
| homepage | |
| repository | https://github.com/mzdk100/ddddocr-rs |
| max_upload_size | |
| id | 2045130 |
| size | 117,328 |
ddddocr-rs is a Rust implementation of the popular Python ddddocr library. It provides offline local captcha recognition using deep learning models trained on synthetic data. The library is designed for testing captcha difficulty and works completely offline without any network calls.
This Rust port maintains the same recognition capabilities while offering Rust's performance and safety benefits.
Add this to your Cargo.toml:
cargo add ddddocr
use ddddocr::DdddOcr;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the OCR with the model file
let mut ocr = DdddOcr::new("ddddocr.onnx")?;
// Read the captcha image
let image_bytes = std::fs::read("captcha.png")?;
// Perform recognition
let result = ocr.classification(&image_bytes).await?;
println!("Recognized text: {}", result);
Ok(())
}
The library provides a custom error type for better error handling:
use ddddocr::{DdddOcr, DdddOcrError};
async fn recognize_captcha(image_data: &[u8]) -> Result<String, DdddOcrError> {
let mut ocr = DdddOcr::new("ddddocr.onnx")?;
ocr.classification(image_data).await
}
#[tokio::main]
async fn main() {
let image_data = std::fs::read("test.png").expect("Failed to read image");
match recognize_captcha(&image_data).await {
Ok(text) => println!("Recognized: {}", text),
Err(e) => eprintln!("Error: {}", e),
}
}
You need to have the ddddocr.onnx model file. You can obtain it from the original ddddocr repository or use your own trained model.
The library processes images through the following pipeline:
(pixel/255.0 - 0.5) / 0.5DdddOcrMain struct for OCR operations.
new(model_path: &str) -> Result<Self, DdddOcrError>Creates a new DdddOcr instance by loading an ONNX model.
model_path: Path to the ONNX model file (.onnx)Result<DdddOcr, DdddOcrError>classification(&mut self, img: &[u8]) -> Result<String, DdddOcrError>Performs OCR recognition on image data.
img: Raw image bytesResult<String, DdddOcrError> - The recognized textort - ONNX Runtime for Rustimage - Image processing librarythiserror - Error handlingThis project is licensed under the MIT License - see the LICENSE file for details.
This library is designed for captcha difficulty testing and educational purposes. The effectiveness of recognition varies depending on captcha types and may require fine-tuning with custom models for specific use cases.