Commit d8bd7aaa428aefd9fb508072302420850d18c342
1 parent
726d60d1
Stable texture mapping
Showing
1 changed file
with
31 additions
and
39 deletions
openbr/plugins/landmarks.cpp
| ... | ... | @@ -168,10 +168,6 @@ class ProcrustesAlignTransform : public Transform |
| 168 | 168 | float aspectRatio; |
| 169 | 169 | |
| 170 | 170 | void init() { |
| 171 | - minX = FLT_MAX, | |
| 172 | - minY = FLT_MAX, | |
| 173 | - maxX = -FLT_MAX, | |
| 174 | - maxY = -FLT_MAX; | |
| 175 | 171 | aspectRatio = 0; |
| 176 | 172 | } |
| 177 | 173 | |
| ... | ... | @@ -261,22 +257,40 @@ class ProcrustesAlignTransform : public Transform |
| 261 | 257 | referenceShape = vectorToMatrix(points.rowwise().sum() / points.cols()); |
| 262 | 258 | } |
| 263 | 259 | |
| 264 | - //Choose crop boundaries and adjustments that captures all data | |
| 265 | - for (int i = 0; i < points.rows(); i++) { | |
| 266 | - for (int j = 0; j < points.cols(); j++) { | |
| 260 | + //Choose crop boundaries and adjustments that captures most data | |
| 261 | + MatrixXf minXs(points.cols(),1); | |
| 262 | + MatrixXf minYs(points.cols(),1); | |
| 263 | + MatrixXf maxXs(points.cols(),1); | |
| 264 | + MatrixXf maxYs(points.cols(),1); | |
| 265 | + for (int j = 0; j < points.cols(); j++) { | |
| 266 | + minX = FLT_MAX, | |
| 267 | + minY = FLT_MAX, | |
| 268 | + maxX = -FLT_MAX, | |
| 269 | + maxY = -FLT_MAX; | |
| 270 | + for (int i = 0; i < points.rows(); i++) { | |
| 267 | 271 | if (i % 2 == 0) { |
| 268 | - if (points(i,j) > maxX) | |
| 269 | - maxX = points(i, j); | |
| 270 | - if (points(i,j) < minX) | |
| 271 | - minX = points(i, j); | |
| 272 | + if (points(i,j) > maxX) | |
| 273 | + maxX = points(i, j); | |
| 274 | + if (points(i,j) < minX) | |
| 275 | + minX = points(i, j); | |
| 272 | 276 | } else { |
| 273 | - if (points(i,j) > maxY) | |
| 274 | - maxY = points(i, j); | |
| 275 | - if (points(i,j) < minY) | |
| 276 | - minY = points(i, j); | |
| 277 | + if (points(i,j) > maxY) | |
| 278 | + maxY = points(i, j); | |
| 279 | + if (points(i,j) < minY) | |
| 280 | + minY = points(i, j); | |
| 277 | 281 | } |
| 278 | 282 | } |
| 283 | + | |
| 284 | + minXs(j) = minX; | |
| 285 | + maxXs(j) = maxX; | |
| 286 | + minYs(j) = minY; | |
| 287 | + maxYs(j) = maxY; | |
| 279 | 288 | } |
| 289 | + | |
| 290 | + minX = eigMean(minXs) - 1 * eigStd(minXs); | |
| 291 | + minY = eigMean(minYs) - 1 * eigStd(minYs); | |
| 292 | + maxX = eigMean(maxXs) + 1 * eigStd(maxXs); | |
| 293 | + maxY = eigMean(maxYs) + 1 * eigStd(maxYs); | |
| 280 | 294 | aspectRatio = (maxX - minX) / (maxY - minY); |
| 281 | 295 | } |
| 282 | 296 | |
| ... | ... | @@ -500,7 +514,8 @@ class TextureMapTransform : public UntrainableTransform |
| 500 | 514 | if (points[i].y() > srcMaxY) srcMaxY = points[i].y(); |
| 501 | 515 | } |
| 502 | 516 | |
| 503 | - float padding = (srcMaxX - srcMinX) / 80 * 14; | |
| 517 | + float padding = (srcMaxX - srcMinX) / 80 * 16; | |
| 518 | + //padding = 8; | |
| 504 | 519 | return QRectF(qRound(srcMinX - padding), qRound(srcMinY - padding), qRound(srcMaxX - srcMinX + 2 * padding), qRound(srcMaxY - srcMinY + 2 * padding)); |
| 505 | 520 | } |
| 506 | 521 | |
| ... | ... | @@ -594,7 +609,6 @@ class TextureMapTransform : public UntrainableTransform |
| 594 | 609 | warpAffine(src.m(), buffer, getAffineTransform(srcPoint1, dstPoint1), Size(dstBound.width(), dstBound.height())); |
| 595 | 610 | |
| 596 | 611 | Mat mask = Mat::zeros(dstHeight, dstWidth, CV_8UC1); |
| 597 | - //Mat mask = Mat::zeros(dstHeight, dstWidth, src.m().type()); | |
| 598 | 612 | Point maskPoints[1][3]; |
| 599 | 613 | maskPoints[0][0] = dstPoint1[0]; |
| 600 | 614 | maskPoints[0][1] = dstPoint1[1]; |
| ... | ... | @@ -602,8 +616,6 @@ class TextureMapTransform : public UntrainableTransform |
| 602 | 616 | const Point* ppt = { maskPoints[0] }; |
| 603 | 617 | fillConvexPoly(mask, ppt, 3, Scalar(255, 255, 255), 8); |
| 604 | 618 | |
| 605 | - //dst.m().setTo(buffer, mask); | |
| 606 | - //bitwise_and(buffer, mask, dst.m(), mask); | |
| 607 | 619 | for (int i = 0; i < dstHeight; i++) { |
| 608 | 620 | for (int j = 0; j < dstWidth; j++) { |
| 609 | 621 | if (mask.at<uchar>(i,j) == 255) { |
| ... | ... | @@ -619,31 +631,11 @@ class TextureMapTransform : public UntrainableTransform |
| 619 | 631 | } |
| 620 | 632 | } |
| 621 | 633 | |
| 622 | - //Mat output(dstBound.height(), dstBound.width(), src.m().type()); | |
| 623 | - | |
| 624 | - /* | |
| 625 | - if (i > 0) { | |
| 626 | - Mat overlap; | |
| 627 | - bitwise_and(dst.m(), mask, overlap); | |
| 628 | - mask.setTo(0, overlap != 0); | |
| 629 | - } | |
| 630 | - */ | |
| 631 | - | |
| 632 | - //bitwise_and(buffer,mask,output); | |
| 633 | - //dst.m() += output; | |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | dst.file.clearPoints(); |
| 637 | 637 | dst.file.clearRects(); |
| 638 | 638 | dst.file.setPoints(dstPoints); |
| 639 | - /* | |
| 640 | - qDebug() << "\nSRC=\n" <<srcPoints; | |
| 641 | - qDebug() << "DST=\n" <<dstPoints; | |
| 642 | - qDebug() << "file=\n" <<dst.file.points(); | |
| 643 | - char a; | |
| 644 | - cin >> a; | |
| 645 | - */ | |
| 646 | - | |
| 647 | 639 | } |
| 648 | 640 | }; |
| 649 | 641 | ... | ... |