diff --git a/openbr/core/opencvutils.cpp b/openbr/core/opencvutils.cpp index 7c132db..de70384 100644 --- a/openbr/core/opencvutils.cpp +++ b/openbr/core/opencvutils.cpp @@ -436,15 +436,15 @@ public: }; // TODO: Make sure case where no confidences are inputted works. -void OpenCVUtils::group(vector &rects, vector &confidences, float confidenceThreshold, float epsilon) +void OpenCVUtils::group(QList &rects, QList &confidences, float confidenceThreshold, float epsilon) { - if (rects.empty()) + if (rects.isEmpty()) return; - const bool useConfidences = !confidences.empty(); + const bool useConfidences = !confidences.isEmpty(); vector labels; - int nClasses = cv::partition(rects, labels, SimilarRects(epsilon)); + int nClasses = cv::partition(rects.toVector().toStdVector(), labels, SimilarRects(epsilon)); // Rect for each class (class meaning identity assigned by partition) vector rrects(nClasses); @@ -534,13 +534,65 @@ void OpenCVUtils::group(vector &rects, vector &confidences, float c // Need to return rects and confidences if( j == nClasses ) { - rects.push_back(r1); + rects.append(r1); if (useConfidences) - confidences.push_back(w1); + confidences.append(w1); } } } +void OpenCVUtils::flip(const br::Template &src, br::Template &dst, int axis) +{ + cv::flip(src, dst, axis); + dst.file = src.file; + + QList flippedPoints; + foreach(const QPointF &point, src.file.points()) { + // Check for missing data using the QPointF(-1,-1) convention + if (point != QPointF(-1,-1)) { + if (axis == 0) { + flippedPoints.append(QPointF(point.x(),src.m().rows-point.y())); + } else if (axis == 1) { + flippedPoints.append(QPointF(src.m().cols-point.x(),point.y())); + } else { + flippedPoints.append(QPointF(src.m().cols-point.x(),src.m().rows-point.y())); + } + } + } + + QList flippedRects; + foreach(const QRectF &rect, src.file.rects()) { + if (axis == 0) { + flippedRects.append(QRectF(rect.x(), + src.m().rows-rect.bottom(), + rect.width(), + rect.height())); + } else if (axis == 1) { + flippedRects.append(QRectF(src.m().cols-rect.right(), + rect.y(), + rect.width(), + rect.height())); + } else { + flippedRects.append(QRectF(src.m().cols-rect.right(), + src.m().rows-rect.bottom(), + rect.width(), + rect.height())); + } + } + + dst.file.setPoints(flippedPoints); + dst.file.setRects(flippedRects); +} + +void OpenCVUtils::flip(const br::TemplateList &src, br::TemplateList &dst, int axis) +{ + for (int i=0; i #include #include +#include namespace OpenCVUtils { @@ -101,7 +102,9 @@ namespace OpenCVUtils float overlap(const QRectF &rect1, const QRectF &rect2); // Misc - void group(std::vector &rects, std::vector &confidences, float confidenceThreshold, float epsilon); + void group(QList &rects, QList &confidences, float confidenceThreshold, float epsilon); + void flip(const br::Template &src, br::Template &dst, int axis); + void flip(const br::TemplateList &src, br::TemplateList &dst, int axis); int getFourcc(); } diff --git a/openbr/plugins/imgproc/flip.cpp b/openbr/plugins/imgproc/flip.cpp index b84c08b..33fd48d 100644 --- a/openbr/plugins/imgproc/flip.cpp +++ b/openbr/plugins/imgproc/flip.cpp @@ -15,6 +15,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include +#include namespace br { @@ -41,44 +42,7 @@ private: void project(const Template &src, Template &dst) const { - cv::flip(src, dst, axis); - - QList flippedPoints; - foreach(const QPointF &point, src.file.points()) { - // Check for missing data using the QPointF(-1,-1) convention - if (point != QPointF(-1,-1)) { - if (axis == Y) { - flippedPoints.append(QPointF(src.m().cols-point.x(),point.y())); - } else if (axis == X) { - flippedPoints.append(QPointF(point.x(),src.m().rows-point.y())); - } else { - flippedPoints.append(QPointF(src.m().cols-point.x(),src.m().rows-point.y())); - } - } - } - - QList flippedRects; - foreach(const QRectF &rect, src.file.rects()) { - if (axis == Y) { - flippedRects.append(QRectF(src.m().cols-rect.right(), - rect.y(), - rect.width(), - rect.height())); - } else if (axis == X) { - flippedRects.append(QRectF(rect.x(), - src.m().rows-rect.bottom(), - rect.width(), - rect.height())); - } else { - flippedRects.append(QRectF(src.m().cols-rect.right(), - src.m().rows-rect.bottom(), - rect.width(), - rect.height())); - } - } - - dst.file.setPoints(flippedPoints); - dst.file.setRects(flippedRects); + OpenCVUtils::flip(src,dst,axis); } };