這個LSD https://github.com/primetang/pylsd是封裝好的,不知道哪兒改參數,原始的LSD檢測前會將圖片縮小至80%,當圖片很小是,之後檢測的線會減少。
可以直接用opencv-python裏面的createLineSegmentDetector()函數,用help查看用法,再根據需要修改參數。我這邊選擇檢測前不縮放,那麼_scale=1
LSD代碼:
img = cv2.imread(imagepath, cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
lsd = cv2.createLineSegmentDetector(0, _scale=1)
dlines = lsd.detect(gray)
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(img, (x0, y0), (x1,y1), 255, 1, cv2.LINE_AA)
cv2.imwrite('./lines.png', img)
也參考opencv:cv::LineSegmentDetector Class Reference
https://docs.opencv.org/trunk/db/d73/classcv_1_1LineSegmentDetector.html