C++中Eigen与OpenCV矩阵的转换

Eigen与Opencv之间的转换,在包含Eigen库的基础上,#include<opencv2/core/eigen.hpp>

需要注意的是Eigen的声明库一定要声明在cv的Eigen库的前面。否则会报错。

将Eigen::Matrix转换为cv::Mat

cv::eigen2cv(matrix,mat);

#include <Eigen/Dense>
#include <iostream>
#include <opencv2/core/eigen.hpp>
#include <opencv2/opencv.hpp>
 
using namespace std;
using namespace cv;
using namespace Eigen;
 
void main()
{
	Mat img;
	Matrix<int,50,50> matrix ;
	m.fill(255);
	eigen2cv(m, img);
	return;
}

将cv::Mat转换为Eigen::Matrix

cv::cv2eigen(mat,matrix);

#include <Eigen/Dense>
#include <iostream>
#include <opencv2/core/eigen.hpp>
#include <opencv2/opencv.hpp>
 
using namespace std;
using namespace cv;
using namespace Eigen;
 
void main()
{
	Mat img = imread("car.jpg",1);
	int row = img.rows;
	int col = img.cols;
	MatrixXd matrix(row, col);
	cv2eigen(img,matrix);
	return;
}
发布了58 篇原创文章 · 获赞 64 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/ThorKing01/article/details/97628704