Commit aff1aa31b7f00fa24b225be3af7438c16b20d53e

Authored by jklontz
2 parents c4d9dfbc 1d591a9f

Merge pull request #90 from biometrics/plotSingleRocPoint

PlotDetection for single roc point
openbr/core/eval.cpp
... ... @@ -384,13 +384,19 @@ static QStringList computeDetectionResults(const QList<ResolvedDetection> &detec
384 384 }
385 385  
386 386 const int keep = qMin(points.size(), Max_Points);
387   - if (keep < 2) qFatal("Insufficient points.");
  387 + if (keep < 1) qFatal("Insufficient points.");
388 388  
389 389 QStringList lines; lines.reserve(keep);
390   - for (int i=0; i<keep; i++) {
391   - const DetectionOperatingPoint &point = points[double(i) / double(keep-1) * double(points.size()-1)];
  390 + if (keep == 1) {
  391 + const DetectionOperatingPoint &point = points[0];
392 392 lines.append(QString("%1ROC, %2, %3").arg(discrete ? "Discrete" : "Continuous", QString::number(point.FalsePositives), QString::number(point.Recall)));
393 393 lines.append(QString("%1PR, %2, %3").arg(discrete ? "Discrete" : "Continuous", QString::number(point.Recall), QString::number(point.Precision)));
  394 + } else {
  395 + for (int i=0; i<keep; i++) {
  396 + const DetectionOperatingPoint &point = points[double(i) / double(keep-1) * double(points.size()-1)];
  397 + lines.append(QString("%1ROC, %2, %3").arg(discrete ? "Discrete" : "Continuous", QString::number(point.FalsePositives), QString::number(point.Recall)));
  398 + lines.append(QString("%1PR, %2, %3").arg(discrete ? "Discrete" : "Continuous", QString::number(point.Recall), QString::number(point.Precision)));
  399 + }
394 400 }
395 401 return lines;
396 402 }
... ...
openbr/core/plot.cpp
... ... @@ -271,6 +271,34 @@ bool Plot(const QStringList &amp;files, const File &amp;destination, bool show)
271 271 return p.finalize(show);
272 272 }
273 273  
  274 +//Check if only one ROC point is in the file
  275 +bool fileHasSinglePoint(const QString &evalFile) {
  276 + QFile file(evalFile);
  277 + bool success = file.open(QFile::ReadOnly);
  278 + if (!success) qFatal("Failed to open %s for reading.", qPrintable(evalFile));
  279 + QStringList lines = QString(file.readAll()).split("\n");
  280 + file.close();
  281 +
  282 + int rocCnt = 0;
  283 + foreach (const QString &line, lines) {
  284 + if (line.contains("DiscreteROC")) {
  285 + rocCnt++;
  286 + }
  287 + if (rocCnt > 1)
  288 + return false;
  289 + }
  290 +
  291 + return true;
  292 +}
  293 +
  294 +//Check all files to see if any single file has only have one ROC point
  295 +bool filesHaveSinglePoint(const QStringList &files) {
  296 + foreach (const File &file, files)
  297 + if (fileHasSinglePoint(file))
  298 + return true;
  299 + return false;
  300 +}
  301 +
274 302 bool PlotDetection(const QStringList &files, const File &destination, bool show)
275 303 {
276 304 qDebug("Plotting %d detection file(s) to %s", files.size(), qPrintable(destination));
... ... @@ -287,8 +315,12 @@ bool PlotDetection(const QStringList &amp;files, const File &amp;destination, bool show)
287 315 "rm(data)\n"
288 316 "\n");
289 317  
  318 + QString plotType("line");
  319 + if (filesHaveSinglePoint(files))
  320 + plotType = QString("point");
  321 +
290 322 foreach (const QString &type, QStringList() << "Discrete" << "Continuous")
291   - p.file.write(qPrintable(QString("qplot(X, Y, data=%1ROC%2").arg(type, (p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : ", geom=\"line\"") +
  323 + p.file.write(qPrintable(QString("qplot(X, Y, data=%1ROC%2").arg(type, (p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : QString(", geom=\"%1\"").arg(plotType)) +
292 324 (p.major.size > 1 ? QString(", colour=factor(%1)").arg(p.major.header) : QString()) +
293 325 (p.minor.size > 1 ? QString(", linetype=factor(%1)").arg(p.minor.header) : QString()) +
294 326 QString(", xlab=\"False Accepts\", ylab=\"True Accept Rate\") + theme_minimal()") +
... ... @@ -297,7 +329,7 @@ bool PlotDetection(const QStringList &amp;files, const File &amp;destination, bool show)
297 329 QString(" + scale_x_log10() + scale_y_continuous(labels=percent) + annotation_logticks(sides=\"b\") + ggtitle(\"%1\")\n\n").arg(type)));
298 330  
299 331 foreach (const QString &type, QStringList() << "Discrete" << "Continuous")
300   - p.file.write(qPrintable(QString("qplot(X, Y, data=%1PR%2").arg(type, (p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : ", geom=\"line\"") +
  332 + p.file.write(qPrintable(QString("qplot(X, Y, data=%1PR%2").arg(type, (p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : QString(", geom=\"%1\"").arg(plotType)) +
301 333 (p.major.size > 1 ? QString(", colour=factor(%1)").arg(p.major.header) : QString()) +
302 334 (p.minor.size > 1 ? QString(", linetype=factor(%1)").arg(p.minor.header) : QString()) +
303 335 QString(", xlab=\"Recall\", ylab=\"Precision\") + theme_minimal()") +
... ...
openbr/plugins/cascade.cpp
... ... @@ -99,6 +99,8 @@ class CascadeTransform : public UntrainableMetaTransform
99 99 Template u(t.file, m);
100 100 if (rejectLevels.size() > j)
101 101 u.file.set("Confidence", rejectLevels[j]*levelWeights[j]);
  102 + else
  103 + u.file.set("Confidence", 1);
102 104 const QRectF rect = OpenCVUtils::fromRect(rects[j]);
103 105 u.file.appendRect(rect);
104 106 u.file.set(model, rect);
... ...