From 0c56c80eefdad3d2abbdc15ace581a8e5d7de392 Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Sun, 14 Jun 2015 13:21:29 -0400 Subject: [PATCH] Don't do an affine wrap with bad points --- openbr/plugins/imgproc/rndaffine.cpp | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/openbr/plugins/imgproc/rndaffine.cpp b/openbr/plugins/imgproc/rndaffine.cpp index 11b2e97..8826dc1 100644 --- a/openbr/plugins/imgproc/rndaffine.cpp +++ b/openbr/plugins/imgproc/rndaffine.cpp @@ -42,29 +42,33 @@ class RndAffineTransform : public UntrainableMetaTransform QPointF affine_0 = t.file.get("Affine_0"); QPointF affine_1 = t.file.get("Affine_1"); - // Append the original points - Template u = t; - u.file.setPoints(QList() << affine_0 << affine_1); - u.file.set("Affine_0", affine_0); - u.file.set("Affine_1", affine_1); - dst.append(u); + if (affine_0 != QPoint(-1,-1) && affine_1 != QPoint(-1,-1)) { + // Append the original points + Template u = t; + u.file.setPoints(QList() << affine_0 << affine_1); + u.file.set("Affine_0", affine_0); + u.file.set("Affine_1", affine_1); + dst.append(u); - const double IPD = sqrt(pow(affine_0.x() - affine_1.x(), 2) + pow(affine_0.y() - affine_1.y(), 2)); - for (int i = 0; i < numAffines; i++) { - int angle = (rand() % (2*maxAngle)) - maxAngle; + const double IPD = sqrt(pow(affine_0.x() - affine_1.x(), 2) + pow(affine_0.y() - affine_1.y(), 2)); + if (IPD != 0) { + for (int i = 0; i < numAffines; i++) { + int angle = (rand() % (2*maxAngle)) - maxAngle; - int min = (int)(sqrt(1 / scaleFactor) * IPD); - int max = (int)(sqrt(scaleFactor) * IPD); - int dx = (rand() % (max - min)) + min; - int dy = (dx * sin(angle * M_PI / 180))/2; + int min = (int)(sqrt(1 / scaleFactor) * IPD); + int max = (int)(sqrt(scaleFactor) * IPD); + int dx = (rand() % (max - min)) + min; + int dy = (dx * sin(angle * M_PI / 180))/2; - QPointF shiftedAffine_0 = QPointF(affine_1.x() - dx, affine_1.y() + dy); + QPointF shiftedAffine_0 = QPointF(affine_1.x() - dx, affine_1.y() + dy); - Template u = t; - u.file.setPoints(QList() << shiftedAffine_0 << affine_1); - u.file.set("Affine_0", shiftedAffine_0); - u.file.set("Affine_1", affine_1); - dst.append(u); + Template u = t; + u.file.setPoints(QList() << shiftedAffine_0 << affine_1); + u.file.set("Affine_0", shiftedAffine_0); + u.file.set("Affine_1", affine_1); + dst.append(u); + } + } } } } -- libgit2 0.21.4