Commit 65ab2622b1bd36c4553c995fcb9eb6b502f42b03
1 parent
e0460ba3
Eigen helper functions
Showing
2 changed files
with
31 additions
and
0 deletions
openbr/core/eigenutils.cpp
| ... | ... | @@ -16,4 +16,32 @@ void writeEigen(MatrixXf X, QString filename) { |
| 16 | 16 | format->write(br::Template(m)); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | +void writeEigen(MatrixXd X, QString filename) { | |
| 20 | + Mat m(X.rows(),X.cols(),CV_32FC1); | |
| 21 | + for (int i = 0; i < X.rows(); i++) { | |
| 22 | + for (int j = 0; j < X.cols(); j++) { | |
| 23 | + m.at<float>(i,j) = (float)X(i,j); | |
| 24 | + } | |
| 25 | + } | |
| 26 | + QScopedPointer<br::Format> format(br::Factory<br::Format>::make(filename)); | |
| 27 | + format->write(br::Template(m)); | |
| 28 | +} | |
| 19 | 29 | |
| 30 | +void writeEigen(VectorXd X, QString filename) { | |
| 31 | + Mat m(X.size(),1,CV_32FC1); | |
| 32 | + for (int i = 0; i < X.rows(); i++) { | |
| 33 | + m.at<float>(i,0) = (float)X(i); | |
| 34 | + } | |
| 35 | + QScopedPointer<br::Format> format(br::Factory<br::Format>::make(filename)); | |
| 36 | + format->write(br::Template(m)); | |
| 37 | +} | |
| 38 | + | |
| 39 | +void printEigen(Eigen::MatrixXd X) { | |
| 40 | + for (int i = 0; i < X.rows(); i++) { | |
| 41 | + QString str; | |
| 42 | + for (int j = 0; j < X.cols(); j++) { | |
| 43 | + str.append(QString::number(X(i,j)) + " "); | |
| 44 | + } | |
| 45 | + qDebug() << str; | |
| 46 | + } | |
| 47 | +} | ... | ... |
openbr/core/eigenutils.h
| ... | ... | @@ -22,6 +22,9 @@ |
| 22 | 22 | #include <assert.h> |
| 23 | 23 | |
| 24 | 24 | void writeEigen(Eigen::MatrixXf X, QString filename); |
| 25 | +void writeEigen(Eigen::MatrixXd X, QString filename); | |
| 26 | +void writeEigen(Eigen::VectorXd X, QString filename); | |
| 27 | +void printEigen(Eigen::MatrixXd X); | |
| 25 | 28 | |
| 26 | 29 | template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> |
| 27 | 30 | inline QDataStream &operator<<(QDataStream &stream, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) | ... | ... |