Python Opencv结构化森林边缘检测类型

2024-06-14 18:13:48 发布

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

当我在Python中调用OpenCV Structured Forests Edge Detection时,出现了一个错误:

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)

我得到的错误是:

^{pr2}$

在文档(link to documentation)中,它作为函数detectEdges()出现在ximgproc_structuredgedetection下。在


Tags: importnumpyimgas错误npcv2opencv
1条回答
网友
1楼 · 发布于 2024-06-14 18:13:48

在文档中,它将需要3通道浮点32图像。也许您需要先创建structuredgedetection对象。 然而,这对我很有效:

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)

相关问题 更多 >