Commit eb20e848dc7709ccacd1b6f35d64c471b66c2d6d

Authored by Scott Klum
1 parent 7f659144

Generalized name/anonymize transforms

Showing 1 changed file with 31 additions and 13 deletions
openbr/plugins/landmarks.cpp
@@ -369,12 +369,14 @@ BR_REGISTER(Transform, ReadLandmarksTransform) @@ -369,12 +369,14 @@ BR_REGISTER(Transform, ReadLandmarksTransform)
369 369
370 /*! 370 /*!
371 * \ingroup transforms 371 * \ingroup transforms
372 - * \brief Name a point 372 + * \brief Name a point/rect
373 * \author Scott Klum \cite sklum 373 * \author Scott Klum \cite sklum
374 */ 374 */
375 -class NamePointsTransform : public UntrainableMetadataTransform 375 +class NameLandmarkTransform : public UntrainableMetadataTransform
376 { 376 {
377 Q_OBJECT 377 Q_OBJECT
  378 + Q_PROPERTY(bool point READ get_point WRITE set_point RESET reset_point STORED false)
  379 + BR_PROPERTY(bool, point, true)
378 Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false) 380 Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false)
379 Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false) 381 Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false)
380 BR_PROPERTY(QList<int>, indices, QList<int>()) 382 BR_PROPERTY(QList<int>, indices, QList<int>())
@@ -382,29 +384,40 @@ class NamePointsTransform : public UntrainableMetadataTransform @@ -382,29 +384,40 @@ class NamePointsTransform : public UntrainableMetadataTransform
382 384
383 void projectMetadata(const File &src, File &dst) const 385 void projectMetadata(const File &src, File &dst) const
384 { 386 {
385 - if (indices.size() != names.size()) qFatal("Point/name size mismatch"); 387 + if (indices.size() != names.size()) qFatal("Index/name size mismatch");
386 388
387 dst = src; 389 dst = src;
388 390
389 - QList<QPointF> points = src.points(); 391 + if (point) {
  392 + QList<QPointF> points = src.points();
390 393
391 - for (int i=0; i<indices.size(); i++) {  
392 - if (indices[i] < points.size()) dst.set(names[i], points[indices[i]]);  
393 - else qFatal("Index out of range."); 394 + for (int i=0; i<indices.size(); i++) {
  395 + if (indices[i] < points.size()) dst.set(names[i], points[indices[i]]);
  396 + else qFatal("Index out of range.");
  397 + }
  398 + } else {
  399 + QList<QRectF> rects = src.rects();
  400 +
  401 + for (int i=0; i<indices.size(); i++) {
  402 + if (indices[i] < rects.size()) dst.set(names[i], rects[indices[i]]);
  403 + else qFatal("Index out of range.");
  404 + }
394 } 405 }
395 } 406 }
396 }; 407 };
397 408
398 -BR_REGISTER(Transform, NamePointsTransform) 409 +BR_REGISTER(Transform, NameLandmarkTransform)
399 410
400 /*! 411 /*!
401 * \ingroup transforms 412 * \ingroup transforms
402 - * \brief Remove a name from a point 413 + * \brief Remove a name from a point/rect
403 * \author Scott Klum \cite sklum 414 * \author Scott Klum \cite sklum
404 */ 415 */
405 -class AnonymizePointsTransform : public UntrainableMetadataTransform 416 +class AnonymizeLandmarkTransform : public UntrainableMetadataTransform
406 { 417 {
407 Q_OBJECT 418 Q_OBJECT
  419 + Q_PROPERTY(bool point READ get_point WRITE set_point RESET reset_point STORED false)
  420 + BR_PROPERTY(bool, point, true)
408 Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false) 421 Q_PROPERTY(QStringList names READ get_names WRITE set_names RESET reset_names STORED false)
409 BR_PROPERTY(QStringList, names, QStringList()) 422 BR_PROPERTY(QStringList, names, QStringList())
410 423
@@ -412,12 +425,17 @@ class AnonymizePointsTransform : public UntrainableMetadataTransform @@ -412,12 +425,17 @@ class AnonymizePointsTransform : public UntrainableMetadataTransform
412 { 425 {
413 dst = src; 426 dst = src;
414 427
415 - foreach (const QString &name, names)  
416 - if (src.contains(name)) dst.appendPoint(src.get<QPointF>(name)); 428 + if (point) {
  429 + foreach (const QString &name, names)
  430 + if (src.contains(name)) dst.appendPoint(src.get<QPointF>(name));
  431 + } else {
  432 + foreach (const QString &name, names)
  433 + if (src.contains(name)) dst.appendRect(src.get<QRectF>(name));
  434 + }
417 } 435 }
418 }; 436 };
419 437
420 -BR_REGISTER(Transform, AnonymizePointsTransform) 438 +BR_REGISTER(Transform, AnonymizeLandmarkTransform)
421 439
422 } // namespace br 440 } // namespace br
423 441