Nasim
Nasim

Reputation: 169

using opencv LineSegmentDetector to find line of an image

i have a color image and i should use opencv LineSegmentDetector algorithm to detect lines of the rectangles in the image

Here is my image:enter image description here

i'm using this code :

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

#Create default parametrization LSD
lsd = cv2.createLineSegmentDetector(0)

#Detect lines in the image
lines = lsd.detect(img)[0] 

#Draw detected lines in the image
drawn_img = lsd.drawSegments(img,lines)

#Show image
cv2.imshow("LSD",drawn_img )
cv2.waitKey(0)

and i'm getting this errpr:

<ipython-input-18-93ae667b0648> in <module>()
      3 
      4 #Create default parametrization LSD
----> 5 lsd = cv2.createLineSegmentDetector(0)
      6 
      7 #Detect lines in the image

error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\lsd.cpp:143: error: (-213:The function/feature is not implemented) Implementation has been removed due original code license issues in function 'cv::LineSegmentDetectorImpl::LineSegmentDetectorImpl'

i checked open-cv version 4.1 documentation to use this method and here is the page , but i dont understand how should i use this method.

any help is appreciated.

Upvotes: 0

Views: 5083

Answers (2)

epistemophiliac
epistemophiliac

Reputation: 869

You can also use Fast Line Detector which is available in OpenCV 4.1.

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

#Create default Fast Line Detector (FSD)
fld = cv2.ximgproc.createFastLineDetector()

#Detect lines in the image
lines = fld.detect(img)

#Draw detected lines in the image
drawn_img = fld.drawSegments(img,lines)

#Show image
cv2.imshow("FLD", drawn_img)
cv2.waitKey(0)

Result: Outlined Shaped

Upvotes: 3

AKX
AKX

Reputation: 169388

Did you read the error message?

error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\lsd.cpp:143: error: (-213:The function/feature is not implemented)
Implementation has been removed due original code license issues in function 'cv::LineSegmentDetectorImpl::LineSegmentDetectorImpl'

The class is not available due to license issues.

You can see that here in the original source.

Upvotes: 2

Related Questions