Debian Codegraph @

core/utilities/facemanagement/bench/recognitionbenchmarker.cpp

raw
1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2010-09-03
7 * Description : Face recognition benchmarker
8 *
9 * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10 * SPDX-FileCopyrightText: 2012-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *
14 * ============================================================ */
15
16 #include "recognitionbenchmarker.h"
17
18 // Local includes
19
20 #include "digikam_debug.h"
21 #include "tagscache.h"
22
23 namespace Digikam
24 {
25
26 RecognitionBenchmarker::RecognitionBenchmarker(FacePipeline::Private* const dd)
27 : d(dd)
28 {
29 }
30
31 /**
32 * NOTE: Bench performance code. No need i18n here
33 */
34 QString RecognitionBenchmarker::result() const
35 {
36 int totalImages = 0;
37
38 for (const Statistics& stat : std::as_const(results))
39 {
40 // cppcheck-suppress useStlAlgorithm
41 totalImages += stat.knownFaces;
42 }
43
44 QString s = QString::fromUtf8("<p>"
45 "<u>Collection Properties:</u><br>"
46 "%1 Images <br>"
47 "%2 Identities <br>"
48 "</p><p>").arg(totalImages).arg(results.size());
49
50 for (QMap<int, Statistics>::const_iterator it = results.begin() ;
51 it != results.end() ; ++it)
52 {
53 const Statistics& stat = it.value();
54 double correctRate = double(stat.correctlyRecognized) / stat.knownFaces;
55 s += TagsCache::instance()->tagName(it.key());
56 s += QString::fromUtf8(": %1 faces, %2 (%3%) correctly recognized<br>")
57 .arg(stat.knownFaces).arg(stat.correctlyRecognized).arg(correctRate * 100);
58 }
59
60 s += QLatin1String("</p>");
61
62 return s;
63 }
64
65 // TODO: investigate this method
66
67 void RecognitionBenchmarker::process(const FacePipelineExtendedPackage::Ptr& package)
68 {
69 FaceUtils utils;
70
71 for (int i = 0 ; i < package->databaseFaces.size() ; ++i)
72 {
73 /*
74 Identity identity = utils.identityForTag(package->databaseFaces[i].tagId(), recognizer);
75 */
76 Identity identity = utils.identityForTag(package->databaseFaces[i].tagId());
77 Statistics& res = results[package->databaseFaces[i].tagId()];
78 res.knownFaces++;
79
80 if (identity == package->recognitionResults[i])
81 {
82 res.correctlyRecognized++;
83 }
84 }
85
86 Q_EMIT processed(package);
87 }
88
89 } // namespace Digikam
90
91 #include "moc_recognitionbenchmarker.cpp"