MCPcopy Create free account
hub / github.com/biometrics/openbr / associateGroundTruthDetections

Function associateGroundTruthDetections

openbr/core/eval.cpp:955–1032  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

953}
954
955static int associateGroundTruthDetections(QList<ResolvedDetection> &resolved, QList<ResolvedDetection> &falseNegative, QMap<QString, Detections> &all, QRectF &offsets)
956{
957 float dLeftTotal = 0.0, dRightTotal = 0.0, dTopTotal = 0.0, dBottomTotal = 0.0;
958 int count = 0, totalTrueDetections = 0;
959
960 foreach (Detections detections, all.values()) {
961 totalTrueDetections += detections.truth.size();
962 // Try to associate ground truth detections with predicted detections
963
964 QList<SortedDetection> sortedDetections; sortedDetections.reserve(detections.truth.size() * detections.predicted.size());
965 for (int t = 0; t < detections.truth.size(); t++) {
966 const Detection truth = detections.truth[t];
967 for (int p = 0; p < detections.predicted.size(); p++) {
968 Detection predicted = detections.predicted[p];
969
970 float predictedWidth = predicted.boundingBox.width();
971 float x, y, width, height;
972 x = predicted.boundingBox.x() + offsets.x()*predictedWidth;
973 y = predicted.boundingBox.y() + offsets.y()*predictedWidth;
974 width = predicted.boundingBox.width() - offsets.width()*predictedWidth;
975 height = predicted.boundingBox.height() - offsets.height()*predictedWidth;
976 Detection newPredicted(QRectF(x, y, width, height), 0.0);
977
978 const float overlap = truth.overlap(newPredicted);
979 if (overlap > 0)
980 sortedDetections.append(SortedDetection(t, p, overlap));
981 }
982 }
983
984 std::sort(sortedDetections.begin(), sortedDetections.end());
985
986 QList<int> removedTruth;
987 QList<int> removedPredicted;
988
989 foreach (const SortedDetection &detection, sortedDetections) {
990 if (removedTruth.contains(detection.truth_idx) || removedPredicted.contains(detection.predicted_idx))
991 continue;
992
993 const Detection truth = detections.truth[detection.truth_idx];
994 const Detection predicted = detections.predicted[detection.predicted_idx];
995
996 if (!truth.ignore) resolved.append(ResolvedDetection(predicted.confidence, detection.overlap));
997
998 removedTruth.append(detection.truth_idx);
999 removedPredicted.append(detection.predicted_idx);
1000
1001 if (offsets.x() == 0 && detection.overlap > 0.3) {
1002 count++;
1003 float width = predicted.boundingBox.width();
1004 dLeftTotal += (truth.boundingBox.left() - predicted.boundingBox.left()) / width;
1005 dRightTotal += (truth.boundingBox.right() - predicted.boundingBox.right()) / width;
1006 dTopTotal += (truth.boundingBox.top() - predicted.boundingBox.top()) / width;
1007 dBottomTotal += (truth.boundingBox.bottom() - predicted.boundingBox.bottom()) / width;
1008 }
1009 }
1010
1011 for (int i = 0; i < detections.predicted.size(); i++)
1012 if (!removedPredicted.contains(i)) resolved.append(ResolvedDetection(detections.predicted[i].confidence, 0));

Callers 1

EvalDetectionFunction · 0.85

Calls 1

xMethod · 0.45

Tested by

no test coverage detected