Crates.io | advent-ocr |
lib.rs | advent-ocr |
version | 0.1.3 |
source | src |
created_at | 2024-10-29 01:24:54.446665 |
updated_at | 2024-10-29 21:40:21.79373 |
description | Converts ASCII-art representations of letters generated by Advent of Code puzzles into a String containing those letters. |
homepage | |
repository | https://github.com/nbanman/advent-ocr |
max_upload_size | |
id | 1426264 |
size | 19,851 |
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:
Add this to your Cargo.toml file:
[dependencies]
advent-ocr = "0.1.3"
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"
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!
Licensed under either of
at your option.