1、 Mat frame =imread("apple.jpg"); 读取图像
if( !frame.date )
return 0;
Mat image.create( frame.size( ),frame.type( ));
image.setTo( cv::Scalar(0,0,0) );
Matimg_roi( Rect( 2,3,56,56 ) );
//image.row(0).setTo(255,255,255);
2、imwrite("apple.jpg",frame); 保存图像为.jpg格式
3、imshow("image",frame);显示图像
4、resize(frame,frame_temp,Size(width,height));改变图像大小
5、 cvtColor(frame,grayframe, CV_BGR2GRAY); 变图像为灰度图,还有其它的如下:
CV_RGB2GRAY CV_GRAY2BGR
CV_GRAY2RGB CV_BGR2YCrCb CV_RGB2YCrCb CV_YCrCb2BGR CV_YCrCb2RGB CV_BGR2HSV CV_RGB2HSV
6、 创建一幅图像
Mat frame = Mat(Size(width,height),CV_8UC3); //CV_8UC1 CV_16UC3 CV_32SC1
或 Matframe;
frame.create(Size(width,height),CV_8UC3);
8、Mat frame; Matframe_temp; //直接赋值矩阵
frame_temp = frame;//只是创建了一个新的矩阵头,矩阵本身还是指向frame,frame变时,frame_temp也会变。
9、//深复制,完全复制
Mat frame; Matframe_temp;
frame_temp = frame.clone();
或 frame.copyTo(frame_temp);
浅复制:
Mat b;
Mat a = b;
Mat a = Mat( b,Rect(2,5,15,20) );
10、Matframe; //提取某个像素的值
float value =frame.at(row,col);
或 char value = frame.at(row,col);
或 int value =frame.at(row,col);
彩色图像:</