From ac231de541a0482c5cd462f480ac02903dcfb853 Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Wed, 16 Sep 2015 11:44:49 -0400 Subject: [PATCH] Minor flip optimizations --- openbr/core/opencvutils.cpp | 76 +++++++++++++++++++++++++++++++++++++++++----------------------------------- openbr/core/opencvutils.h | 4 ++-- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/openbr/core/opencvutils.cpp b/openbr/core/opencvutils.cpp index de70384..cb20741 100644 --- a/openbr/core/opencvutils.cpp +++ b/openbr/core/opencvutils.cpp @@ -541,54 +541,60 @@ void OpenCVUtils::group(QList &rects, QList &confidences, float con } } -void OpenCVUtils::flip(const br::Template &src, br::Template &dst, int axis) +void OpenCVUtils::flip(const br::Template &src, br::Template &dst, int axis, bool flipMat, bool flipPoints, bool flipRects) { - cv::flip(src, dst, axis); - dst.file = src.file; + if (flipMat) { + cv::flip(src, dst, axis); + dst.file = src.file; + } else + dst = src; - 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())); + if (flipPoints) { + 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())); + } } } + dst.file.setPoints(flippedPoints); } - 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())); + if (flipRects) { + 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.setRects(flippedRects); } - - dst.file.setPoints(flippedPoints); - dst.file.setRects(flippedRects); } -void OpenCVUtils::flip(const br::TemplateList &src, br::TemplateList &dst, int axis) +void OpenCVUtils::flip(const br::TemplateList &src, br::TemplateList &dst, int axis, bool flipMat, bool flipPoints, bool flipRects) { for (int i=0; i &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); + void flip(const br::Template &src, br::Template &dst, int axis, bool flipMat=true, bool flipPoints=true, bool flipRects=true); + void flip(const br::TemplateList &src, br::TemplateList &dst, int axis, bool flipMat=true, bool flipPoints=true, bool flipRects=true); int getFourcc(); } -- libgit2 0.21.4