2 releases
0.1.3 | Oct 29, 2024 |
---|---|
0.1.2 | Oct 29, 2024 |
0.1.1 |
|
0.1.0 |
|
#580 in Text processing
375 downloads per month
19KB
301 lines
advent-ocr
A Rust function to convert ASCII-art representations of letters generated by Advent of Code puzzles into a String containing those letters. Through 2023, these puzzles are:
- 2016, Day 8
- 2018, Day 10
- 2019, Days 8 and 11
- 2011, Day 13
- 2022, Day 10
Installation
Add this to your Cargo.toml file:
[dependencies]
advent-ocr = "0.1.3"
Usage
There is one function, ocr()
, that takes one argument, image
.
image
can take the following types:
&str
(&Vec<bool>, usize)
, a tuple consisting of a Vec of bools and the width of a line.(&Vec<bool>, usize)
, a tuple consisting of a Vec of chars and the width of a line.&Vec<Vec<bool>>
, a Vec of a Vec of bools.&Vec<Vec<char>>
, a Vec of a Vec of chars.
For &str and the char-based Vecs, '#' is considered part of a letter and all other chars are considered blank space. For the bool-based Vecs, true
is considered part of a letter and false
is considered blank space.
use advent_ocr::ocr
let image = r"
.##..###...##.
#..#.#..#.#..#
#..#.###..#...
####.#..#.#...
#..#.#..#.#..#
#..#.###...##.
";
let s = ocr(image);
println!("{s}"); // prints "ABC"
Warning/Credits
This library recognizes the two font sizes used in Advent of Code puzzles, but neither font alphabet is complete. This draws on the efforts of mstksg and possibly others. If the function does not recognize a letter, send me a message with the image that failed to render, and I will add it!
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.