Commit bff24ce78c9bf684bf102530822b45564363ccc8
1 parent
7aeb043e
Added pad to opencvutils
Showing
2 changed files
with
38 additions
and
0 deletions
openbr/core/opencvutils.cpp
| ... | ... | @@ -527,6 +527,42 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | +void OpenCVUtils::pad(const br::Template &src, br::Template &dst, bool padMat, const QList<int> &padding, bool padPoints, bool padRects, int border, int value) | |
| 531 | +{ | |
| 532 | + // Padding is expected to be top, bottom, left, right | |
| 533 | + if (padMat) | |
| 534 | + copyMakeBorder(src, dst, padding[0], padding[1], padding[2], padding[3], border, Scalar(value)); | |
| 535 | + else | |
| 536 | + dst = src; | |
| 537 | + | |
| 538 | + if (padPoints) { | |
| 539 | + QList<QPointF> points = src.file.points(); | |
| 540 | + QList<QPointF> paddedPoints; | |
| 541 | + for (int i=0; i<points.size(); i++) | |
| 542 | + paddedPoints.append(points[i] += QPointF(padding[2],padding[0])); | |
| 543 | + dst.file.setPoints(paddedPoints); | |
| 544 | + } | |
| 545 | + | |
| 546 | + if (padRects) { | |
| 547 | + QList<QRectF> rects = src.file.rects(); | |
| 548 | + QList<QRectF> paddedRects; | |
| 549 | + for (int i=0; i<rects.size(); i++) | |
| 550 | + paddedRects.append(rects[i].translated(QPointF(padding[2],padding[0]))); | |
| 551 | + dst.file.setRects(paddedRects); | |
| 552 | + } | |
| 553 | + | |
| 554 | + | |
| 555 | +} | |
| 556 | + | |
| 557 | +void OpenCVUtils::pad(const br::TemplateList &src, br::TemplateList &dst, bool padMat, const QList<int> &padding, bool padPoints, bool padRects, int border, int value) | |
| 558 | +{ | |
| 559 | + for (int i=0; i<src.size(); i++) { | |
| 560 | + br::Template t; | |
| 561 | + pad(src[i], t, padMat, padding, padPoints, padRects, border, value); | |
| 562 | + dst.append(t); | |
| 563 | + } | |
| 564 | +} | |
| 565 | + | |
| 530 | 566 | void OpenCVUtils::rotate(const br::Template &src, br::Template &dst, int degrees, bool rotateMat, bool rotatePoints, bool rotateRects) |
| 531 | 567 | { |
| 532 | 568 | Mat rotMatrix = getRotationMatrix2D(Point2f(src.m().rows/2,src.m().cols/2),degrees,1.0); | ... | ... |
openbr/core/opencvutils.h
| ... | ... | @@ -103,6 +103,8 @@ namespace OpenCVUtils |
| 103 | 103 | |
| 104 | 104 | // Misc |
| 105 | 105 | void group(QList<cv::Rect> &rects, QList<float> &confidences, float confidenceThreshold, int minNeighbors, float epsilon); |
| 106 | + void pad(const br::Template &src, br::Template &dst, bool padMat, const QList<int> &padding, bool padPoints, bool padRects, int border=0, int value=0); | |
| 107 | + void pad(const br::TemplateList &src, br::TemplateList &dst, bool padMat, const QList<int> &padding, bool padPoints, bool padRects, int border=0, int value=0); | |
| 106 | 108 | void rotate(const br::Template &src, br::Template &dst, int degrees, bool rotateMat=true, bool rotatePoints=true, bool rotateRects=true); |
| 107 | 109 | void rotate(const br::TemplateList &src, br::TemplateList &dst, int degrees, bool rotateMat=true, bool rotatePoint=true, bool rotateRects=true); |
| 108 | 110 | void flip(const br::Template &src, br::Template &dst, int axis, bool flipMat=true, bool flipPoints=true, bool flipRects=true); | ... | ... |