首页 > 代码库 > opencv的图片的灰度处理‘

opencv的图片的灰度处理‘

 

#include "stdafx.h" //实现将彩色图片转换成灰度图

int _tmain(int argc, _TCHAR* argv[])
{
IplImage *image; //初始化保存原始图像
IplImage *result; //保存灰度图

image = cvLoadImage("图片3.jpg",-1);

int channel =-1;
int depth =image->depth;
CvSize sz;
sz.width =image->width;
sz.height =image->height;

result = cvCreateImage(sz,depth,channel);
cvCvtColor(image,result,CV_BGR2GRAY);
cvNamedWindow("original",1);
cvShowImage("original",image);
cvNamedWindow("gray",1);
cvShowImage("gray",result);
cvSaveImage("路面5.jpg",result);


cvWaitKey(0);
cvReleaseImage(&image);
cvReleaseImage(&result);
cvDestroyWindow("original");
cvDestroyWindow("gray");
return 0;
}

opencv的图片的灰度处理‘