Skip to main content

Jigsaw Jeeves

A Python library that acts as a computer-vision assistant for solving jigsaw puzzles. Rather than solving the puzzle for you, it tells you where each piece most likely belongs, narrowing the search space to a small ranked candidate list so you can make progress when you are stuck.


Installation

pip install jigsaw-jeeves

Requires Python 3.12 or above.

Dependencies (opencv-python, numpy, scipy) are installed automatically.


Prerequisites

To use Jigsaw Jeeves you need two images:

  1. Reference image -- a photo of the puzzle box cover (the completed picture)
  2. Scrambled image -- a photo of the puzzle pieces arranged face-up in a neat rectangular grid on a flat, contrasting surface

Both images should be reasonably well-lit and photographed from roughly overhead. The grid dimensions you pass to solve() must match how you physically arranged the pieces before photographing.


Quick Start

from jigsaw_jeeves import solve

results = solve(
    reference_image_filepath="box_cover.jpg",
    scrambled_image_filepath="pieces_on_table.jpg",
    grid=(20, 25),       # rows x cols matching how you arranged the pieces
    top_k=3,             # number of candidate positions to return per piece
    save_to_file="solution.txt",  # optional: also write results to a file
)

# results maps each scrambled tile position to a ranked list of candidates.
for pos, candidates in results.items():
    best_dest, score = candidates[0]
    print(f"Piece at {pos} most likely belongs at {best_dest}  (similarity: {score:.3f})")

solve() -- full signature

solve(
    reference_image_filepath: str,
    scrambled_image_filepath: str,
    grid: tuple[int, int] | None = None,
    top_k: int = 3,
    save_to_file: str | None = None,
) -> dict

Parameters

Parameter Type Description
reference_image_filepath str Path to the puzzle box cover image (the solved reference).
scrambled_image_filepath str Path to a photograph of the scrambled pieces arranged face-up in a rectangle on a flat surface.
grid tuple[int, int] or None (rows, cols) matching the physical layout of pieces. If None, inferred automatically from the reference image dimensions (targeting tiles of ~150×150 px).
top_k int Number of candidate destination positions to return per tile (default 3).
save_to_file str or None If provided, results are written to this file path. The parent directory must exist. The dict is always returned regardless.

Returns

A dict mapping each scrambled tile position (row, col) to a ranked list of up to top_k candidate solved positions. Each list entry is ((dest_row, dest_col), cosine_similarity_score). The first entry is the globally optimal assignment (via the Hungarian algorithm); remaining entries are the next-best matches by cosine similarity.

Raises

ValueError with a human-friendly message if:

  • Either image path does not exist or cannot be opened
  • grid is not a 2-tuple of positive integers
  • top_k is not a positive integer
  • save_to_file's parent directory does not exist
  • Either image is entirely black after background suppression (insufficient contrast with background)

How It Works

  • The pipeline overlays an R-by-C grid on both images and treats each grid cell as the unit of comparison.
  • Each cell is represented as a 513-dimensional feature vector: a normalized 3-D RGB color histogram (512 values) and a single edge-density scalar.
  • Cosine similarity is used to measure how closely a scrambled tile matches each reference tile.
  • The Hungarian algorithm finds the globally optimal bijective assignment, guaranteeing that every scrambled tile is matched to a unique reference position.

License

MIT

Metadata

Release files for jigsaw-jeeves 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jigsaw-jeeves 0.0.2
File Size Uploaded
jigsaw_jeeves-0.0.2.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jigsaw-jeeves 0.0.2
File Interpreter ABI Platform
jigsaw_jeeves-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 20.8 kB

Release files / jigsaw_jeeves-0.0.2.tar.gz

Download URL jigsaw_jeeves-0.0.2.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
de93150a19dfbc90da9226f978c16f767505314688028f84c844b4982ec0fc7d
BLAKE2b-256 checksum
How to use checksums
30a951a7d7ac6d11e7dd47c1e93da14fc5584df3200063c68912d1899a16536e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.11

Release files / jigsaw_jeeves-0.0.2-py3-none-any.whl

Download URL jigsaw_jeeves-0.0.2-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee604cc9e7263813fd66ec6972695df3cd1f35b007c2b00e8a20861d4af81421
BLAKE2b-256 checksum
How to use checksums
7b81947ea8e1dff522dffb751f49bb5b6626d3eda437825715edf8e5b7578a44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.11

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page