EmguCV-Canny函数抛出_src.depth()== CV_8U

问题描述 投票:0回答:1

我目前正在使用EmguCV 4.2的项目中工作

我需要使用Canny函数:

gray=gray.Canny(50, 200);

并且抛出错误:

 _src.depth()==CV_8U

我注意到,仅当我之前在图像上使用CvInvoke.Threshold()时,才会发生异常

CvInvoke.Threshold(skeleton,img,0,255,Emgu.CV.CvEnum.ThresholdType.Binary);

我想知道为什么会这样,如果没有Threshold()函数,一切正常。此功能会以某种方式改变我图像的深度吗?如何将其转换回使用Canny()函数而没有问题?

提前感谢。

c# exception emgucv threshold
1个回答
0
投票

根据我从您的问题中得到的信息,可能是图像转换为灰度时出现问题。

下面的错误代码是指图像的深度类型,即,图像的每个像素内可以容纳多少个颜色值。在您的情况下,对于灰度图像,由于您只保留从黑色到白色的值,并且中间有不同的灰度值,因此图像的深度类型会更小。

_src.depth()==CV_8U

如果只想将图像传递给Canny函数,则必须先将其转换为灰度。

//Read in the image from a file path
Mat img = CvInvoke.Imread(filePath, ImreadModes.AnyColor);

//Convert the image to gray scale
Image<Gray, byte> gray = img.ToImage<Gray, byte>();

//Threshold the image
CvInvoke.Threshold(gray, gray, 0, 100, ThresholdType.Binary);

//Canny the thresholded image
gray = gray.Canny(50, 200);

如果只想将图像传递给Canny函数而不通过阈值,则可以使用下面的代码。

//Read in the image from a file path
Mat img = CvInvoke.Imread(filePath, ImreadModes.AnyColor);

//Convert the image to gray scale
Image<Gray, byte> gray = img.ToImage<Gray, byte>();

//Canny the thresholded image
gray = gray.Canny(50, 200);
© www.soinside.com 2019 - 2024. All rights reserved.