Expand description
§ddddocr - Rust implementation of OCR for captcha recognition
This library is a Rust port of the Python ddddocr library, designed for offline local captcha recognition. It uses ONNX Runtime for inference and supports recognition of various captcha types including text and character-based captchas.
§Features
- Offline local recognition - no network calls required
- Support for various captcha types
- Based on deep learning models trained on synthetic data
- Simple API with minimal dependencies
- Async inference support
§Quick Start
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(())
}§Error Handling
The library uses a custom error type DdddOcrError for all operations:
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
}Structs§
- DdddOcr
- Main OCR struct for captcha recognition.
Enums§
- Dddd
OcrError - Error type for ddddocr operations.