Commit 65854488bd77f98d68b41d07c956939bf9be69cb
1 parent
15548017
Added PointsToMatrix and NormalizePoints
Showing
1 changed file
with
48 additions
and
0 deletions
openbr/plugins/landmarks.cpp
| ... | ... | @@ -437,6 +437,54 @@ class AnonymizeLandmarksTransform : public UntrainableMetadataTransform |
| 437 | 437 | |
| 438 | 438 | BR_REGISTER(Transform, AnonymizeLandmarksTransform) |
| 439 | 439 | |
| 440 | +class PointsToMatrixTransform : public UntrainableTransform | |
| 441 | +{ | |
| 442 | + Q_OBJECT | |
| 443 | + | |
| 444 | + Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) | |
| 445 | + BR_PROPERTY(QString, inputVariable, QString()) | |
| 446 | + | |
| 447 | + void project(const Template &src, Template &dst) const | |
| 448 | + { | |
| 449 | + dst = src; | |
| 450 | + | |
| 451 | + if (inputVariable.isEmpty()) { | |
| 452 | + dst.m() = OpenCVUtils::pointsToMatrix(dst.file.points()); | |
| 453 | + } else { | |
| 454 | + if (src.file.contains(inputVariable)) | |
| 455 | + dst.m() = OpenCVUtils::pointsToMatrix(dst.file.get<QList<QPointF> >(inputVariable)); | |
| 456 | + } | |
| 457 | + } | |
| 458 | +}; | |
| 459 | + | |
| 460 | +BR_REGISTER(Transform, PointsToMatrixTransform) | |
| 461 | + | |
| 462 | +class NormalizePointsTransform : public UntrainableTransform | |
| 463 | +{ | |
| 464 | + Q_OBJECT | |
| 465 | + | |
| 466 | + Q_PROPERTY(int index READ get_index WRITE set_index RESET reset_index STORED false) | |
| 467 | + BR_PROPERTY(int, index, 0) | |
| 468 | +; | |
| 469 | + void project(const Template &src, Template &dst) const | |
| 470 | + { | |
| 471 | + dst = src; | |
| 472 | + | |
| 473 | + QList<QPointF> points = dst.file.points(); | |
| 474 | + QPointF normPoint = points.at(index); | |
| 475 | + | |
| 476 | + QList<QPointF> normalizedPoints; | |
| 477 | + normalizedPoints.append(normPoint); | |
| 478 | + for (int i=0; i<points.size(); i++) | |
| 479 | + if (i!=index) | |
| 480 | + normalizedPoints.append(normPoint-points[i]); | |
| 481 | + | |
| 482 | + dst.file.setPoints(normalizedPoints); | |
| 483 | + } | |
| 484 | +}; | |
| 485 | + | |
| 486 | +BR_REGISTER(Transform, NormalizePointsTransform) | |
| 487 | + | |
| 440 | 488 | } // namespace br |
| 441 | 489 | |
| 442 | 490 | #include "landmarks.moc" | ... | ... |