I find it difficult to find the lines on the chessboard in this image using HoughLinesP with OpenCV in Python.
In an attempt to understand the parameters of HoughLinesP, I got the following code:
import numpy as np import cv2 from matplotlib import pyplot as plt from matplotlib import image as image I = image.imread('chess.jpg') G = cv2.cvtColor(I, cv2.COLOR_BGR2GRAY) # Canny Edge Detection: Threshold1 = 150; Threshold2 = 350; FilterSize = 5 E = cv2.Canny(G, Threshold1, Threshold2, FilterSize) Rres = 1 Thetares = 1*np.pi/180 Threshold = 1 minLineLength = 1 maxLineGap = 100 lines = cv2.HoughLinesP(E,Rres,Thetares,Threshold,minLineLength,maxLineGap) N = lines.shape[0] for i in range(N): x1 = lines[i][0][0] y1 = lines[i][0][1] x2 = lines[i][0][2] y2 = lines[i][0][3] cv2.line(I,(x1,y1),(x2,y2),(255,0,0),2) plt.figure(),plt.imshow(I),plt.title('Hough Lines'),plt.axis('off') plt.show()
The problem I am facing is that it raises only one line. If I reduce maxLineGap to 1, it will take thousands.
I understand why this may be, but how to choose the appropriate set of parameters to combine all these line lines? Did I miss something?
I would like to keep the code simple, as I use it as an example of this function in action.
Thanks in advance for your help!
Update: This works great with HoughLines.
And it seems that there are no problems with border detection, since Canny is working fine.
However, I still need to get HoughLinesP to work. Any ideas?
Images here: Results