如何在python3中使用OpenCV4的FastLineDetector?

2024-09-30 14:21:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用python3中OpenCV4库中的FastLineDetector来检测图像中的直线和线段,但似乎没有办法使其工作。我已经阅读了这里的文档:https://docs.opencv.org/3.4/df/d4c/classcv_1_1ximgproc_1_1FastLineDetector.html对我来说仍然没有什么是清楚的。 我已经安装了opencv4.1.0,并在ubuntu18.0.4中运行python3.6。在

以下是我分别尝试过的代码:

img = cv2.imread('/tmp/output0.png', cv2.CV_8UC1)
fld = cv2.ximgproc_FastLineDetector.detect(img)
^{pr2}$

以下是输出错误:

fld = cv2.ximgproc_FastLineDetector.detect(img)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: descriptor 'detect' requires a 'cv2.ximgproc_FastLineDetector' object but received a 'numpy.ndarray'
fld = cv2.ximgproc_FastLineDetector.detect(cv2.ximgproc_FastLineDetector(img))
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: Incorrect type of self (must be 'ximgproc_FastLineDetector' or its derivative)

有人知道如何使用FastLineDetector或有一个例子吗?在

顺便问一下,和cv.ximgproc.createFastLineDetector() ? 在


Tags: inmostimginputlinecallcv2file
1条回答
网友
1楼 · 发布于 2024-09-30 14:21:59

给你

def FLD(image):
    # Create default Fast Line Detector class
    fld = cv2.ximgproc.createFastLineDetector()
    # Get line vectors from the image
    lines = fld.detect(image)
    # Draw lines on the image
    line_on_image = fld.drawSegments(image, lines)
    # Plot
    plt.imshow(line_on_image, interpolation='nearest', aspect='auto')
    plt.show()
    return line_on_image

相关问题 更多 >