Mat代码操作
- #include<opencv2/opencv.hpp>
- #include<iostream>
- using namespace std;
- using namespace cv;
- int main()
- {
- float array[]={1,2,3};
- float array1[]={2,3,1};
-
- Mat mat=Mat(1,3,CV_32F,array);
- Mat mat1=Mat(1,3,CV_32F,array1);
- Mat tempmat;
-
- mat.copyTo(tempmat);
- cout<<tempmat<<endl;
-
- Mat roi(mat,Rect(0,0,2,1));
- cout<<roi<<endl;
-
- cout<<norm(mat,mat1,CV_L1)<<endl;
-
- cout<<norm(mat,mat1,CV_L2)<<endl;
-
- cout<<mat<<endl;
-
- Mat eyemat=Mat::eye(4,4,CV_8U);
- cout<<eyemat<<endl;
-
- Mat submat=eyemat(Range(0,2),Range(2,4));
- cout<<submat<<endl;
-
- float a[2][2]={2,3,1,2};
- float b[2][2]={2,1,0,-1};
- Mat amat(2,2,CV_32F,a);
- Mat bmat(2,2,CV_32F,b);
- cout<<amat<<endl;
- cout<<bmat<<endl;
-
- cout<<amat.inv()<<endl;
-
- cout<<amat.mul(bmat)<<endl;
-
- cout<<Mat::zeros(3,3,CV_32F)<<endl;
-
- cout<<Mat::ones(3,3,CV_32F)<<endl;
- system("pause");
- }
- #include<opencv2/opencv.hpp>
- #include<assert.h>
- using namespace cv;
- int main()
- {
- Mat srcImage=imread("f:/huangshan.jpg");
- Mat dstImage=imread("f:/Lena.jpg");
- assert(srcImage.data!=NULL && dstImage.data!=NULL);
-
- Mat roi=srcImage(Rect(0,0,dstImage.cols,dstImage.rows));
- Mat mask = imread("f:/Lena.jpg",0);
- namedWindow("image",WINDOW_AUTOSIZE);
- roi=roi.t();
- flip(roi,roi,0);
-
-
- addWeighted(roi,0.7,dstImage,0.3,0.,roi);
-
-
-
-
- imshow("image",srcImage);
- waitKey();
- return 0;
- }
原文地址:https://www.cnblogs.com/ttzm/p/5418910.html