适当的 houghlines 参数化有问题吗?

Trouble with appropriate houghlines parametrization?

我试图在我的图中识别一组线,但我无法确定我应该为霍夫变换选择哪些合适的参数。

img = 255 - cv2.imread('isolate.png', 0)
blank = np.zeros(img.shape) + 255
dilation = cv2.dilate(img, np.ones((2,2)), iterations = 1)
processed = cv2.bitwise_not(dilation)
cv2.imwrite('lol.png', processed)
# cv2.imwrite('process.png',dilation)
lines = cv2.HoughLinesP(processed,rho = 1,theta = 1*np.pi/180,threshold = 100,minLineLength = 180,maxLineGap = 1)
for line in lines:
    # import pdb; pdb.set_trace()
    x1, y1, x2, y2 = line[0]
    cv2.line(processed, (x1, y1), (x2, y2), (255, 0, 0), 1)
cv2.imwrite("result.png", processed)

传入 HoughLinesP 的图像如下所示 - 我绘制后得到的图像是这样的 -

看完图片不要反转:

img = cv2.imread(test_image_filepath, cv2.IMREAD_GRAYSCALE)

但反转 processed。由于源图像是灰度图像,您必须先将图像转换为 BGR,然后再在图像上绘制蓝线:

processed = cv2.cvtColor(255-processed, cv2.COLOR_GRAY2BGR)

总计:

img = cv2.imread('isolate.png', cv2.IMREAD_GRAYSCALE)

dilation = cv2.dilate(img, np.ones((2,2)), iterations = 1)
processed = cv2.bitwise_not(dilation)

lines = cv2.HoughLinesP(processed,
    rho = 1,theta = 1*np.pi/180,threshold = 100,minLineLength = 180,maxLineGap = 1)

processed = cv2.cvtColor(255-processed, cv2.COLOR_GRAY2BGR)
for line in lines:
    x1, y1, x2, y2 = line[0]
    cv2.line(processed, (x1, y1), (x2, y2), (255, 0, 0), 1)