C++精解【6】

eigen

Matrix

基础

  • 所有矩阵和向量都是Matrix模板类的对象。
  • 向量也是矩阵,单行或单列。
  • Matrix模板类6个参数,常用就3个参数,其它3个参数有默认值。
Matrix<typename Scalar, int RowsAtCompileTime, int ColsAtCompileTime>

分别是元素标量类型,编译时行数和列数
-下面定义float类型元素,4*5的矩阵

typedef Matrix<float, 4, 4> Matrix4f;
  • 4*1列 向量
typedef Matrix<float, 4, 1> Vector3f;
  • 1*2行向量
typedef Matrix<int, 1, 2> RowVector2i;
  • 运行时再指定维度
typedef Matrix<double, Dynamic, Dynamic> MatrixXd;
typedef Matrix<int, Dynamic, 1> VectorXi;
//只指定行
Matrix<float, 3, Dynamic>
MatrixXf a(10,15);
VectorXf b(30);
  • 初始化元素
Vector2i a(1, 2);                      
Matrix<int, 5, 1> b {1, 2, 3, 4, 5};   
Matrix<int, 1, 5> c = {1, 2, 3, 4, 5}; 

编译时固定尺寸
  • Matrix4f
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"

using Eigen::Matrix4f;

int main()
{
  Matrix4f m = Matrix4f::Random();
  std::cout << m << std::endl;
}


 -0.997497   0.170019    0.64568   0.421003
  0.127171 -0.0402539    0.49321  0.0270699
 -0.613392  -0.299417  -0.651784   -0.39201
  0.617481   0.791925   0.717887  -0.970031

Process returned 0 (0x0)   execution time : 0.099 s
Press any key to continue.


  • Vector3f
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"

using Eigen::Vector3f;

int main()
{
  Vector3f m = Vector3f::Random();
  std::cout << m << std::endl;
}


-0.997497
 0.127171
-0.613392

Process returned 0 (0x0)   execution time : 0.103 s
Press any key to continue.
  • RowVector2i
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"

using Eigen::RowVector2i;

int main()
{
  RowVector2i m = RowVector2i::Random();
  std::cout << m << std::endl;
}


-16343   2083

Process returned 0 (0x0)   execution time : 0.091 s
Press any key to continue.

  • 指定大小
    6*6的矩阵
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"

using Eigen::Matrix;
typedef Matrix<int,6,6> Matrix6i;
int main()
{
  Matrix6i m = Matrix6i::Random();
  std::cout << m << std::endl;
}


-16343  -4906   6897 -11557 -16092 -10937
  2083  12974    443 -10948  -4002   5342
-10050  10578  -6423  16007   1037  -1613
 10116   8080 -15893  -1780   2332  -4846
  2785 -10679 -13389 -12482   3334 -14515
  -660  11761  -4442 -16231   3511   3528

Process returned 0 (0x0)   execution time : 0.101 s
Press any key to continue.
运行指定大小
  • double型元素
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"

using Eigen::MatrixXf;
int main()
{
  MatrixXf m = MatrixXf::Random(3,3);
  std::cout << m << std::endl;
}
 -0.997497   0.617481  -0.299417
  0.127171   0.170019   0.791925
 -0.613392 -0.0402539    0.64568

Process returned 0 (0x0)   execution time : 0.099 s
Press any key to continue.

  • int型元素
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"

using Eigen::MatrixXi;
int main()
{
  MatrixXi m = MatrixXi::Random(3,3);
  std::cout << m << std::endl;
}


-16343  10116  -4906
  2083   2785  12974
-10050   -660  10578

Process returned 0 (0x0)   execution time : 0.098 s
Press any key to continue.

  • 指定元素值
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"

using Eigen::Vector2i;
using Eigen::Matrix;
int main()
{
    Vector2i a(1, 2);
    Matrix<int, 5, 1> b {1, 2, 3, 4, 5};
    Matrix<int, 1, 5> c = {1, 2, 3, 4, 5};
    std::cout << a<< std::endl;
    std::cout << b<< std::endl;
    std::cout << c<< std::endl;
}
1
2
1
2
3
4
5
1 2 3 4 5

Process returned 0 (0x0)   execution time : 0.094 s
Press any key to continue.

OpenCV

概述

  • OpenCV(开源计算机视觉库:http://opencv.org)是一个开源库,包含数百种计算机视觉算法。
  • 操作均是在windows下,所以从下面链接下载安装包:
    https://github.com/opencv/opencv/releases/latest
    -
  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值