zoukankan      html  css  js  c++  java
  • Mat代码操作

    [cpp] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. #include<opencv2/opencv.hpp>  
    2. #include<iostream>  
    3. using namespace std;  
    4. using namespace cv;  
    5. int main()  
    6. {  
    7.     float array[]={1,2,3};  
    8.     float array1[]={2,3,1};  
    9.     //用数组初始化Mat  
    10.     Mat mat=Mat(1,3,CV_32F,array);  
    11.     Mat mat1=Mat(1,3,CV_32F,array1);  
    12.     Mat tempmat;  
    13.     //对mat拷贝  
    14.     mat.copyTo(tempmat);  
    15.     cout<<tempmat<<endl;  
    16.     //选择roi,rect的四个参数分别是(x,y)坐标,第三个参数是宽度,第四个参数是高度  
    17.     Mat roi(mat,Rect(0,0,2,1));  
    18.     cout<<roi<<endl;  
    19.     //mat-mat1的1范数  
    20.     cout<<norm(mat,mat1,CV_L1)<<endl;  
    21.     //mat-mat1的2范数  
    22.     cout<<norm(mat,mat1,CV_L2)<<endl;  
    23.     //打印mat的内容  
    24.     cout<<mat<<endl;  
    25.     //创建对角为1的矩阵  
    26.     Mat eyemat=Mat::eye(4,4,CV_8U);  
    27.     cout<<eyemat<<endl;  
    28.     //提取eyemat的1-2行,3-4列  
    29.     Mat submat=eyemat(Range(0,2),Range(2,4));  
    30.     cout<<submat<<endl;  
    31.     //abs(),max(),min(),+,-,*,/等操作很简单,就不写了  
    32.     float a[2][2]={2,3,1,2};  
    33.     float b[2][2]={2,1,0,-1};  
    34.     Mat amat(2,2,CV_32F,a);  
    35.     Mat bmat(2,2,CV_32F,b);  
    36.     cout<<amat<<endl;  
    37.     cout<<bmat<<endl;  
    38.     //求amat的逆  
    39.     cout<<amat.inv()<<endl;  
    40.     //两矩阵相乘  
    41.     cout<<amat.mul(bmat)<<endl;  
    42.     //生成一个值为0的矩阵  
    43.     cout<<Mat::zeros(3,3,CV_32F)<<endl;  
    44.     //生成一个值为1的矩阵  
    45.     cout<<Mat::ones(3,3,CV_32F)<<endl;  
    46.     system("pause");  
    47. }  
    [cpp] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. #include<opencv2/opencv.hpp>  
    2. #include<assert.h>  
    3. using namespace cv;  
    4. int main()  
    5. {  
    6.     Mat srcImage=imread("f:/huangshan.jpg");  
    7.     Mat dstImage=imread("f:/Lena.jpg");  
    8.     assert(srcImage.data!=NULL && dstImage.data!=NULL);   
    9.   
    10.     Mat roi=srcImage(Rect(0,0,dstImage.cols,dstImage.rows)); //获取感兴趣区域  
    11.     Mat mask = imread("f:/Lena.jpg",0);  
    12.     namedWindow("image",WINDOW_AUTOSIZE);  
    13.     roi=roi.t(); //mat转置  
    14.     flip(roi,roi,0); //0为上下翻转,>0为左右翻转,<0同时上下左右翻转  
    15.     //将掩膜拷贝到ROI中  
    16.     //dstImage.copyTo(roi,mask);  
    17.     addWeighted(roi,0.7,dstImage,0.3,0.,roi);  
    18.   
    19.       
    20.     //Mat mask = imread("f:/huangshan.jpg",0);  
    21.     //img.copyTo(roi,mask);  
    22.     imshow("image",srcImage);  
    23.     waitKey();  
    24.     return 0;  
    25. }  
  • 相关阅读:
    mybatis多参数传递(包括数组)
    mysql查询树状目录所有子节点
    Kettle ETL调用 java代码来进行数据库的增删改查
    java dom4j解析器使用
    Linux查看系统位数
    Linux查看系统是32位还是64位命令(getconf WORD_BIT和getconf LONG_BIT)
    Centos7下Redis缓存清理_FZlion
    springboot+vue项目实战(代码可运行)
    SpringBoot控制台打印SQL语句
    Error running ‘Application‘: Command line is too long
  • 原文地址:https://www.cnblogs.com/ttzm/p/5418910.html
Copyright © 2011-2022 走看看