将颜色图像转换为OpenCV中的灰度问题
Converting a color image to grayscale issue in OpenCV
当我尝试将颜色图像转换为灰度时,我正在面临问题。错误是:" cvgetSize中的坏参数(数组应为cvmat或iplimage)",但是当我评论所有与灰度相关的行时,我可以设法加载原始颜色映像并显示它。如何解决此错误?
#include <opencvcv.h>
#include <opencvhighgui.h>
#include <iostream>
#include <stdio.h>
int main(int argc, char** argv)
{
//Loading the color image
IplImage* frame = cvLoadImage("lena.jpg");
//Converting the color image to grayscale
IplImage* grayframe = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
cvCvtColor(frame, grayframe, CV_RGB2GRAY);
//Creating a window for color image
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
//Creating a window for grayscale image
cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE);
// Showing the color image
cvShowImage("Example1", frame);
// Showing the grayscale image
cvShowImage("Example2", grayframe);
//Showeing for X seconds
cvWaitKey(2000);
cvReleaseImage(&frame);
cvDestroyWindow("Example1");
cvReleaseImage(&grayframe);
cvDestroyWindow("Example2");
return 0;
}
为什么要iPlimage?
如果您想在以后扩展示例,请尝试使用MAT。
Mat image = imread("lena.jpg");
Mat gray;
cvtColor(image,gray,CV_BGR2GRAY);
这会轻松,将为您提供灰度图像。
但是,如果有使用C API的特定原因,那么问题在
IplImage* grayframe = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
我不知道这样做的确切原因,但是,我可以为您提供运行代码的替代方法。
int x= frame->width, y=frame->height;
IplImage* grayframe = cvCreateImage(cvSize(x,y), IPL_DEPTH_8U, 1);
tyr,它可能对您有用
相关文章:
- 在 C++ 中将 RGB 更改为灰度
- OpenCV - 如何在灰度图像上应用 Kmeans?
- OpenCV - 如何将灰度转换为彩色(CV_8UC3)?
- C++灰度图像处理
- 如何显示具有 opengl 纹理的灰度图像
- C++ Gdi+将图像转换为灰度
- 将 BMP 图像转换为灰度
- 如何使用Canny到32位灰度
- 颜色到灰度转换
- (C++)(Visual Studio) 将高斯模糊滤镜应用于 RGB 中的灰度图像
- 使用 SSE 以最快的速度缩小 8 位灰度图像
- 使用 OpenCV 和 C++将 16 位灰度图像更改为彩色图像
- 有没有办法使用 glDrawPixel 渲染单通道灰度图像?
- goodFeaturesToTrack() 只适用于灰度?
- 如何在OpenCV中减去两个不同尺寸的图像和灰度图像
- 使用 ImageMagick 从像素强度数组创建灰度图像时遇到问题
- 如何将图像转换为灰度 opengl c++
- 将高斯模糊应用于灰度图像
- 将颜色图像转换为OpenCV中的灰度问题
- c++和OpenCV:问题转换图像到灰度