use*_*684 7 python-2.7 opencv3.0
是否可以提供示例实现代码或指针来实现具有opencv 3.0和python的LSD?HoughLines和HoughLinesP没有在python中给出期望的结果,并且想要在python中测试LSD但是没有得到任何地方.
我试图做以下事情:
LSD=cv2.createLineSegmentDetector(0)
lines_std=LSD.detect(mixChl)
LSD.drawSegments(mask,lines_std)
但是,当我在掩码上绘制线条时,我得到一个错误,即:LSD.drawSegments(mask,lines_std)TypeError:lines不是数字元组
有人可以帮我这个吗?提前致谢.
Fla*_*ayn 11
您可以像这样使用cv2.drawSegments函数:
#Read gray image
img = cv2.imread("test.png",0)
#Create default parametrization LSD
lsd = cv2.createLineSegmentDetector(0)
#Detect lines in the image
lines = lsd.detect(img)[0] #Position 0 of the returned tuple are the detected lines
#Draw detected lines in the image
drawn_img = lsd.drawSegments(img,lines)
#Show image
cv2.imshow("LSD",drawn_img )
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
您可以查看OpenCV 文档.
小智 6
我能够使用以下内容在 OpenCV 3.2.0 中绘制线条:
lsd = cv2.createLineSegmentDetector(0)
dlines = lsd.detect(gray_image)
for dline in dlines[0]:
x0 = int(round(dline[0][0]))
y0 = int(round(dline[0][1]))
x1 = int(round(dline[0][2]))
y1 = int(round(dline[0][3]))
cv2.line(mask, (x0, y0), (x1,y1), 255, 1, cv2.LINE_AA)
Run Code Online (Sandbox Code Playgroud)
我不确定为什么所有额外的 [0] 间接,但这似乎是提取坐标所需要的。
当打开 OpenCV 返回时,我发现在控制台上打印东西很有帮助。在这种情况下,我做了
print(dlines)
Run Code Online (Sandbox Code Playgroud)
从所有嵌套的方括号中,我经常可以找到解决方案,而不必过多担心这一切的原因和原因。
我以前使用过从作者的源代码编译并使用 ctypes 调用的 LSD 的 Windows DLL 版本。