Canny edge detection - grayscale images always coming up as 3-channel, unusable?

Posted by cvcentral on Stack Overflow See other posts from Stack Overflow or by cvcentral
Published on 2010-05-10T02:07:28Z Indexed on 2010/05/10 2:18 UTC
Read the original article Hit count: 453

Filed under:
|
|

I am working through the book "Learning OpenCV" from the O'Reilly series and am trying to perform a canny edge detection sample.

Any grayscale image I choose seems to come up as having 3 channels, and to the best of my knowledge, canny only works with single channel images, so this always fails. I am even using the images provided by OpenCV.

Here is my code..

IplImage* doCanny(IplImage* in, double lowThresh, double highThresh, double aperture)
{
    if(in->nChannels != 1)
        return(0); //canny only handles gray scale images
    IplImage* out = cvCreateImage(cvSize(in->width, in->height), IPL_DEPTH_8U, 1);
    cvCanny(in, out, lowThresh, highThresh, aperture);
    return(out);
};

IplImage* img = cvLoadImage("someGrayscaleImage.jpg");
IplImage* out = doCanny(img, 10, 100, 3);

Why might this always give me 3-channel images? How can I solve this?

© Stack Overflow or respective owner

Related posts about opencv

Related posts about edge-detection