Skip to content

Image processing package to parse Codenames board game (color map and word cards)

Notifications You must be signed in to change notification settings

asaf-kali/codenames-parser

Repository files navigation

Codenames Parser

PyPI version Pipeline codecov Ruff Code style: black Imports: isort Type checked: mypy Linting: pylint

A Python package to parse Codenames game boards from images.
Before we dive in, here are some examples:

Color map extraction

Given color_map.png:

Running:

python -m codenames_parser/color_map/entrypoint.py color_map.png classic

Outputs:

Some parsing logs...

# As emoji table
⬜ 🟥 🟦 🟦 🟥
⬜ 🟦 🟥 ⬜ 🟦
🟦 🟥 🟥 🟦 ⬜
🟦 🟥 🟥 ⬜ ⬜
⬜ 🟦 💀 🟥 🟦

# As list
['NEUTRAL', 'RED', 'BLUE', 'BLUE', 'RED', 'NEUTRAL', 'BLUE', 'RED', 'NEUTRAL', 'BLUE', 'BLUE', 'RED', 'RED', 'BLUE', 'NEUTRAL', 'BLUE', 'RED', 'RED', 'NEUTRAL', 'NEUTRAL', 'NEUTRAL', 'BLUE', 'ASSASSIN', 'RED', 'BLUE']

Board extraction

"Life is not perfect, neither is OCR" (credit: Github Copilot)

Given board.png:

Running:

python -m codenames_parser/board/entrypoint.py board.png heb

Outputs:

Some parsing logs...

# As table
+-------+---------+-------+-------+------+
| ציבור | אוטובוס | ישראל |  מתח  |  גס  |
+-------+---------+-------+-------+------+
| ברית  |   גוש   | איום  | מורח  | קנה  |
+-------+---------+-------+-------+------+
| לידה  |  מבחן   | אודם  | שוקו  | חטיף |
+-------+---------+-------+-------+------+
|  חוק  |   רץ    | חצות  | רדיו  | כתם  |
+-------+---------+-------+-------+------+
|  גרם  |   כהן   | רושם  | אלמוג |      |
+-------+---------+-------+-------+------+

# As list
[
    "ציבור",    "אוטובוס",    "ישראל",    "מתח",    "גס",
    "ברית",    "גוש",    "איום",    "מורח",    "קנה",
    "לידה",    "מבחן",    "אודם",    "שוקו",    "חטיף",
    "חוק",    "רץ",    "חצות",    "רדיו",    "כתם",
    "גרם",    "כהן",    "רושם",    "אלמוג",     "",
]

* It looks as if the direction of the board is flipped. This is a bug due to Hebrew being written from right to left, the list order is correct.

Installation

pip install codenames-parser

OCR

  1. Uses pytesseract to extract text from images.
  2. Requires tesseract to be installed on the system ( see installing-tesseract).
  3. Download more languages from: https://github.com/tesseract-ocr/tessdata