Commit 41805575210bd6cc52e739f826114c83554ef03e

Authored by Josh Klontz
1 parent eb260b02

first pass at evalLandmarking

Showing 1 changed file with 42 additions and 6 deletions
openbr/core/eval.cpp
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 #include "bee.h" 17 #include "bee.h"
18 #include "eval.h" 18 #include "eval.h"
  19 +#include "openbr/core/common.h"
19 #include "openbr/core/qtutils.h" 20 #include "openbr/core/qtutils.h"
20 21
21 using namespace cv; 22 using namespace cv;
@@ -478,13 +479,48 @@ float EvalDetection(const QString &predictedGallery, const QString &truthGallery @@ -478,13 +479,48 @@ float EvalDetection(const QString &predictedGallery, const QString &truthGallery
478 479
479 float EvalLandmarking(const QString &predictedGallery, const QString &truthGallery, const QString &csv, int normalizationIndexA, int normalizationIndexB) 480 float EvalLandmarking(const QString &predictedGallery, const QString &truthGallery, const QString &csv, int normalizationIndexA, int normalizationIndexB)
480 { 481 {
481 - (void) predictedGallery;  
482 - (void) truthGallery;  
483 - (void) csv;  
484 - (void) normalizationIndexA;  
485 - (void) normalizationIndexB; 482 + qDebug("Evaluating landmarking of %s against %s", qPrintable(predictedGallery), qPrintable(truthGallery));
  483 + const TemplateList predicted(TemplateList::fromGallery(predictedGallery));
  484 + const TemplateList truth(TemplateList::fromGallery(truthGallery));
  485 + const QStringList predictedNames = File::get<QString>(predicted, "name");
  486 + const QStringList truthNames = File::get<QString>(truth, "name");
  487 +
  488 + QList< QList<float> > pointErrors;
  489 + for (int i=0; i<predicted.size(); i++) {
  490 + const QString &predictedName = predictedNames[i];
  491 + const int truthIndex = truthNames.indexOf(predictedName);
  492 + if (truthIndex == -1) qFatal("Could not identify ground truth for file: %s", qPrintable(predictedName));
  493 + const QList<QPointF> predictedPoints = predicted[i].file.points();
  494 + const QList<QPointF> truthPoints = truth[truthIndex].file.points();
  495 + if (predictedPoints.size() != truthPoints.size()) qFatal("Points size mismatch for file: %s", qPrintable(predictedName));
  496 + while (pointErrors.size() < predictedPoints.size())
  497 + pointErrors.append(QList<float>());
  498 + if (normalizationIndexA >= truthPoints.size()) qFatal("Normalization index A is out of range.");
  499 + if (normalizationIndexB >= truthPoints.size()) qFatal("Normalization index B is out of range.");
  500 + const float normalizedLength = QtUtils::euclideanLength(truthPoints[normalizationIndexB] - truthPoints[normalizationIndexA]);
  501 + for (int j=0; j<predictedPoints.size(); j++)
  502 + pointErrors[j].append(QtUtils::euclideanLength(predictedPoints[j] - truthPoints[j])/normalizedLength);
  503 + }
  504 +
  505 + QList<float> averagePointErrors; averagePointErrors.reserve(pointErrors.size());
  506 + for (int i=0; i<pointErrors.size(); i++) {
  507 + std::sort(pointErrors[i].begin(), pointErrors[i].end());
  508 + averagePointErrors.append(Common::Mean(pointErrors[i]));
  509 + }
  510 + const float averagePointError = Common::Mean(averagePointErrors);
  511 +
  512 + QStringList lines;
  513 + lines.append("Plot,X,Y");
  514 + for (int i=0; i<pointErrors.size(); i++) {
  515 + const QList<float> &pointError = pointErrors[i];
  516 + const int keep = qMin(Max_Points, pointError.size());
  517 + for (int j=0; j<keep; j++)
  518 + lines.append(QString("Box,%1,%2").arg(QString::number(i), QString::number(pointError[j*(pointError.size()-1)/(keep-1)])));
  519 + }
486 520
487 - return 0; 521 + QtUtils::writeFile(csv, lines);
  522 + qDebug("Average Error: %.3f", averagePointError);
  523 + return averagePointError;
488 } 524 }
489 525
490 void EvalRegression(const QString &predictedGallery, const QString &truthGallery, QString predictedProperty, QString truthProperty) 526 void EvalRegression(const QString &predictedGallery, const QString &truthGallery, QString predictedProperty, QString truthProperty)