网站开发产权保护,服务器网站建设流程,邢台人才网,抚顺市网站建设专栏系列文章如下#xff1a; 【视觉SLAM十四讲学习笔记】第一讲——SLAM介绍 【视觉SLAM十四讲学习笔记】第二讲——初识SLAM 【视觉SLAM十四讲学习笔记】第三讲——旋转矩阵 本章将介绍视觉SLAM的基本问题之一#xff1a;如何描述刚体在三维空间中的运动#xff1f; Eigen…专栏系列文章如下 【视觉SLAM十四讲学习笔记】第一讲——SLAM介绍 【视觉SLAM十四讲学习笔记】第二讲——初识SLAM 【视觉SLAM十四讲学习笔记】第三讲——旋转矩阵 本章将介绍视觉SLAM的基本问题之一如何描述刚体在三维空间中的运动 Eigen 
Eigen是一个C开源线性代数库。它提供了快速的有关矩阵的线性代数运算还包括解方程等功能。 
请输入以下命令进行安装 
sudo apt-get install libeigen3-dev与其他库相比Eigen的特殊之处在于它是一个纯用头文件搭建起来的库这意味着你只能找到它的头文件而没有类似.so或者.a的二进制文件。在使用时只需引入Eigen的头文件即可不需要链接库文件因为它没有库文件。接下来对这个库的使用做一些示例 
#include iostreamusing namespace std;#include ctime
// Eigen 核心部分
#include Eigen/Core
// 稠密矩阵的代数运算逆特征值等
#include Eigen/Denseusing namespace Eigen;int main(int argc, char **argv) {// Eigen 中所有向量和矩阵都是Eigen::Matrix它是一个模板类。它的前三个参数为数据类型行列// 声明一个2*3的float矩阵Matrixfloat, 2, 3 matrix_23;// 同时Eigen 通过 typedef 提供了许多内置类型不过底层仍是Eigen::Matrix// 例如 Vector3d 实质上是 Eigen::Matrixdouble, 3, 1即三维向量Vector3d v_3d;// 这是一样的Matrixfloat, 3, 1 vd_3d;// Matrix3d 实质上是 Eigen::Matrixdouble, 3, 3Matrix3d matrix_33  Matrix3d::Zero(); //初始化为零// 如果不确定矩阵大小可以使用动态大小的矩阵Matrixdouble, Dynamic, Dynamic matrix_dynamic;// 更简单的MatrixXd matrix_x;// 这种类型还有很多我们不一一列举// 下面是对Eigen阵的操作// 输入数据初始化matrix_23  1, 2, 3, 4, 5, 6;// 输出cout  matrix 2x3 from 1 to 6: \n  matrix_23  endl;// 用()访问矩阵中的元素cout  print matrix 2x3:   endl;for (int i  0; i  2; i) {for (int j  0; j  3; j) cout  matrix_23(i, j)  \t;cout  endl;}return 0;
}输出结果 
matrix 2x3 from 1 to 6: 
1 2 3
4 5 6
print matrix 2x3: 
1	2	3	
4	5	6	矩阵运算 
#include iostreamusing namespace std;#include ctime
#include Eigen/Core
#include Eigen/Denseusing namespace Eigen;int main(int argc, char **argv) {// Eigen 中所有向量和矩阵都是Eigen::Matrix它是一个模板类。它的前三个参数为数据类型行列// 声明一个2*3的float矩阵Matrixfloat, 2, 3 matrix_23;Vector3d v_3d;Matrixfloat, 3, 1 vd_3d;// Matrix3d 实质上是 Eigen::Matrixdouble, 3, 3Matrix3d matrix_33  Matrix3d::Zero(); //初始化为零// 下面是对Eigen阵的操作// 输入数据初始化matrix_23  1, 2, 3, 4, 5, 6;// 矩阵和向量相乘实际上仍是矩阵和矩阵v_3d  3, 2, 1;vd_3d  4, 5, 6;// 但是在Eigen里你不能混合两种不同类型的矩阵像这样是错的// Matrixdouble, 2, 1 result_wrong_type  matrix_23 * v_3d;// 应该显式转换Matrixdouble, 2, 1 result  matrix_23.castdouble() * v_3d;cout  [1,2,3;4,5,6]*[3,2,1]  result.transpose()  endl;Matrixfloat, 2, 1 result2  matrix_23 * vd_3d;cout  [1,2,3;4,5,6]*[4,5,6]:   result2.transpose()  endl;// 一些矩阵运算// 四则运算就不演示了直接用-*/即可。matrix_33  Matrix3d::Random();      // 随机数矩阵cout  random matrix: \n  matrix_33  endl;cout  transpose: \n  matrix_33.transpose()  endl;      // 转置cout  sum:   matrix_33.sum()  endl;            // 各元素和cout  trace:   matrix_33.trace()  endl;          // 迹cout  times 10: \n  10 * matrix_33  endl;               // 数乘cout  inverse: \n  matrix_33.inverse()  endl;        // 逆cout  det:   matrix_33.determinant()  endl;    // 行列式// 特征值// 实对称矩阵可以保证对角化成功SelfAdjointEigenSolverMatrix3d eigen_solver(matrix_33.transpose() * matrix_33);cout  Eigen values  \n  eigen_solver.eigenvalues()  endl;cout  Eigen vectors  \n  eigen_solver.eigenvectors()  endl;return 0;
}	输出结果 
[1,2,3;4,5,6]*[3,2,1]10 28
[1,2,3;4,5,6]*[4,5,6]: 32 77
random matrix: 0.680375   0.59688 -0.329554
-0.211234  0.823295  0.5364590.566198 -0.604897 -0.444451
transpose: 0.680375 -0.211234  0.5661980.59688  0.823295 -0.604897
-0.329554  0.536459 -0.444451
sum: 1.61307
trace: 1.05922
times 10: 6.80375   5.9688 -3.29554
-2.11234  8.23295  5.364595.66198 -6.04897 -4.44451
inverse: 
-0.198521   2.22739    2.83571.00605 -0.555135  -1.41603-1.62213   3.59308   3.28973
det: 0.208598
Eigen values  
0.02428990.9921541.80558
Eigen vectors  
-0.549013 -0.735943  0.3961980.253452 -0.598296 -0.760134
-0.796459  0.316906 -0.514998解方程 
#include iostream
#include ctime
#include Eigen/Core
#include Eigen/Dense
using namespace std;
using namespace Eigen;#define MATRIX_SIZE 50int main(int argc, char **argv) {// 解方程// 我们求解 matrix_NN * x  v_Nd 这个方程// N的大小在前边的宏里定义它由随机数生成// 直接求逆自然是最直接的但是求逆运算量大Matrixdouble, MATRIX_SIZE, MATRIX_SIZE matrix_NN MatrixXd::Random(MATRIX_SIZE, MATRIX_SIZE);matrix_NN  matrix_NN * matrix_NN.transpose();  // 保证半正定Matrixdouble, MATRIX_SIZE, 1 v_Nd  MatrixXd::Random(MATRIX_SIZE, 1);clock_t time_stt  clock(); // 计时// 直接求逆Matrixdouble, MATRIX_SIZE, 1 x  matrix_NN.inverse() * v_Nd;cout  time of normal inverse is  1000 * (clock() - time_stt) / (double) CLOCKS_PER_SEC  ms  endl;cout  x    x.transpose()  endl;// 通常用矩阵分解来求例如QR分解速度会快很多time_stt  clock();x  matrix_NN.colPivHouseholderQr().solve(v_Nd);cout  time of Qr decomposition is  1000 * (clock() - time_stt) / (double) CLOCKS_PER_SEC  ms  endl;cout  x    x.transpose()  endl;// 对于正定矩阵还可以用cholesky分解来解方程time_stt  clock();x  matrix_NN.ldlt().solve(v_Nd);cout  time of ldlt decomposition is  1000 * (clock() - time_stt) / (double) CLOCKS_PER_SEC  ms  endl;cout  x    x.transpose()  endl;return 0;
}结果如下 
time of normal inverse is 2.606ms
x  -55.7896 -298.793  130.113 -388.455 -159.312  160.654 -40.0416 -193.561  155.844  181.144  185.125 -62.7786  19.8333 -30.8772 -200.746  55.8385 -206.604  26.3559 -14.6789  122.719 -221.449   26.233  -318.95 -78.6931  50.1446  87.1986 -194.922  132.319  -171.78 -4.19736   11.876 -171.779  48.3047  84.1812 -104.958 -47.2103 -57.4502 -48.9477 -19.4237  28.9419  111.421  92.1237 -288.248 -23.3478  -275.22 -292.062  -92.698  5.96847 -93.6244  109.734
time of Qr decomposition is 3.419ms
x  -55.7896 -298.793  130.113 -388.455 -159.312  160.654 -40.0416 -193.561  155.844  181.144  185.125 -62.7786  19.8333 -30.8772 -200.746  55.8385 -206.604  26.3559 -14.6789  122.719 -221.449   26.233  -318.95 -78.6931  50.1446  87.1986 -194.922  132.319  -171.78 -4.19736   11.876 -171.779  48.3047  84.1812 -104.958 -47.2103 -57.4502 -48.9477 -19.4237  28.9419  111.421  92.1237 -288.248 -23.3478  -275.22 -292.062  -92.698  5.96847 -93.6244  109.734
time of ldlt decomposition is 1.38ms
x  -55.7896 -298.793  130.113 -388.455 -159.312  160.654 -40.0416 -193.561  155.844  181.144  185.125 -62.7786  19.8333 -30.8772 -200.746  55.8385 -206.604  26.3559 -14.6789  122.719 -221.449   26.233  -318.95 -78.6931  50.1446  87.1986 -194.922  132.319  -171.78 -4.19736   11.876 -171.779  48.3047  84.1812 -104.958 -47.2103 -57.4502 -48.9477 -19.4237  28.9419  111.421  92.1237 -288.248 -23.3478  -275.22 -292.062  -92.698  5.96847 -93.6244  109.734这个例程演示了Eigen矩阵的基本操作与运算。要编译它需要在CMakeLists.txt里指定Eigen的头文件目录 
#添加头文件
include_directories(/usr/include/eigen3)因为Eigen库只有头文件所以不需要再用target_link_libraries语句将程序链接到库上。 文章转载自: http://www.morning.yltyr.cn.gov.cn.yltyr.cn http://www.morning.bhrkx.cn.gov.cn.bhrkx.cn http://www.morning.hlfnh.cn.gov.cn.hlfnh.cn http://www.morning.srxhd.cn.gov.cn.srxhd.cn http://www.morning.syssdz.cn.gov.cn.syssdz.cn http://www.morning.qwbht.cn.gov.cn.qwbht.cn http://www.morning.nbnq.cn.gov.cn.nbnq.cn http://www.morning.ybgcn.cn.gov.cn.ybgcn.cn http://www.morning.sryyt.cn.gov.cn.sryyt.cn http://www.morning.srckl.cn.gov.cn.srckl.cn http://www.morning.jnzfs.cn.gov.cn.jnzfs.cn http://www.morning.wzwyz.cn.gov.cn.wzwyz.cn http://www.morning.kfrhh.cn.gov.cn.kfrhh.cn http://www.morning.mgmyt.cn.gov.cn.mgmyt.cn http://www.morning.wfjrl.cn.gov.cn.wfjrl.cn http://www.morning.benqc.com.gov.cn.benqc.com http://www.morning.jcwrb.cn.gov.cn.jcwrb.cn http://www.morning.rdnkx.cn.gov.cn.rdnkx.cn http://www.morning.mlyq.cn.gov.cn.mlyq.cn http://www.morning.fmkjx.cn.gov.cn.fmkjx.cn http://www.morning.nfdty.cn.gov.cn.nfdty.cn http://www.morning.ydtdn.cn.gov.cn.ydtdn.cn http://www.morning.1000sh.com.gov.cn.1000sh.com http://www.morning.cczrw.cn.gov.cn.cczrw.cn http://www.morning.pjjkz.cn.gov.cn.pjjkz.cn http://www.morning.hqbk.cn.gov.cn.hqbk.cn http://www.morning.wfhnz.cn.gov.cn.wfhnz.cn http://www.morning.mnqg.cn.gov.cn.mnqg.cn http://www.morning.rwqj.cn.gov.cn.rwqj.cn http://www.morning.qttft.cn.gov.cn.qttft.cn http://www.morning.pjqxk.cn.gov.cn.pjqxk.cn http://www.morning.dwtdn.cn.gov.cn.dwtdn.cn http://www.morning.rqpgk.cn.gov.cn.rqpgk.cn http://www.morning.tqbw.cn.gov.cn.tqbw.cn http://www.morning.svtxeu.com.gov.cn.svtxeu.com http://www.morning.hwpcm.cn.gov.cn.hwpcm.cn http://www.morning.bftqc.cn.gov.cn.bftqc.cn http://www.morning.kjcll.cn.gov.cn.kjcll.cn http://www.morning.zsrdp.cn.gov.cn.zsrdp.cn http://www.morning.cpgdy.cn.gov.cn.cpgdy.cn http://www.morning.datadragon-auh.cn.gov.cn.datadragon-auh.cn http://www.morning.brbnc.cn.gov.cn.brbnc.cn http://www.morning.fmjzl.cn.gov.cn.fmjzl.cn http://www.morning.ygwyt.cn.gov.cn.ygwyt.cn http://www.morning.nxzsd.cn.gov.cn.nxzsd.cn http://www.morning.pwqyd.cn.gov.cn.pwqyd.cn http://www.morning.simpliq.cn.gov.cn.simpliq.cn http://www.morning.xpzkr.cn.gov.cn.xpzkr.cn http://www.morning.fpxms.cn.gov.cn.fpxms.cn http://www.morning.ffgbq.cn.gov.cn.ffgbq.cn http://www.morning.hmdn.cn.gov.cn.hmdn.cn http://www.morning.rxnxl.cn.gov.cn.rxnxl.cn http://www.morning.nptls.cn.gov.cn.nptls.cn http://www.morning.zrwlz.cn.gov.cn.zrwlz.cn http://www.morning.ckhry.cn.gov.cn.ckhry.cn http://www.morning.rbzd.cn.gov.cn.rbzd.cn http://www.morning.hqwcd.cn.gov.cn.hqwcd.cn http://www.morning.bnxfj.cn.gov.cn.bnxfj.cn http://www.morning.bfwk.cn.gov.cn.bfwk.cn http://www.morning.xpzrx.cn.gov.cn.xpzrx.cn http://www.morning.wkpfm.cn.gov.cn.wkpfm.cn http://www.morning.3ox8hs.cn.gov.cn.3ox8hs.cn http://www.morning.rymd.cn.gov.cn.rymd.cn http://www.morning.bypfj.cn.gov.cn.bypfj.cn http://www.morning.shxmr.cn.gov.cn.shxmr.cn http://www.morning.stcds.cn.gov.cn.stcds.cn http://www.morning.pbsfq.cn.gov.cn.pbsfq.cn http://www.morning.lonlie.com.gov.cn.lonlie.com http://www.morning.mypxm.com.gov.cn.mypxm.com http://www.morning.bqrd.cn.gov.cn.bqrd.cn http://www.morning.tcpnp.cn.gov.cn.tcpnp.cn http://www.morning.krrjb.cn.gov.cn.krrjb.cn http://www.morning.rjmb.cn.gov.cn.rjmb.cn http://www.morning.pcgjj.cn.gov.cn.pcgjj.cn http://www.morning.qgfy.cn.gov.cn.qgfy.cn http://www.morning.tkzqw.cn.gov.cn.tkzqw.cn http://www.morning.qnxzx.cn.gov.cn.qnxzx.cn http://www.morning.tmfm.cn.gov.cn.tmfm.cn http://www.morning.zfcfx.cn.gov.cn.zfcfx.cn http://www.morning.wtnwf.cn.gov.cn.wtnwf.cn