#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
//加载图片并显示灰度图
void loadGrayImg()
{
Mat src = imread("D:\images\1.jpg");
if (src.empty())
{
cout <<"could load image..." << endl;
}
namedWindow("window1",CV_WINDOW_AUTOSIZE);
imshow("window1",src);//显示原图
//灰度图
Mat grayImg;
cvtColor(src,grayImg,CV_BGR2GRAY);
namedWindow("window2", CV_WINDOW_AUTOSIZE);
imshow("window2",grayImg);//显示灰度图
//其他色彩空间
Mat otherImg;
cvtColor(src,otherImg,CV_BGR2HLS);
namedWindow("window3",CV_WINDOW_AUTOSIZE);
imshow("window3",otherImg);
//保存图片
imwrite("D:\images\1-gray.jpg",grayImg);
imwrite("D:\images\1-gray.tif", grayImg);
}
int main()
{
loadGrayImg();
waitKey(0);
return 0;
}