


In my first attempt I used the Hough Transform to find the main lines of the puzzle piece and tried to cluster them into 4 different subsets (one for each side).
PIXEL PUZZLE SOLVER HOW TO
This is the most critical part since all the following steps will work perfectly if the corners are correct.ĭuring the first step I found an approximate location of the corners, while in section 4 I’ll explain how to refine the corner detections in order to obtain the exact locations. In order to separate each side of a puzzle piece, we need to correctly find the 4 main corners of the puzzle piece. Puzzle piece segmentation and post-processing 3. Here’s an example of the output image from this phase: Finally I further crop the piece into a square image that allows for piece rotations without losing part of it. Once obtained the thresholded image, I clear potential false positives areas (background pixels marked as puzzle piece pixels) by using the cv2.connectedComponents OpenCV function and taking the connected component with the maximum area (i.e. The binarized image is then smoothed using a mean filter: gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.medianBlur(gray, ksize=5) thresh = cv2.threshold(gray, 130, 255, cv2.THRESH_BINARY) thresh = cv2.blur(thresh, ksize=(3, 3)) Before applying the binarization, a median filter is applied to the grayscale image in order to remove white noise on the puzzle piece. Since both light conditions and piece color don’t change inside the dataset, segmentation is achieved using simple binary thresholding. Example of picture of puzzle piece and cropping 2.
