diff --git a/openbr/plugins/regions.cpp b/openbr/plugins/regions.cpp index 317eb54..9e9e92a 100644 --- a/openbr/plugins/regions.cpp +++ b/openbr/plugins/regions.cpp @@ -345,9 +345,12 @@ class RectFromPointsTransform : public UntrainableTransform dst.file.setPoints(points); - if (crop) dst.m() = src.m()(Rect(std::max(0.0, minX - deltaWidth/2.0), std::max(0.0, minY - deltaHeight/2.0), std::min((double)src.m().cols, width), std::min((double)src.m().rows, height))); + const int x = std::max(0.0, minX - deltaWidth/2.0); + const int y = std::max(0.0, minY - deltaHeight/2.0); + + if (crop) dst.m() = src.m()(Rect(x, y, std::min((double)src.m().cols-x, width), std::min((double)src.m().rows-y, height))); else { - dst.file.appendRect(QRectF(std::max(0.0, minX - deltaWidth/2.0), std::max(0.0, minY - deltaHeight/2.0), std::min((double)src.m().cols, width), std::min((double)src.m().rows, height))); + dst.file.appendRect(QRectF(x, y, std::min((double)src.m().cols-x, width), std::min((double)src.m().rows-y, height))); dst.m() = src.m(); } }