Commit 915787e3e588dba34c57dfdc99b85b6daa09c44e

Authored by Josh Klontz
1 parent 3b5e183c

fixed some edge cases in ROI propagation

openbr/plugins/imgproc/roi.cpp
... ... @@ -41,12 +41,14 @@ class ROITransform : public UntrainableTransform
41 41  
42 42 void project(const Template &src, Template &dst) const
43 43 {
44   - if (!propName.isEmpty()) {
  44 + if ((propName == "Rects") || !src.file.rects().empty()) {
  45 + foreach (const QRectF &rect, src.file.rects())
  46 + dst += src.m()(OpenCVUtils::toRect(rect));
  47 + } else if (!propName.isEmpty()) {
45 48 QRectF rect = src.file.get<QRectF>(propName);
46 49 dst += src.m()(OpenCVUtils::toRect(rect));
47 50 } else if (!src.file.rects().empty()) {
48   - foreach (const QRectF &rect, src.file.rects())
49   - dst += src.m()(OpenCVUtils::toRect(rect));
  51 +
50 52 } else if (src.file.contains(QStringList() << "X" << "Y" << "Width" << "Height")) {
51 53 dst += src.m()(Rect(src.file.get<int>("X"),
52 54 src.file.get<int>("Y"),
... ...
openbr/plugins/metadata/checkrects.cpp
... ... @@ -39,15 +39,15 @@ class CheckRectsTransform : public UntrainableTransform
39 39 dst.file.clearRects();
40 40 QList<QRectF> rects = src.file.rects();
41 41  
42   - if (fixRects){
43   - for (int i=0; i<rects.size(); i++) {
44   - QRectF r = rects[i];
45   - if (r.left() < 0) r.moveLeft(0);
46   - if (r.right() > src.m().cols-1) r.moveRight(src.m().cols-1);
47   - if (r.top() < 0) r.moveTop(0);
48   - if (r.bottom() > src.m().rows-1) r.moveBottom(src.m().rows-1);
49   - dst.file.appendRect(r);
50   - }
  42 + if (fixRects) {
  43 + foreach (QRectF r, rects)
  44 + if ((r.height() <= src.m().rows) && (r.width() <= src.m().cols)) /* can't fix rects that don't fit the image */ {
  45 + if (r.left() < 0) r.moveLeft(0);
  46 + if (r.right() > src.m().cols-1) r.moveRight(src.m().cols-1);
  47 + if (r.top() < 0) r.moveTop(0);
  48 + if (r.bottom() > src.m().rows-1) r.moveBottom(src.m().rows-1);
  49 + dst.file.appendRect(r);
  50 + }
51 51 } else {
52 52 foreach (QRectF r, rects){
53 53 if ((r.left() < 0) || (r.right() > src.m().cols-1) || (r.top() < 0) || (r.bottom() > src.m().rows-1)){
... ...
openbr/plugins/metadata/savemat.cpp
... ... @@ -61,7 +61,7 @@ class JustTransform : public UntrainableMetaTransform
61 61 foreach (const QString &key, keys)
62 62 if (key == "_Points") {
63 63 dst.file.setPoints(tmp.file.points());
64   - } else {
  64 + } else if (tmp.file.contains(key)) {
65 65 dst.file.set(key, tmp.file.value(key));
66 66 }
67 67 }
... ...