diff --git a/openbr/core/eval.cpp b/openbr/core/eval.cpp index 13f761a..9e813d8 100644 --- a/openbr/core/eval.cpp +++ b/openbr/core/eval.cpp @@ -373,6 +373,8 @@ static QStringList computeDetectionResults(const QList &detec } const int keep = qMin(points.size(), Max_Points); + if (keep < 2) qFatal("Insufficient points."); + QStringList lines; lines.reserve(keep); for (int i=0; i &detec return lines; } +QString getDetectKey(const TemplateList &templates) +{ + const File &f = templates.first().file; + foreach (const QString &key, f.localKeys()) + if (!f.get(key, QRectF()).isNull()) + return key; + return ""; +} + float EvalDetection(const QString &predictedInput, const QString &truthInput, const QString &csv) { qDebug("Evaluating detection of %s against %s", qPrintable(predictedInput), qPrintable(truthInput)); @@ -389,20 +400,22 @@ float EvalDetection(const QString &predictedInput, const QString &truthInput, co const TemplateList truth(TemplateList::fromGallery(truthInput)); // Figure out which metadata field contains a bounding box - QString detectKey; - foreach (const QString &key, truth.first().file.localKeys()) - if (!truth.first().file.get(key, QRectF()).isNull()) { - detectKey = key; - break; - } - if (detectKey.isNull()) qFatal("No suitable metadata key found."); - else qDebug("Using metadata key: %s", qPrintable(detectKey)); + QString truthDetectKey = getDetectKey(truth); + if (truthDetectKey.isEmpty()) qFatal("No suitable ground truth metadata key found."); + QString predictedDetectKey = truthDetectKey; + if (predicted.first().file.get(predictedDetectKey, QRectF()).isNull()) + predictedDetectKey = getDetectKey(predicted); + if (predictedDetectKey.isEmpty()) qFatal("No suitable predicted metadata key found."); + + qDebug("Using metadata key: %s%s", + qPrintable(predictedDetectKey), + qPrintable(predictedDetectKey == truthDetectKey ? QString() : "/"+truthDetectKey)); QMap allDetections; // Organized by file, QMap used to preserve order foreach (const Template &t, predicted) - allDetections[t.file.baseName()].predicted.append(Detection(t.file.get(detectKey), t.file.get("Confidence", -1))); + allDetections[t.file.baseName()].predicted.append(Detection(t.file.get(predictedDetectKey), t.file.get("Confidence", -1))); foreach (const Template &t, truth) - allDetections[t.file.baseName()].truth.append(Detection(t.file.get(detectKey))); + allDetections[t.file.baseName()].truth.append(Detection(t.file.get(truthDetectKey))); QList resolvedDetections, falseNegativeDetections; foreach (Detections detections, allDetections.values()) {