22, Eigen simple learning and finishing

Recently, I saw the deepsort tracking algorithm, and the author uses the C++ Eigen function, so simply record the use process;

sudo apt-get install libeigen3-dev
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include 
#include<iostream>
#include<Eigen/Dense>
#include<vector>
using namespace std;
using namespace Eigen;
typedef Matrix<double,1,4,RowMajor> Detection;
typedef Matrix<double,3,1,ColMajor> V3D_1;
int main(int argc, char **argv)
{
        V3D_1 v3d_1(1,2,3); 
        cout<<v3d_1<<endl;
        Matrix3d matrix33(3,3);
        matrix33<<31,2,3,4,5,6,7,8,9;
        cout<<matrix33<<endl;
        cout<<"逆矩阵"<<endl<<matrix33.inverse()<<endl; // 逆矩阵
        cout<<"对角线的和"<<endl<<matrix33.trace()<<endl; // 对角线的和
        cout<<"矩阵元素求和"<<endl<<matrix33.sum()<<endl; //矩阵元素的和
        cout<<"矩阵转置"<<endl<<matrix33.transpose()<<endl; // 矩阵转置
        Matrix3d mat = Matrix3d::Identity(3,3); // 单位矩阵
        
        cout<<mat<<endl;
	vector<Detection> vec_eigen;
	//	Matrix<float,4,1,RowMajor> tracker;
	//	tracker(1,2,3,4);
	Detection detection(1,2,3,4);
	vec_eigen.push_back(detection);
	vec_eigen.push_back(detection+detection);
	//cout<<detection<<endl;
	//cout<<tracker<<endl;
	for (int i=0;i<vec_eigen.size();i++)
		cout<<vec_eigen.at(i)<<endl;
        Matrix3d x3d; // 3x3 矩阵
        Vector3d v3d; // 3x1 向量
        Matrix<double,3,3,RowMajor> xx3d;
        Matrix<double,3,1,ColMajor> vv3d;
        x3d<<2,3,4,5,6,7,8,9,10;
        xx3d=x3d;
        v3d<<2,3,4;
        vv3d=v3d;
        cout<<xx3d<<endl;
        cout<<vv3d<<endl;

 	
	return 0;
}

Output result

ubuntu@ubuntu:~$ g++ ttest.cpp 
ubuntu@ubuntu:~$ ./a.out 
1
2
3
31  2  3
 4  5  6
 7  8  9
逆矩阵
 0.0333333 -0.0666667  0.0333333
-0.0666667   -2.86667    1.93333
 0.0333333        2.6   -1.63333
对角线的和
45
矩阵元素求和
75
矩阵转置
31  4  7
 2  5  8
 3  6  9
1 0 0
0 1 0
0 0 1
1 2 3 4
2 4 6 8
 2  3  4
 5  6  7
 8  9 10
2
3
4

 

Guess you like

Origin blog.csdn.net/sxj731533730/article/details/105514850