首次运行会自动下载模型到 ~/.cache/ocrs,需联网;目前仅识别拉丁字母(如英文),其他语言尚未支持;项目处于早期预览,错误率可能高于商业 OCR 引擎。
ocrs
robertknightApache-2.0活跃维护用 Rust 写的 OCR 库和命令行工具,能从图片中提取文字,适合需要轻量、可嵌入的光学字符识别能力的场景。
Rust library and CLI tool for OCR (extracting text from images)
cargo install ocrs-cli --lockedREADME 未说明显存或 GPU 要求;模型通过 RTen 引擎执行,但 README 未列出支持的 GPU 厂商或型号。
Rust 写的 OCR 库和命令行工具,用 ONNX 神经网络模型从图片里提取文字
用 Rust 写的 OCR 库和命令行工具,能从图片中提取文字,适合需要轻量、可嵌入的光学字符识别能力的场景。
核心能力
- 用 PyTorch 训练、导出 ONNX 模型,经 RTen 引擎推理
- 减少预处理依赖,覆盖扫描件、照片、截图等图片
- 提供 CLI,可直接对图片文件或系统剪贴板做 OCR
- 支持输出纯文本、JSON 布局信息或标注后的 PNG
- 可编译到 WebAssembly,代码库便于理解和修改
容易踩的坑
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Ocrs
ocrs is a Rust library and CLI tool for extracting text from images, also known as OCR (Optical Character Recognition).
The goal is to create a modern OCR engine that:
- Works well on a wide variety of images (scanned documents, photos containing text, screenshots etc.) with zero or much less preprocessing effort compared to earlier engines like Tesseract. This is achieved by using machine learning more extensively in the pipeline.
- Is easy to compile and run across a variety of platforms, including WebAssembly
- Is trained on open and liberally licensed datasets
- Has a codebase that is easy to understand and modify
Under the hood, the library uses neural network models trained in PyTorch, which are then exported to ONNX and executed using the RTen engine. See the models section for more details.
Status
ocrs is currently in an early preview. Expect more errors than commercial OCR engines.
Language Support
ocrs currently recognizes the Latin alphabet only (eg. English). Support for more languages is planned.
CLI installation
To install the CLI tool, you will first need Rust and Cargo installed. Then run:
$ cargo install ocrs-cli --locked
To enable support for reading images from the system clipboard, add the
clipboard feature:
$ cargo install ocrs-cli --locked --features clipboard
CLI usage
To extract text from an image, run:
$ ocrs image.png
When the tool is run for the first time, it will download the required models
automatically and store them in ~/.cache/ocrs.
If ocrs was installed with the clipboard feature, you can extract text from
an image on the system clipboard with:
$ ocrs --clipboard
$ ocrs -c # Short form
Additional examples
Extract text from an image and write to content.txt:
$ ocrs image.png -o content.txt
Extract text and layout information from the image in JSON format:
$ ocrs image.png --json -o content.json
Annotate an image to show the location of detected words and lines:
$ ocrs image.png --png -o annotated.png
Library usage
See the ocrs crate README for details on how to use ocrs as a Rust library.
Models and datasets
ocrs uses neural network models written in PyTorch. See the ocrs-models repository for more details about the models and datasets, as well as tools for training custom models.
Development
To build and run the ocrs library and CLI tool locally you will need a recent stable Rust version installed. Then run:
git clone https://github.com/robertknight/ocrs.git
cd ocrs
cargo run -p ocrs-cli -r -- image.png
Common development tasks are defined as recipes in the justfile and run with
just. Run just --list to see them all.
Testing
Ocrs has unit tests for the code that runs before and after ML model processing, plus E2E tests which exercise the whole pipeline, including models.
After making changes to the code, run unit tests and lint checks with:
just check
You can also run standard commands like cargo test directly.
Run the E2E tests with:
just test-e2e
For details of how the ML models are evaluated, see the ocrs-models repository.