Commit ea579f93c79ebc1af46f18c19a8c6a8f92019fc2
Merge pull request #252 from biometrics/helper
Simple helper method to convert from cv::Mat (32F) to Eigen::MatrixXf
Showing
2 changed files
with
13 additions
and
0 deletions
openbr/core/eigenutils.cpp
| @@ -137,3 +137,11 @@ Eigen::MatrixXf matrixToVector(const Eigen::MatrixXf matrix) { | @@ -137,3 +137,11 @@ Eigen::MatrixXf matrixToVector(const Eigen::MatrixXf matrix) { | ||
| 137 | return vector; | 137 | return vector; |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | +Eigen::MatrixXf toEigen(const Mat m) { | ||
| 141 | + if (m.type() != CV_32F) | ||
| 142 | + qFatal("Mat to Eigen Converstation only supports CV_32F"); | ||
| 143 | + | ||
| 144 | + Eigen::MatrixXf data(m.rows, m.cols); | ||
| 145 | + return Eigen::Map<const Eigen::MatrixXf>(m.ptr<float>(), m.rows, m.cols); | ||
| 146 | +} | ||
| 147 | + |
openbr/core/eigenutils.h
| @@ -21,6 +21,8 @@ | @@ -21,6 +21,8 @@ | ||
| 21 | #include <Eigen/Core> | 21 | #include <Eigen/Core> |
| 22 | #include <assert.h> | 22 | #include <assert.h> |
| 23 | 23 | ||
| 24 | +#include <opencv2/core/core.hpp> | ||
| 25 | + | ||
| 24 | void writeEigen(Eigen::MatrixXf X, QString filename); | 26 | void writeEigen(Eigen::MatrixXf X, QString filename); |
| 25 | void writeEigen(Eigen::MatrixXd X, QString filename); | 27 | void writeEigen(Eigen::MatrixXd X, QString filename); |
| 26 | void writeEigen(Eigen::VectorXd X, QString filename); | 28 | void writeEigen(Eigen::VectorXd X, QString filename); |
| @@ -40,6 +42,9 @@ Eigen::MatrixXf removeRowCol(const Eigen::MatrixXf X, int row, int col); | @@ -40,6 +42,9 @@ Eigen::MatrixXf removeRowCol(const Eigen::MatrixXf X, int row, int col); | ||
| 40 | Eigen::MatrixXf pointsToMatrix(const QList<QPointF> points, bool isAffine=false); | 42 | Eigen::MatrixXf pointsToMatrix(const QList<QPointF> points, bool isAffine=false); |
| 41 | QList<QPointF> matrixToPoints(const Eigen::MatrixXf P); | 43 | QList<QPointF> matrixToPoints(const Eigen::MatrixXf P); |
| 42 | 44 | ||
| 45 | +//Convert cv::Mat to Eigen | ||
| 46 | +Eigen::MatrixXf toEigen(const cv::Mat m); | ||
| 47 | + | ||
| 43 | template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> | 48 | template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> |
| 44 | inline QDataStream &operator<<(QDataStream &stream, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) | 49 | inline QDataStream &operator<<(QDataStream &stream, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) |
| 45 | { | 50 | { |