简体   繁体   中英

EmguCV - Canny function throwing _src.depth()==CV_8U

I'm working currently on a project where I use EmguCV 4.2

I need to use Canny function:

gray=gray.Canny(50, 200);

And it's throwing error:

 _src.depth()==CV_8U

I noticed that exception occurs only if I use CvInvoke.Threshold() on my image earlier

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

I'm wondering why is this happening, without the Threshold() function everything works. Is this function changing the depth of my image somehow? How do I convert it back to use the Canny() function without problems?

Thanks in advance.

From what I can gather from your question, there might be an issue with your conversion of your image to gray scale.

The error code below refers the the depth type of your image, ie, how many color values can fit inside each individual pixel of your image. In your case, with gray scale images, since you only hold values from black to white with different variants of gray in between, the depth type of the image will be smaller.

_src.depth()==CV_8U

If you just want to pass an image to the Canny function, then you must convert it to gray scale first.

// 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);

If you just want to pass an image to the Canny function without passing it through a threshold, then you can use the code below.

// 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM