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 used findContours and drawContours functions:
im_gray = cv2.imread('redLines.png', cv2.IMREAD_GRAYSCALE)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2))
morphed = cv2.dilate(im_gray, kernel, iterations=1)
(ret, thresh) = cv2.threshold(morphed, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(thresh, contours, -1, (255, 255, 255), 3)
And it worked well, the last imshow looks something like this:
Now, I'm trying to detect each square in the grid and save its points in a unique index in a vector.
I know I can do it using the contours array. But when I print the length of the contours it keeps changing rapidly, from size 2 up to 112..
So I guess it's not recognizing the grids well.
Any help would be appreciated.


