Skip to content
/ ocrs Public
forked from robertknight/ocrs

A modern OCR engine (extracts text from images), written in Rust

License

Notifications You must be signed in to change notification settings

but-io/ocrs

 
 

Repository files navigation

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.

CLI installation

To install the CLI tool, you will first need Rust and Cargo installed. Then run:

$ cargo install ocrs-cli

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.

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

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. These models are also available in ONNX format for use with other machine learning runtimes.

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

Library installation

See the ocrs crate README for details on how to use ocrs as a Rust library.

About

A modern OCR engine (extracts text from images), written in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 70.9%
  • TypeScript 25.0%
  • JavaScript 2.2%
  • Other 1.9%