opencv矩阵与eigen矩阵的转换
opencv矩阵结构为:cv::Mat,或者cv::Mat_等,当需要与eigen的矩阵结构相互转换时主要使用函数:
cv::eigen2cv和cv::cv2eigen,需要头文件:#include<opencv2/core/eigen.hpp>
实例:
#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("jasen.jpg",CV_LOAD_IMAGE_GRAYSCALE);
int row = img.rows;
int col = img.cols;
MatrixXd m(row, col);
cv2eigen(img,m);
return;
}
实例:
#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,100,100> m ;
m.fill(255);
eigen2cv(m, img);
return;
}