如何使用OpenCV4';Python 3中的FastLineDetector是什么?
我试图在Python3中使用OpenCV4库中的FastLineDetector来检测图像中的线条和线段,但似乎没有办法让它工作。我已经阅读了这里的文档:对我来说仍然没有什么是清楚的。 我已经安装了OpenCV 4.1.0,并且正在Ubuntu 18.0.4中运行Python 3.6 下面是我分别尝试过的代码:如何使用OpenCV4';Python 3中的FastLineDetector是什么?,python,python-3.x,opencv,detection,segment,Python,Python 3.x,Opencv,Detection,Segment,我试图在Python3中使用OpenCV4库中的FastLineDetector来检测图像中的线条和线段,但似乎没有办法让它工作。我已经阅读了这里的文档:对我来说仍然没有什么是清楚的。 我已经安装了OpenCV 4.1.0,并且正在Ubuntu 18.0.4中运行Python 3.6 下面是我分别尝试过的代码: img=cv2.imread('/tmp/output0.png',cv2.CV_8UC1) fld=cv2.ximgproc\U FastLineDetector.detect(img
img=cv2.imread('/tmp/output0.png',cv2.CV_8UC1)
fld=cv2.ximgproc\U FastLineDetector.detect(img)
fld=cv2.ximgproc\u FastLineDetector.detect(cv2.ximgproc\u FastLineDetector(img))
飞行检测(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\u FastLineDetector.detect(img)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:描述符“detect”需要“cv2.ximgproc\u FastLineDetector”对象,但收到了“numpy.ndarray”
fld=cv2.ximgproc\u FastLineDetector.detect(cv2.ximgproc\u FastLineDetector(img))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:self的类型不正确(必须是“ximgproc\u FastLineDetector”或其衍生物)
是否有人知道如何使用FastLineDetector或有一个示例
顺便问一下,cv.ximgproc.createFastLineDetector()与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
如果使用
cv2.ximgproc\u FastLineDetector().detect(img)
,会怎么样?仍然不起作用。它向我显示了这个错误:cv2.ximgproc\u FastLineDetector().detect(img)回溯(最近一次调用):文件“”,第1行,在TypeError:error中不正确的自我类型(必须是“ximgproc\u FastLineDetector”或其派生版本)
对我有效,谢谢。对于那些不知道的人,您需要使用opencv contrib python来实现此代码,而不是opencv python。@Doğuş,如果您使用的是Anaconda,他们的默认包似乎包含contrib模块,因此您不需要特殊包。
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