diff --git a/openbr/plugins/crop.cpp b/openbr/plugins/crop.cpp index 01b5167..b62dc67 100644 --- a/openbr/plugins/crop.cpp +++ b/openbr/plugins/crop.cpp @@ -49,6 +49,24 @@ class CropTransform : public UntrainableTransform BR_REGISTER(Transform, CropTransform) + +static QRectF constrainRect(int height, int width, const QRectF &rect) +{ + QRectF newRect = rect; + + // roi.x + roi.width <= m.cols && roi.y + roi.height <= m.rows + + if (rect.x() < 0) newRect.setX(0); + if (rect.y() < 0) newRect.setY(0); + + if ((newRect.y() + rect.width()) > width) newRect.setWidth(width-newRect.y()); + if ((newRect.x() + rect.height()) > height) newRect.setHeight(height-newRect.x()); + + qDebug() << ((newRect.x() + newRect.width()) <= width) << ((newRect.y() + newRect.height()) <= height); + + return newRect; +} + /*! * \ingroup transforms * \brief Crops the rectangular regions of interest. @@ -63,11 +81,13 @@ class ROITransform : public UntrainableTransform void project(const Template &src, Template &dst) const { if (!propName.isEmpty()) { - QRectF rect = src.file.get(propName); + QRectF rect = constrainRect(src.m().rows, src.m().cols, src.file.get(propName)); dst += src.m()(OpenCVUtils::toRect(rect)); } else if (!src.file.rects().empty()) { - foreach (const QRectF &rect, src.file.rects()) - dst += src.m()(OpenCVUtils::toRect(rect)); + foreach (const QRectF &rect, src.file.rects()) { + QRectF newRect = constrainRect(src.m().rows, src.m().cols, rect); + dst += src.m()(OpenCVUtils::toRect(newRect)); + } } else if (src.file.contains(QStringList() << "X" << "Y" << "Width" << "Height")) { dst += src.m()(Rect(src.file.get("X"), src.file.get("Y"), diff --git a/openbr/plugins/landmarks.cpp b/openbr/plugins/landmarks.cpp index 6f9f911..4266c80 100644 --- a/openbr/plugins/landmarks.cpp +++ b/openbr/plugins/landmarks.cpp @@ -372,7 +372,7 @@ BR_REGISTER(Transform, ReadLandmarksTransform) * \brief Name a point/rect * \author Scott Klum \cite sklum */ -class NameLandmarkTransform : public UntrainableMetadataTransform +class NameLandmarksTransform : public UntrainableMetadataTransform { Q_OBJECT Q_PROPERTY(bool point READ get_point WRITE set_point RESET reset_point STORED false) @@ -406,14 +406,14 @@ class NameLandmarkTransform : public UntrainableMetadataTransform } }; -BR_REGISTER(Transform, NameLandmarkTransform) +BR_REGISTER(Transform, NameLandmarksTransform) /*! * \ingroup transforms * \brief Remove a name from a point/rect * \author Scott Klum \cite sklum */ -class AnonymizeLandmarkTransform : public UntrainableMetadataTransform +class AnonymizeLandmarksTransform : public UntrainableMetadataTransform { Q_OBJECT Q_PROPERTY(bool point READ get_point WRITE set_point RESET reset_point STORED false) @@ -435,7 +435,7 @@ class AnonymizeLandmarkTransform : public UntrainableMetadataTransform } }; -BR_REGISTER(Transform, AnonymizeLandmarkTransform) +BR_REGISTER(Transform, AnonymizeLandmarksTransform) } // namespace br