cv :: Mat转换为Eigen-Matrix和back [英] cv::Mat conversion to Eigen-Matrix and back
问题描述
我有几个特征向量存储在 cv :: Mat
其中,每一行都是一个特征向量(像这样的几行: [x1 y1 x2 y2 x3 y3 ....]
)。我必须对每个特征向量应用SVD,因此我使用Eigen库。但是,在应用SVD之前,特征矩阵必须转换为 Eigen :: Matrix
形式。
I have several feature vectors stored in a cv::Mat
where, each row is a feature vector (several rows like this one here: [ x1 y1 x2 y2 x3 y3.... ]
). I have to apply SVD on each feature vector and for that I use Eigen library. But, before applying SVD the feature matrix has to be converted to Eigen::Matrix
form.
必须将SVD结果转换回 cv :: Mat
。
Later, I have to convert the SVD result back to cv::Mat
.
任何人都可以建议一个好的方法这个?我需要它在 cv :: Mat
形式的原因是因为我必须输入到OpenCV中的神经网络,只有 cv :: Mat
输入矩阵。
Could anyone please suggest a nice way to do this? The reason I need it in cv::Mat
form is because I have to input it to a Neural Network in OpenCV and only cv::Mat
inputs matrices are allowed.
谢谢!!!
推荐答案
#include <opencv2/core/eigen.hpp>
cv::Mat_<float> a = Mat_<float>::ones(2,2);
Eigen::Matrix<float,Dynamic,Dynamic> b;
cv2eigen(a,b);
Also, OpenCV CV::Mat and Eigen::Matrix has a solution using an Eigen::Map.
这篇关于cv :: Mat转换为Eigen-Matrix和back的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!