'Chessboard cropping squares by contours array OpenCV

I detected a chessboard using OpenCV in python using:

  • Computing the edge of the image
  • Computing the Hough transform
  • Finding the local maxima of Hough transform
  • Extracting the image lines

Then I found the contours, then detected only the valid contours of the chessboard And saved them in a NumPy array, for example when I run the following code:

    for c in valid_cnts:
      if i < 9:
        cv2.drawContours(orig,[c] , -1, (255, 255, 255), -1)
      i+=1

The imshow function shows this image:

enter image description here

From this valid numpy Array contours I would like to have the ability to get pictures like this: (I drew it myself, not so accurate sorry)

I would like to have the ability to crop the noise around each grid, so I can recognize the pieces I would put on later.

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source