Commit f0af46eb7701552ebc8e46c994a5e1826b99670f

Authored by Brendan Klare
1 parent 54a98a97

Various helper functions

openbr/core/eigenutils.cpp
... ... @@ -36,6 +36,15 @@ void writeEigen(VectorXd X, QString filename) {
36 36 format->write(br::Template(m));
37 37 }
38 38  
  39 +void writeEigen(VectorXf X, QString filename) {
  40 + Mat m(X.size(),1,CV_32FC1);
  41 + for (int i = 0; i < X.rows(); i++) {
  42 + m.at<float>(i,0) = X(i);
  43 + }
  44 + QScopedPointer<br::Format> format(br::Factory<br::Format>::make(filename));
  45 + format->write(br::Template(m));
  46 +}
  47 +
39 48 void printEigen(Eigen::MatrixXd X) {
40 49 for (int i = 0; i < X.rows(); i++) {
41 50 QString str;
... ...
openbr/core/eigenutils.h
... ... @@ -24,6 +24,7 @@
24 24 void writeEigen(Eigen::MatrixXf X, QString filename);
25 25 void writeEigen(Eigen::MatrixXd X, QString filename);
26 26 void writeEigen(Eigen::VectorXd X, QString filename);
  27 +void writeEigen(Eigen::VectorXf X, QString filename);
27 28 void printEigen(Eigen::MatrixXd X);
28 29  
29 30 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
... ...
openbr/core/opencvutils.cpp
... ... @@ -300,6 +300,30 @@ QList&lt;QRectF&gt; OpenCVUtils::fromRects(const QList&lt;Rect&gt; &amp;cvRects)
300 300 return qRects;
301 301 }
302 302  
  303 +float OpenCVUtils::overlap(const Rect &rect1, const Rect &rect2) {
  304 + float left = max(rect1.x, rect2.x);
  305 + float top = max(rect1.y, rect2.y);
  306 + float right = min(rect1.x + rect1.width, rect2.x + rect2.width);
  307 + float bottom = min(rect1.y + rect1.height, rect2.y + rect2.height);
  308 +
  309 + float overlap = (right - left + 1) * (top - bottom + 1) / max(rect1.width * rect1.height, rect2.width * rect2.height);
  310 + if (overlap < 0)
  311 + return 0;
  312 + return overlap;
  313 +}
  314 +
  315 +float OpenCVUtils::overlap(const QRectF &rect1, const QRectF &rect2) {
  316 + float left = max(rect1.x(), rect2.x());
  317 + float top = max(rect1.y(), rect2.y());
  318 + float right = min(rect1.x() + rect1.width(), rect2.x() + rect2.width());
  319 + float bottom = min(rect1.y() + rect1.height(), rect2.y() + rect2.height());
  320 +
  321 + float overlap = (right - left + 1) * (top - bottom + 1) / max(rect1.width() * rect1.height(), rect2.width() * rect2.height());
  322 + if (overlap < 0)
  323 + return 0;
  324 + return overlap;
  325 +}
  326 +
303 327 bool OpenCVUtils::overlaps(const QList<Rect> &posRects, const Rect &negRect, double overlap)
304 328 {
305 329 foreach (const Rect &posRect, posRects) {
... ...
openbr/core/opencvutils.h
... ... @@ -88,6 +88,8 @@ namespace OpenCVUtils
88 88 QList<cv::Rect> toRects(const QList<QRectF> &qRects);
89 89 QList<QRectF> fromRects(const QList<cv::Rect> &cvRects);
90 90 bool overlaps(const QList<cv::Rect> &posRects, const cv::Rect &negRect, double overlap);
  91 + float overlap(const cv::Rect &rect1, const cv::Rect &rect2);
  92 + float overlap(const QRectF &rect1, const QRectF &rect2);
91 93  
92 94 int getFourcc();
93 95 }
... ...
openbr/plugins/template.cpp
... ... @@ -70,6 +70,45 @@ class RemoveMetadataTransform : public UntrainableTransform
70 70 };
71 71 BR_REGISTER(Transform, RemoveMetadataTransform)
72 72  
  73 +/*!
  74 + * \ingroup transforms
  75 + * \brief Retains only landmarks/points at the provided indices
  76 + * \author Brendan Klare \cite bklare
  77 + */
  78 +class SelectPointsTransform : public UntrainableTransform
  79 +{
  80 + Q_OBJECT
  81 + Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false)
  82 + BR_PROPERTY(QList<int>, indices, QList<int>())
  83 +
  84 + void project(const Template &src, Template &dst) const
  85 + {
  86 + dst = src;
  87 + QList<QPointF> origPoints = src.file.points();
  88 + dst.file.clearPoints();
  89 + for (int i = 0; i < indices.size(); i++)
  90 + dst.file.appendPoint(origPoints[indices[i]]);
  91 + }
  92 +};
  93 +
  94 +BR_REGISTER(Transform, SelectPointsTransform)
  95 +
  96 +/*!
  97 + * \ingroup transforms
  98 + * \brief Does nothing.
  99 + */
  100 +class NoneTransform : public UntrainableMetaTransform
  101 +{
  102 + Q_OBJECT
  103 +
  104 + void project(const Template &src, Template &dst) const
  105 + {
  106 + dst = src;
  107 + }
  108 +};
  109 +
  110 +BR_REGISTER(Transform, NoneTransform)
  111 +
73 112 } // namespace br
74 113  
75 114 #include "template.moc"
... ...