Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 472
shefff Avatar asked Mar 07 '26 01:03

shefff


1 Answers

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, i.e, 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);
like image 126
Aaron Jones Avatar answered Mar 09 '26 03:03

Aaron Jones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!