mygugl.blogg.se

Pixel puzzle solver
Pixel puzzle solver












pixel puzzle solver

  • Compute the intersections between the four mean lines to finally obtain the 4 piece corners.īlue lines are all the hough lines after the pruning phase.
  • Compute the mean line for each cluster.
  • Clustering the lines with KMeans: we can group all lines into 4 different clusters, one for each side of the piece, based on their coefficients.
  • Remove unwanted lines by estimating the piece orientation: since we expect the four lines passing through the four piece corners to form a rectangle, I grouped together lines with the same orientation in order to prune lines that do not belong to this group.
  • For each line returned by this function, we get its coefficients in parametric form.
  • Apply the Hough Transform for line detection: cv2.HoughLines.
  • Perform edge detection on the binarized image by applying the cv2.Canny function.
  • Here I’ll explain briefly the algorithm steps:

    pixel puzzle solver

    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.














    Pixel puzzle solver