gaps: 一种基于遗传算法的拼图求解器


Clone repo:

[code lang=bash]
$ git clone
$ cd gaps

Install requirements:

[code lang=bash]
$ pip install -r requirements.txt
$ sudo apt-get install python-tk

Install project in editable mode:

[code lang=bash]
$ pip install -e .

Creating puzzles from images

To create puzzle from image use create_puzzle script.


[code lang=bash]
$ create_puzzle images/pillars.jpg –size=48 –destination=puzzle.jpg

[SUCCESS] Puzzle created with 420 pieces


will create puzzle with 420 pieces from images/pillars.jpg where each piece is 48×48 pixels.

Run create_puzzle --help for detailed help.

NOTE Created puzzle dimensions may be smaller then original image depending on
given puzzle piece size. Maximum possible rectangle is cropped from original image.

Solving puzzles

In order to solve puzzles, use gaps script.


[code lang=bash]
$ gaps –image=puzzle.jpg –generations=20 –population=600

This will start genetic algorithm with initial population of 600 and 20 generations.

Following options are provided:

Option Description
--image Path to puzzle
--size Puzzle piece size in pixels
--generations Number of generations for genetic algorithm
--population Number of individuals in population
--verbose Show best solution after each generation
--save Save puzzle solution as image

Run gaps --help for detailed help.

Related posts

Leave a Comment