Commit 5ba8e4e3a41c963bbcf947e51f248e1a54efa1b1

Authored by Scott Klum
1 parent a64bd9fe

Refactored flip to be an opencv utility

openbr/core/opencvutils.cpp
... ... @@ -436,15 +436,15 @@ public:
436 436 };
437 437  
438 438 // TODO: Make sure case where no confidences are inputted works.
439   -void OpenCVUtils::group(vector<Rect> &rects, vector<float> &confidences, float confidenceThreshold, float epsilon)
  439 +void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float confidenceThreshold, float epsilon)
440 440 {
441   - if (rects.empty())
  441 + if (rects.isEmpty())
442 442 return;
443 443  
444   - const bool useConfidences = !confidences.empty();
  444 + const bool useConfidences = !confidences.isEmpty();
445 445  
446 446 vector<int> labels;
447   - int nClasses = cv::partition(rects, labels, SimilarRects(epsilon));
  447 + int nClasses = cv::partition(rects.toVector().toStdVector(), labels, SimilarRects(epsilon));
448 448  
449 449 // Rect for each class (class meaning identity assigned by partition)
450 450 vector<Rect> rrects(nClasses);
... ... @@ -534,13 +534,65 @@ void OpenCVUtils::group(vector&lt;Rect&gt; &amp;rects, vector&lt;float&gt; &amp;confidences, float c
534 534 // Need to return rects and confidences
535 535 if( j == nClasses )
536 536 {
537   - rects.push_back(r1);
  537 + rects.append(r1);
538 538 if (useConfidences)
539   - confidences.push_back(w1);
  539 + confidences.append(w1);
540 540 }
541 541 }
542 542 }
543 543  
  544 +void OpenCVUtils::flip(const br::Template &src, br::Template &dst, int axis)
  545 +{
  546 + cv::flip(src, dst, axis);
  547 + dst.file = src.file;
  548 +
  549 + QList<QPointF> flippedPoints;
  550 + foreach(const QPointF &point, src.file.points()) {
  551 + // Check for missing data using the QPointF(-1,-1) convention
  552 + if (point != QPointF(-1,-1)) {
  553 + if (axis == 0) {
  554 + flippedPoints.append(QPointF(point.x(),src.m().rows-point.y()));
  555 + } else if (axis == 1) {
  556 + flippedPoints.append(QPointF(src.m().cols-point.x(),point.y()));
  557 + } else {
  558 + flippedPoints.append(QPointF(src.m().cols-point.x(),src.m().rows-point.y()));
  559 + }
  560 + }
  561 + }
  562 +
  563 + QList<QRectF> flippedRects;
  564 + foreach(const QRectF &rect, src.file.rects()) {
  565 + if (axis == 0) {
  566 + flippedRects.append(QRectF(rect.x(),
  567 + src.m().rows-rect.bottom(),
  568 + rect.width(),
  569 + rect.height()));
  570 + } else if (axis == 1) {
  571 + flippedRects.append(QRectF(src.m().cols-rect.right(),
  572 + rect.y(),
  573 + rect.width(),
  574 + rect.height()));
  575 + } else {
  576 + flippedRects.append(QRectF(src.m().cols-rect.right(),
  577 + src.m().rows-rect.bottom(),
  578 + rect.width(),
  579 + rect.height()));
  580 + }
  581 + }
  582 +
  583 + dst.file.setPoints(flippedPoints);
  584 + dst.file.setRects(flippedRects);
  585 +}
  586 +
  587 +void OpenCVUtils::flip(const br::TemplateList &src, br::TemplateList &dst, int axis)
  588 +{
  589 + for (int i=0; i<src.size(); i++) {
  590 + br::Template t;
  591 + flip(src[i], t, axis);
  592 + dst.append(t);
  593 + }
  594 +}
  595 +
544 596 QDataStream &operator<<(QDataStream &stream, const Mat &m)
545 597 {
546 598 // Write header
... ...
openbr/core/opencvutils.h
... ... @@ -24,6 +24,7 @@
24 24 #include <opencv2/core/core.hpp>
25 25 #include <opencv2/ml/ml.hpp>
26 26 #include <assert.h>
  27 +#include <openbr/openbr_plugin.h>
27 28  
28 29 namespace OpenCVUtils
29 30 {
... ... @@ -101,7 +102,9 @@ namespace OpenCVUtils
101 102 float overlap(const QRectF &rect1, const QRectF &rect2);
102 103  
103 104 // Misc
104   - void group(std::vector<cv::Rect> &rects, std::vector<float> &confidences, float confidenceThreshold, float epsilon);
  105 + void group(QList<cv::Rect> &rects, QList<float> &confidences, float confidenceThreshold, float epsilon);
  106 + void flip(const br::Template &src, br::Template &dst, int axis);
  107 + void flip(const br::TemplateList &src, br::TemplateList &dst, int axis);
105 108  
106 109 int getFourcc();
107 110 }
... ...
openbr/plugins/imgproc/flip.cpp
... ... @@ -15,6 +15,7 @@
15 15 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
16 16  
17 17 #include <openbr/plugins/openbr_internal.h>
  18 +#include <openbr/core/opencvutils.h>
18 19  
19 20 namespace br
20 21 {
... ... @@ -41,44 +42,7 @@ private:
41 42  
42 43 void project(const Template &src, Template &dst) const
43 44 {
44   - cv::flip(src, dst, axis);
45   -
46   - QList<QPointF> flippedPoints;
47   - foreach(const QPointF &point, src.file.points()) {
48   - // Check for missing data using the QPointF(-1,-1) convention
49   - if (point != QPointF(-1,-1)) {
50   - if (axis == Y) {
51   - flippedPoints.append(QPointF(src.m().cols-point.x(),point.y()));
52   - } else if (axis == X) {
53   - flippedPoints.append(QPointF(point.x(),src.m().rows-point.y()));
54   - } else {
55   - flippedPoints.append(QPointF(src.m().cols-point.x(),src.m().rows-point.y()));
56   - }
57   - }
58   - }
59   -
60   - QList<QRectF> flippedRects;
61   - foreach(const QRectF &rect, src.file.rects()) {
62   - if (axis == Y) {
63   - flippedRects.append(QRectF(src.m().cols-rect.right(),
64   - rect.y(),
65   - rect.width(),
66   - rect.height()));
67   - } else if (axis == X) {
68   - flippedRects.append(QRectF(rect.x(),
69   - src.m().rows-rect.bottom(),
70   - rect.width(),
71   - rect.height()));
72   - } else {
73   - flippedRects.append(QRectF(src.m().cols-rect.right(),
74   - src.m().rows-rect.bottom(),
75   - rect.width(),
76   - rect.height()));
77   - }
78   - }
79   -
80   - dst.file.setPoints(flippedPoints);
81   - dst.file.setRects(flippedRects);
  45 + OpenCVUtils::flip(src,dst,axis);
82 46 }
83 47 };
84 48  
... ...