如何在Python 3中使用OpenCV4的FastLineDetector?

How to use OpenCV4's FastLineDetector in Python 3?

我正在尝试使用 Python 3 中 OpenCV4 库中的 FastLineDetector 来检测图像中的线条和线段,但似乎无法使其工作。我已经阅读了此处的文档:https://docs.opencv.org/3.4/df/d4c/classcv_1_1ximgproc_1_1FastLineDetector.html 对我来说似乎还不清楚。 我已经安装了 OpenCV 4.1.0,我是 运行 Python 3.6 in Ubuntu 18.0.4.

这是我单独尝试过的代码:

img = cv2.imread('/tmp/output0.png', cv2.CV_8UC1)
fld = cv2.ximgproc_FastLineDetector.detect(img)
fld = cv2.ximgproc_FastLineDetector.detect(cv2.ximgproc_FastLineDetector(img))
fld.detect(img)

这是输出错误:

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() 有什么区别吗?

给你

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