接上一篇
#include "cv.h"
#include "highgui.h"
using namespace cv;
using namespace std;
int main(int argc,char *argv[])
{
Mat src,gray;
src=imread("lena.jpg",CV_LOAD_IMAGE_COLOR);
if (!src.data)
{
cout<<"Cound not read the file!"<<endl;
getchar();
return -1;
}
cvtColor(src,gray,CV_RGB2GRAY);
imwrite("../gray.jpg",gray); //其中../表示工程文件的上一级文件夹
namedWindow("src");namedWindow("gray");
imshow("src",src);imshow("gray",gray);
waitKey(0);
return 0;
}
从中看到C++编程的方便性,在图像处理时,不用先创建图像空间
The functions can read/write images in the following formats:(格式支持)
BMP (.bmp), JPEG (.jpg, .jpeg), TIFF (.tif, .ti ), PNG(.png), PBM/PGM/PPM (.p?m), Sun Raster (.sr),JPEG 2000 (.jp2). Every format supports 8-bit, 1- or3-channel images. Some formats (PNG, JPEG 2000) support 16 bits per channel.