First, let's take a look at the verification form of the target
It is a verification method through verification reasoning , It's really effective to prevent man-machine cracking , however ,But, There are already some flaws in this , such as :
① 200 Multiple copies Python e-book ( And classic books ) Should have
② Python Standard library information ( The most complete Chinese version )
③ Project source code ( Forty or fifty interesting and reliable hand training projects and source code )
④ Python Basic introduction 、 Reptiles 、 Network development 、 Big data analysis video ( Suitable for Xiaobai to learn )
⑤ Python Learning Roadmap ( Farewell to bad learning )
Python Exchange of learning Q Group 101677771
( The above is the result of the original drawing and binarization )
( This is a normal picture )
Places like red lines , You can see obvious mutations , And after binarization, the edge tends to be straight , But the normal image will not have such obvious mutation phenomenon .
later , I went to read the articles and papers related to machine vision , Found a powerful algorithm , This algorithm is ——Genetic Algorithm Genetic algorithm (ga) , The most intimate thing is , The author uses this algorithm to realize a function ,“ The puzzle is automatically restored ”( It's not like A* Algorithm to find the optimal route solution , It's a simple puzzle ) Project warehouse address
First of all, let's introduce how to use the running project , There are really many pits , Now feel pyCham Report mistakes all the way !
So here I'm going to use theta python3.10 Version of , It's the latest version
This step in the document will report an error
pip3 install -r requirements.txt
Solution : Alone requirements.txt Each package under the file is downloaded separately , Then replace the old version number according to the latest version of the currently downloaded package .
I currently use these version numbers for each package
After all the replacement , Execute the following code again , He won't report wrong
pip3 install -r requirements.txt
And then the next step , Execute the following code
pip3 install -e .
Then we follow the tips on the official website , First create a puzzle , This is the order ( I changed the file name here )
create_puzzle images/starry.jpg --size=60 --destination=puzzle.jpg
Will find , I don 't think I can , Because we didn't execute in the right place , His script is located in bin Under the folder , You may encounter the following problems
After success , Will be in bin Generate a puzzle picture under the directory
The above is how to generate pictures , Next is the play , How to restore pictures
gaps --image=puzzle.jpg --generations=20 --population=600
For the interpretation of parameters, the official website is like this :
Option
: --image Path to puzzle( Pictures that need to be restored )
--size Puzzle piece size in pixels ( The size of the puzzle )
--generations Number of generations for genetic algorithm ( Algebra of genetic algorithm )
--population Number of individuals in population
--verbose Show best solution after each generation ( Show the best solution after each generation )
--save Save puzzle solution as image ( Save the puzzle result as an image )
Let's go through it according to the official
very good , Very comfortable , Continue to report mistakes , And we haven't misspelled in grammar and spelling , No problem ! I've helped you find a solution .
python gaps --image=puzzle.jpg --generations=20 --population=600 --size=60 --save
Or you don't specify genetic algebra and population
python gaps --image=puzzle.jpg --size=60 --save
This is the result of complete restoration , thus , We cut through difficulties to report mistakes from solving the project , Dig and fill all the way to demo Running successfully , Here we have made it 60%, The next step is how to use this project , To crack Netease's reasoning puzzle verification .
First look at the project directory :
gaps Below the folder is the source code of all modules , The author encapsulates the basic functions , But the function we want doesn't exist , You need to read and understand the source code by yourself , Then the second switch realizes the function you want .
We mainly focus on this document individual.py:
Let me translate it for you in vernacular ,“ In all permutations , Help you find the optimal solution ”
Output this mapping , It turns out like this , Just what we want
Here's a way to create an image , This is the image mosaic function that finally obtains the optimal solution
that , We map the final index to OK 了 !
The following is an example of the mapping value output of the optimal solution :
When initializing , Add a variable to store the final result
self.pieceMapping = None
Customize a function
# Return the mapping value def getPieceMapping(self): return self.pieceMapping
Every time it's executed , Pass the optimal solution out
def to_image(self): """Converts individual to showable image""" pieces = [piece.image for piece in self.pieces] self.pieceMapping = self._piece_mapping return image_helpers.assemble_image(pieces, self.rows, self.columns)
above , Just output the results we want
call :
key Mark the final result ,value Is the original logo .
PS: For extremely complex puzzles created from original images , After restore , The error will be big .