From 05f974da0bfd8e4c7ffc45758d42a091d08b737c Mon Sep 17 00:00:00 2001 From: Brendan Klare Date: Mon, 7 Jul 2014 22:46:55 -0400 Subject: [PATCH] Convenience function to go between matrix and point list --- openbr/core/eigenutils.cpp | 9 +++++++++ openbr/core/eigenutils.h | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/openbr/core/eigenutils.cpp b/openbr/core/eigenutils.cpp index ad0dc48..2bae4cd 100644 --- a/openbr/core/eigenutils.cpp +++ b/openbr/core/eigenutils.cpp @@ -95,3 +95,12 @@ MatrixXf removeRowCol(MatrixXf X, int row, int col) { } return Y; } + +MatrixXf pointsToMatrix(QList points) { + MatrixXf P(points.size(), 2); + for (int i = 0; i < points.size(); i++) { + P(i, 0) = points[i].x(); + P(i, 1) = points[i].y(); + } + return P; +} diff --git a/openbr/core/eigenutils.h b/openbr/core/eigenutils.h index 8f5e0b7..50b4b5d 100644 --- a/openbr/core/eigenutils.h +++ b/openbr/core/eigenutils.h @@ -29,9 +29,13 @@ void printEigen(Eigen::MatrixXd X); void printEigen(Eigen::MatrixXf X); void printSize(Eigen::MatrixXf X); -//Remove row and column from the matrix +//Remove row and column from the matrix: Eigen::MatrixXf removeRowCol(Eigen::MatrixXf X, int row, int col); +//Convert a point list into a matrix: +Eigen::MatrixXf pointsToMatrix(QList points); + + template inline QDataStream &operator<<(QDataStream &stream, const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &mat) { @@ -121,4 +125,5 @@ Eigen::MatrixBase eigStd(const Eigen::MatrixBase& x,int dim) } qFatal("A matrix can only have two dimensions"); } + #endif // EIGENUTILS_H -- libgit2 0.21.4