Advent of Code ASCII-art character recognition
Project description
aococr
OCR tool in python for Advent of Code (AoC) ASCII art.
Som AoC puzzles produce a result which uses values '#', and '.' to mimic pixels turned on/off in a display, like below:
.##..###...##.
#..#.#..#.#..#
#..#.###..#...
####.#..#.#...
#..#.#..#.#..#
#..#.###...##.
Converting the above string into the string 'ABC' is a task which, unaccaptably, requires a human to think and type for a few seconds.
This package exposes functionality to automatically parse ASCII art-like displays like the above into strings. It can be called in two ways in python, via the aococr
method, or via the aoc-ocr
command-line tool.
Variations like fontsize of the ASCII glyphs and handling other characters than "#" / "." Should™ be handled automatically. If not, see the aococr
docstring.
Installation
pip install aococr
Usage
Can be used in a python script, or from the command line
In python:
from aococr import aococr
display_string = """
.##..###...##.
#..#.#..#.#..#
#..#.###..#...
####.#..#.#...
#..#.#..#.#..#
#..#.###...##.
"""
s = aococr(display_string)
print(s) # prints "ABC"
The aococr
method accepts several data types:
- list of lists of characters
- strings, which are stripped of trailing/leading whitespace and converted into lists of lists
- numpy-arrays of characters (though numpy is not a dependency)
A helper method for displaying ASCII art on a terminal can also be imported using from aococr import display
. It takes any of the formats listed above, replaces '.'
with ' '
to increase readability, and prints it.
From command line
The aoc-ocr
CLI tool reads from stdin and writes its result to stdout, so it can be run on e.g. ascii art in a text file, or by piping the output from another script directly like:
aoc-ocr < some_file.txt
# or
python solve_day_xx.py | aoc-ocr
Credit
The ASCII-glyphs come from mstksg's advent-of-code-ocr Haskell library, which lists contributions to collecting the fonts to Reddit users u/usbpc102, u/TheShallowOne, and @gilgamec.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aococr-1.0.0.tar.gz
.
File metadata
- Download URL: aococr-1.0.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-47-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 968367d701e8ff3afdcb97c8f84df3e95ac675e1897c425da19dcf7fe2dbf6c6 |
|
MD5 | 6b73e6143b199d9b70631142081cc8e3 |
|
BLAKE2b-256 | 5939149f0579be702d7df95fcfd4d092a8d6507ab14a01884c747e071b7b00c8 |
File details
Details for the file aococr-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: aococr-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-47-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40124ac207cf79ff49df2861c3bbc1defae7648d3273b73176f859c572e0ba52 |
|
MD5 | f81850bc53731077fbb9c3fa91dba8c7 |
|
BLAKE2b-256 | 69a28cc7b214a128705ef9d23143873da8746884fd3d951a38a5af5f18ed60e0 |