Commit ac231de541a0482c5cd462f480ac02903dcfb853
1 parent
86cffac4
Minor flip optimizations
Showing
2 changed files
with
43 additions
and
37 deletions
openbr/core/opencvutils.cpp
| @@ -541,54 +541,60 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con | @@ -541,54 +541,60 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con | ||
| 541 | } | 541 | } |
| 542 | } | 542 | } |
| 543 | 543 | ||
| 544 | -void OpenCVUtils::flip(const br::Template &src, br::Template &dst, int axis) | 544 | +void OpenCVUtils::flip(const br::Template &src, br::Template &dst, int axis, bool flipMat, bool flipPoints, bool flipRects) |
| 545 | { | 545 | { |
| 546 | - cv::flip(src, dst, axis); | ||
| 547 | - dst.file = src.file; | 546 | + if (flipMat) { |
| 547 | + cv::flip(src, dst, axis); | ||
| 548 | + dst.file = src.file; | ||
| 549 | + } else | ||
| 550 | + dst = src; | ||
| 548 | 551 | ||
| 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())); | 552 | + if (flipPoints) { |
| 553 | + QList<QPointF> flippedPoints; | ||
| 554 | + foreach(const QPointF &point, src.file.points()) { | ||
| 555 | + // Check for missing data using the QPointF(-1,-1) convention | ||
| 556 | + if (point != QPointF(-1,-1)) { | ||
| 557 | + if (axis == 0) { | ||
| 558 | + flippedPoints.append(QPointF(point.x(),src.m().rows-point.y())); | ||
| 559 | + } else if (axis == 1) { | ||
| 560 | + flippedPoints.append(QPointF(src.m().cols-point.x(),point.y())); | ||
| 561 | + } else { | ||
| 562 | + flippedPoints.append(QPointF(src.m().cols-point.x(),src.m().rows-point.y())); | ||
| 563 | + } | ||
| 559 | } | 564 | } |
| 560 | } | 565 | } |
| 566 | + dst.file.setPoints(flippedPoints); | ||
| 561 | } | 567 | } |
| 562 | 568 | ||
| 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())); | 569 | + if (flipRects) { |
| 570 | + QList<QRectF> flippedRects; | ||
| 571 | + foreach(const QRectF &rect, src.file.rects()) { | ||
| 572 | + if (axis == 0) { | ||
| 573 | + flippedRects.append(QRectF(rect.x(), | ||
| 574 | + src.m().rows-rect.bottom(), | ||
| 575 | + rect.width(), | ||
| 576 | + rect.height())); | ||
| 577 | + } else if (axis == 1) { | ||
| 578 | + flippedRects.append(QRectF(src.m().cols-rect.right(), | ||
| 579 | + rect.y(), | ||
| 580 | + rect.width(), | ||
| 581 | + rect.height())); | ||
| 582 | + } else { | ||
| 583 | + flippedRects.append(QRectF(src.m().cols-rect.right(), | ||
| 584 | + src.m().rows-rect.bottom(), | ||
| 585 | + rect.width(), | ||
| 586 | + rect.height())); | ||
| 587 | + } | ||
| 580 | } | 588 | } |
| 589 | + dst.file.setRects(flippedRects); | ||
| 581 | } | 590 | } |
| 582 | - | ||
| 583 | - dst.file.setPoints(flippedPoints); | ||
| 584 | - dst.file.setRects(flippedRects); | ||
| 585 | } | 591 | } |
| 586 | 592 | ||
| 587 | -void OpenCVUtils::flip(const br::TemplateList &src, br::TemplateList &dst, int axis) | 593 | +void OpenCVUtils::flip(const br::TemplateList &src, br::TemplateList &dst, int axis, bool flipMat, bool flipPoints, bool flipRects) |
| 588 | { | 594 | { |
| 589 | for (int i=0; i<src.size(); i++) { | 595 | for (int i=0; i<src.size(); i++) { |
| 590 | br::Template t; | 596 | br::Template t; |
| 591 | - flip(src[i], t, axis); | 597 | + flip(src[i], t, axis, flipMat, flipPoints, flipRects); |
| 592 | dst.append(t); | 598 | dst.append(t); |
| 593 | } | 599 | } |
| 594 | } | 600 | } |
openbr/core/opencvutils.h
| @@ -103,8 +103,8 @@ namespace OpenCVUtils | @@ -103,8 +103,8 @@ namespace OpenCVUtils | ||
| 103 | 103 | ||
| 104 | // Misc | 104 | // Misc |
| 105 | void group(QList<cv::Rect> &rects, QList<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); | 106 | + void flip(const br::Template &src, br::Template &dst, int axis, bool flipMat=true, bool flipPoints=true, bool flipRects=true); |
| 107 | + void flip(const br::TemplateList &src, br::TemplateList &dst, int axis, bool flipMat=true, bool flipPoints=true, bool flipRects=true); | ||
| 108 | 108 | ||
| 109 | int getFourcc(); | 109 | int getFourcc(); |
| 110 | } | 110 | } |