Python Opencv结构化森林边缘检测TypeError
Python Opencv Structured Forests Edge Detection TypeError
当我如下所示在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 下。
如文档中所述,它需要 3 通道浮点 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)
当我如下所示在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 下。
如文档中所述,它需要 3 通道浮点 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)