1、图像的读取和显示
#include<iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> using namespace std; using namespace cv; int main(int argc, int* argv[]) { Mat image = imread("lena.bmp"); namedWindow("原图像"); imshow(" image ",image); waitKey(6000); return 0; }
其中imread();函数有三个参数分别是:
CV_LOAD_IMAGE_COLOR (>0) RGB彩色模式
CV_LOAD_IMAGE_GRAYSCALE ( 0 ) 灰度图像模式
CV_LOAD_IMAGE_UNCHANGED m ( <0 ) 视图像情况而定
/* 将一副图像转成灰度图像 */ #include <iostream> #include <cv.h> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> using namespace std; using namespace cv; int main(int argc, int* argv[]) { Mat image = imread("lena.bmp"); Mat grayimg; cvtColor(image, grayimg, CV_RGB2GRAY); imshow(" image1 ",image); imshow(" grayimg ",grayimg); waitKey(6000); return 0; }