Open lix19937 opened 5 months ago
lsd
# coding=utf-8
import cv2
import numpy as np
img0 = cv2.imread("test3.jpg")
img = cv2.cvtColor(img0,cv2.COLOR_BGR2GRAY)
lsd = cv2.createLineSegmentDetector(0)
dlines = lsd.detect(img)
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(img0, (x0, y0), (x1,y1), (0,255,0), 1, cv2.LINE_AA)
cv2.imwrite('test3_r.jpg', img0)
cv2.imshow("LSD", img0)
cv2.waitKey(0)
cv2.destroyAllWindows()
fsd
# coding=utf-8
import cv2
import numpy as np
img0 = cv2.imread("test3.jpg")
img = cv2.cvtColor(img0,cv2.COLOR_BGR2GRAY)
fld = cv2.ximgproc.createFastLineDetector()
dlines = fld.detect(img)
for dline in dlines:
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(img0, (x0, y0), (x1,y1), (0,255,0), 1, cv2.LINE_AA)
cv2.imwrite('test3_r.jpg', img0)
cv2.imshow("LSD", img0)
cv2.waitKey(0)
cv2.destroyAllWindows()
在opencv 4.2.0.34版本下调用 lsd = cv2.createLineSegmentDetector(0) 运行报错
报源码许可证问题而删除了实现
在opencv contrib扩展中的ximgproc模块中给出了一个LineSegmentDetector类,来替代LSD算法。
该算法来自于2014年ICRA的一篇论文《Outdoor place recognition in urban environments using straight lines》
ref https://blog.csdn.net/Zhaoxi_Li/article/details/106844821