# ssocr-rs

A pure Rust port/implementation of the popular **Seven Segment Optical Character Recognition (ssocr)** CLI tool, originally developed by Erik Auerswal.

This project replicates the core logic and features of the original [ssocr C implementation](https://github.com/auerswal/ssocr), allowing you to perform OCR on seven-segment display images using a modern Rust toolchain without C/C++ dependencies (powered by the pure-Rust `image` library).

---

## Features

- **Port of `ssocr`**: Re-implements the segment-detection algorithms and image prep pipelines of the original C codebase.
- **Image Processing Commands**: Re-implements many CLI commands for pre-processing target images, including:
  - `dilation` / `erosion` / `opening` / `closing`
  - `remove_isolated` / `make_mono` / `grayscale` / `invert`
  - `gray_stretch` / `dynamic_threshold` / `rgb_threshold`
  - `white_border` / `shear` / `rotate` / `mirror` / `crop`
  - `set_pixels_filter` / `keep_pixels_filter`
- **Configurable OCR Engine**: Fine-tune detection using flags like `--threshold`, `--number-pixels`, `--min-segment`, `--number-digits`, `--one-ratio`, `--minus-ratio`, etc.
- **Flexible Charsets**: Support for different segment mappings:
  - `full` (standard seven-segment charset)
  - `digits` (0-9)
  - `decimal` (digits with decimal point and minus)
  - `hex` (hexadecimal characters)
  - `tt_robot` (table tennis robot characters)
- **Debugging & Visualization**: Output intermediate processed images (`--output-image`) or debug-mapped images (`--debug-image`).

---

## Installation

To build `ssocr-rs`, you need a working installation of Rust.

1. Clone the repository:
   ```bash
   git clone https://github.com/Youknow2509/ssocr-rs.git
   cd ssocr-rs
   ```

2. Build the project in release mode:
   ```bash
   cargo build --release
   ```

The compiled binary will be available at `./target/release/ssocr-rs`.

---

## Usage

```bash
ssocr-rs [OPTIONS]... [COMMANDS]... IMAGE
```

### Quick Example

To detect digits in an image of a seven-segment display:
```bash
./target/release/ssocr-rs -d 4 -t 45.0 test_image.png
```

To pre-process an image (e.g., crop, grayscale, invert, and run dynamic thresholding) before performing OCR:
```bash
./target/release/ssocr-rs crop 10 20 200 80 grayscale invert dynamic_threshold 7 7 -d 6 input.png
```

### Options

Use `--help` to view all command line options and instructions:
```bash
./target/release/ssocr-rs --help
```

---

## Acknowledgments

This tool is a Rust port of **ssocr** by Erik Auerswal. All credits for the underlying algorithms and logic go to the original author.
- Original Repository: [auerswal/ssocr](https://github.com/auerswal/ssocr)
- Original Author website: [Seven Segment Optical Character Recognition](https://www.unix-ag.uni-kl.de/~auerswal/ssocr/)

---

## License

This project is licensed under the same terms as the original `ssocr` package, under the GNU General Public License (GPL) version 3 or later. See `LICENSE` for details.

---

## Contact
- **Mail**: *lytranvinh.work@gmail.com*
- **Github**: *https://github.com/Youknow2509*
