Python Opencv结构化森林边缘检测TypeError

时间:2019-02-28 14:47:47

标签: python opencv edge-detection

如下所示,当我在Python中调用OpenCV结构化森林边缘检测时,出现错误:

import numpy as np
import cv2

img = cv2.imread('2009_005193.jpg')
gray_img = np.asarray(img.mean(axis=2) / 255, np.float32)
out = cv2.ximgproc_StructuredEdgeDetection.detectEdges(gray_img)

我得到的错误是:

Traceback (most recent call last):
  File "gop1.py", line 19, in <module>
    out = cv2.ximgproc_StructuredEdgeDetection.detectEdges(gray_img)
TypeError: descriptor 'detectEdges' requires a 'cv2.ximgproc_StructuredEdgeDetection' object but received a 'numpy.ndarray'

在文档(link to documentation)中,它作为功能detectEdges()存在于ximgproc_StructuredEdgeDetection下。

1 个答案:

答案 0 :(得分:0)

与文档中一样,它将需要3通道float 32图像。也许您需要首先创建StructuredEdgeDetection对象。 但是,这对我有用:

imgrgb=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)/255
imgrgb=imgrgb.astype(np.float32)
model='structured edge/model.yml'
retval=cv2.ximgproc.createStructuredEdgeDetection(model)
out=retval.detectEdges(imgrgb)