C++调用Opencv实现基本矩阵操作

1、生成常用矩阵

Mat类中的函数eye(),one()在mat.hpp文件中有申明:

/*@param rows Number of rows.
  @param cols Number of columns.
  @param type Created matrix type.*/
static MatExpr eye(int rows, int cols, int type);
static MatExpr ones(int rows, int cols, int type);

/*@param size Alternative matrix size specification as Size(cols, rows) .
  @param type Created matrix type.*/
static MatExpr eye(Size size, int type);
static MatExpr ones(Size size, int type);

/*@param ndims Array dimensionality.
  @param sz Array of integers specifying the array shape.
  @param type Created matrix type.*/
static MatExpr ones(int ndims, const int* sz, int type);

生成矩阵:

#include<iostream>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
	Mat m1 = Mat::eye(4, 4, CV_32F);
	Mat m2 = Mat::eye(Size(5, 5), CV_32S);
	Mat m3 = Mat::ones(3, 4, CV_32F);
        Mat m4 = (Mat_ < float >(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);
	cout << "m1="<<m1 << "\n"<< "m2=" << m2 << "\n"<< "m3=" << m3 << "\n"<<"m4="<<m4 <<endl;
	getchar();
}
/*输出为:
   m1=[1, 0, 0, 0;      m2=[1,0,0,0,0;     m3=[1,1,1,1,1;      m4=[1,2,3;       
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值