Ask Your Question

Any implementation of LineSegmentDetector for python ?

asked 2019-07-17 01:57:57 -0500

ilas gravatar image

I see that cv2.createLineSegmentDetector implementation has been removed due original code license issues in function, any workarounds that don't include downgrading to an older version ?

Thanks a lot!

edit retag flag offensive close merge delete


Yes. cv2.createLineSegmentDetector is still there OpenCV 4.1.x. I am using OpenCV 4.1.1. Raspberry pi 4B, Buster Ver 10

supra56 gravatar imagesupra56 ( 2019-07-17 06:52:09 -0500 )edit

@ilas. Can you post ur code?

supra56 gravatar imagesupra56 ( 2019-07-17 06:53:11 -0500 )edit

I tried something very simple, just to give a first look :

img = cv2.imread("messigray.jpg",0)
lsd = cv2.createLineSegmentDetector(0)
lines = lsd.detect(img)[0] #Position 0 of the returned tuple are the detected lines
drawn_img = lsd.drawSegments(img,lines)
cv2.imshow("LSD",drawn_img )
ilas gravatar imageilas ( 2019-07-17 07:15:21 -0500 )edit

My apologized. You were right. My co-worker found problem.. implementation has been removed due original code license issues in function. It doesn't work on OpenCV 4.1.x. I then switched to OpenCV 3.X and it should work too.

supra56 gravatar imagesupra56 ( 2019-07-17 07:55:44 -0500 )edit

@ilas. I tried your code in OpenCV 3.x and it worked too.

supra56 gravatar imagesupra56 ( 2019-07-17 07:59:47 -0500 )edit

I see. Well, I wouldn't like to change versions cause I need the newest in other parts of the projet. Thank you anyway !

ilas gravatar imageilas ( 2019-07-17 08:06:17 -0500 )edit

I think you can use instead the Fast line detector. There is a sample.

Eduardo gravatar imageEduardo ( 2019-07-17 08:08:07 -0500 )edit

As Line Segment Detector has been removed due to license conflict, I suggest you all add a thumbs-up to this issue!
"Restore LineSegmentDetector LSD & avoid license conflict":

ruelj2 gravatar imageruelj2 ( 2020-05-09 14:29:17 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-12-22 08:50:23 -0500

supra56 gravatar image

updated 2019-12-22 08:51:42 -0500

ATTENTION: Fast Line Detector which is available in OpenCV 4.x.x.

import cv2
img = cv2.imread("box.jpg", 0)

fld = cv2.ximgproc.createFastLineDetector()
lines = fld.detect(img)

result_img = fld.drawSegments(img,lines)

cv2.imshow("Result",  result_img)
edit flag offensive delete link more


Note: it's available in OpenCV 3.4.x too.

lapis gravatar imagelapis ( 2020-01-13 04:41:56 -0500 )edit

Question Tools

1 follower


Asked: 2019-07-17 01:57:57 -0500

Seen: 4,969 times

Last updated: Dec 22 '19