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,12 +41,14 @@ class ROITransform : public UntrainableTransform
41 41
42 void project(const Template &src, Template &dst) const 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 QRectF rect = src.file.get<QRectF>(propName); 48 QRectF rect = src.file.get<QRectF>(propName);
46 dst += src.m()(OpenCVUtils::toRect(rect)); 49 dst += src.m()(OpenCVUtils::toRect(rect));
47 } else if (!src.file.rects().empty()) { 50 } else if (!src.file.rects().empty()) {
48 - foreach (const QRectF &rect, src.file.rects())  
49 - dst += src.m()(OpenCVUtils::toRect(rect)); 51 +
50 } else if (src.file.contains(QStringList() << "X" << "Y" << "Width" << "Height")) { 52 } else if (src.file.contains(QStringList() << "X" << "Y" << "Width" << "Height")) {
51 dst += src.m()(Rect(src.file.get<int>("X"), 53 dst += src.m()(Rect(src.file.get<int>("X"),
52 src.file.get<int>("Y"), 54 src.file.get<int>("Y"),
openbr/plugins/metadata/checkrects.cpp
@@ -39,15 +39,15 @@ class CheckRectsTransform : public UntrainableTransform @@ -39,15 +39,15 @@ class CheckRectsTransform : public UntrainableTransform
39 dst.file.clearRects(); 39 dst.file.clearRects();
40 QList<QRectF> rects = src.file.rects(); 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 } else { 51 } else {
52 foreach (QRectF r, rects){ 52 foreach (QRectF r, rects){
53 if ((r.left() < 0) || (r.right() > src.m().cols-1) || (r.top() < 0) || (r.bottom() > src.m().rows-1)){ 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,7 +61,7 @@ class JustTransform : public UntrainableMetaTransform
61 foreach (const QString &key, keys) 61 foreach (const QString &key, keys)
62 if (key == "_Points") { 62 if (key == "_Points") {
63 dst.file.setPoints(tmp.file.points()); 63 dst.file.setPoints(tmp.file.points());
64 - } else { 64 + } else if (tmp.file.contains(key)) {
65 dst.file.set(key, tmp.file.value(key)); 65 dst.file.set(key, tmp.file.value(key));
66 } 66 }
67 } 67 }