A Rust binding for OneOCR, the OCR engine embedded in the Windows 11 Snipping Tool app ✂️.
This crate allows you to leverage the powerful OCR capabilities of the Windows 11 Snipping Tool within your Rust applications. It provides a simple and efficient way to perform OCR on images, extract text, and obtain bounding boxes for lines and words.
- 🖼️ Perform OCR on images offline.
 - 📏 Get bounding boxes for lines and words.
 - 💯 Get confidence scores for words.
 - 📐 Get image angle.
 - ✍️ Distinguish between handwritten and printed text.
 - ⚙️ Configure OCR options (e.g., max line count, resize resolution).
 
- 💻 Windows 11 (not tested on Windows 10, as it may not work).
 - 📄 The 
oneocr.dll,oneocr.onemodel, andonnxruntime.dllfiles must be present in the same directory as your executable. These files are part of the Snipping Tool app. You can find its installation location by running the following PowerShell command. After locating the folder, copy these three files into your project's target directory (e.g.,target/debugortarget/release) or alongside your final executable. 
Get-AppxPackage Microsoft.ScreenSketch | Select-Object -ExpandProperty InstallLocationExample output:
C:\Program Files\WindowsApps\Microsoft.ScreenSketch_11.2504.38.0_x64__8wekyb3d8bbwe
Add this to your Cargo.toml:
[dependencies]
oneocr-rs = "0.3.1" # Replace with the latest versionuse oneocr_rs::{OcrEngine, OneOcrError};
use std::path::Path;
fn main() -> Result<(), OneOcrError> {
    // Create a new OCR engine instance
    let ocr_engine = OcrEngine::new()?;
    // Set the path of the image
    let image_path = Path::new("screenshot.png");
    // Perform OCR on the image
    let ocr_result = ocr_engine.run(image_path.into())?;
    // Print the OCR lines and their bounding boxes
    for line in &ocr_result.lines {
        println!("Text: {}, Bounding Box: {}", line.text, line.bounding_box);
    }
    Ok(())
}See the examples directory for more detailed usage examples.
Drawing bounding boxes around the detected lines and words in an image.
See CHANGELOG.md for a detailed history of changes and releases.
Contributions are welcome! Please feel free to submit a pull request or open an issue if you have suggestions or find bugs.
This project is based on the excellent work done by b1tg in the b1tg/win11-oneocr repository. Their efforts in reverse-engineering and understanding the OneOCR interface made this Rust binding possible.
This project is licensed under the MIT License. See the LICENSE file for details.
