Commit a0bb95c7216335064923f23196711079e20cee82
1 parent
635d372c
Simple helper method to convert from cv::Mat (32F) to Eigen::MatrixXf
Showing
2 changed files
with
11 additions
and
0 deletions
openbr/core/opencvutils.cpp
| @@ -336,6 +336,14 @@ bool OpenCVUtils::overlaps(const QList<Rect> &posRects, const Rect &negRect, dou | @@ -336,6 +336,14 @@ bool OpenCVUtils::overlaps(const QList<Rect> &posRects, const Rect &negRect, dou | ||
| 336 | return false; | 336 | return false; |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | +Eigen::MatrixXf OpenCVUtils::toEigen(Mat m) { | ||
| 340 | + if (m.type() != CV_32F) | ||
| 341 | + qFatal("Mat to Eigen Converstation only supports CV_32F"); | ||
| 342 | + | ||
| 343 | + Eigen::MatrixXf data(m.rows, m.cols); | ||
| 344 | + return Eigen::Map<const Eigen::MatrixXf>(m.ptr<float>(), m.rows, m.cols); | ||
| 345 | +} | ||
| 346 | + | ||
| 339 | QDataStream &operator<<(QDataStream &stream, const Mat &m) | 347 | QDataStream &operator<<(QDataStream &stream, const Mat &m) |
| 340 | { | 348 | { |
| 341 | // Write header | 349 | // Write header |
openbr/core/opencvutils.h
| @@ -24,6 +24,8 @@ | @@ -24,6 +24,8 @@ | ||
| 24 | #include <opencv2/core/core.hpp> | 24 | #include <opencv2/core/core.hpp> |
| 25 | #include <assert.h> | 25 | #include <assert.h> |
| 26 | 26 | ||
| 27 | +#include <Eigen/Core> | ||
| 28 | + | ||
| 27 | namespace OpenCVUtils | 29 | namespace OpenCVUtils |
| 28 | { | 30 | { |
| 29 | // Test/write/display image | 31 | // Test/write/display image |
| @@ -91,6 +93,7 @@ namespace OpenCVUtils | @@ -91,6 +93,7 @@ namespace OpenCVUtils | ||
| 91 | bool overlaps(const QList<cv::Rect> &posRects, const cv::Rect &negRect, double overlap); | 93 | bool overlaps(const QList<cv::Rect> &posRects, const cv::Rect &negRect, double overlap); |
| 92 | float overlap(const cv::Rect &rect1, const cv::Rect &rect2); | 94 | float overlap(const cv::Rect &rect1, const cv::Rect &rect2); |
| 93 | float overlap(const QRectF &rect1, const QRectF &rect2); | 95 | float overlap(const QRectF &rect1, const QRectF &rect2); |
| 96 | + Eigen::MatrixXf toEigen(cv::Mat m); | ||
| 94 | 97 | ||
| 95 | int getFourcc(); | 98 | int getFourcc(); |
| 96 | } | 99 | } |