Canny 边缘检测 - 灰度图像总是以 3 通道的形式出现,无法使用?
我正在阅读 O'Reilly 系列的《学习 OpenCV》一书,并尝试执行精明的边缘检测示例。
我选择的任何灰度图像似乎都有 3 个通道,据我所知,canny 只适用于单通道图像,所以这总是失败。我什至使用 OpenCV 提供的图像。
这是我的代码..
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);
为什么这总是给我 3 通道图像?我该如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将此方法与另一个参数一起使用。
默认参数是加载带有颜色的图像。您要做的就是用灰度加载它
这是一个示例
这是该方法的详细说明。您可以在这里查看更多详细信息:
Open CV 2.0 参考
scolor – 加载的特定颜色类型图片:如果$> 0$,加载的图像强制为3通道彩色图像;如果为0,则加载的图像强制为灰度;如果 $ < 0 $,加载的图像将按原样加载(请注意,在当前实现中,alpha 通道(如果有)将从输出图像中剥离,例如 4 通道 RGBA 图像将作为 RGB 加载)。
You can use this method with another parameter
The default parameter is load image with color. What you have to do is to load it with grayscale
Here is an example
Here is the detail explanation for that method. You can look at here for more details:
Open CV 2.0 References
scolor – Specific color type of the loaded image: if $ > 0 $, the loaded image is forced to be a 3-channel color image; if 0, the loaded image is forced to be grayscale; if $ < 0 $, the loaded image will be loaded as is (note that in the current implementation the alpha channel, if any, is stripped from the output image, e.g. 4-channel RGBA image will be loaded as RGB).