File indexing completed on 2025-01-19 03:57:55
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-09-03 0007 * Description : Face recognition benchmarker 0008 * 0009 * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "recognitionbenchmarker.h" 0017 0018 // Local includes 0019 0020 #include "digikam_debug.h" 0021 #include "tagscache.h" 0022 0023 namespace Digikam 0024 { 0025 0026 RecognitionBenchmarker::Statistics::Statistics() 0027 : knownFaces (0), 0028 correctlyRecognized(0) 0029 { 0030 } 0031 0032 RecognitionBenchmarker::RecognitionBenchmarker(FacePipeline::Private* const dd) 0033 : d(dd) 0034 { 0035 } 0036 0037 /** 0038 * NOTE: Bench performance code. No need i18n here 0039 */ 0040 QString RecognitionBenchmarker::result() const 0041 { 0042 int totalImages = 0; 0043 0044 Q_FOREACH (const Statistics& stat, results) 0045 { 0046 // cppcheck-suppress useStlAlgorithm 0047 totalImages += stat.knownFaces; 0048 } 0049 0050 QString s = QString::fromUtf8("<p>" 0051 "<u>Collection Properties:</u><br/>" 0052 "%1 Images <br/>" 0053 "%2 Identities <br/>" 0054 "</p><p>").arg(totalImages).arg(results.size()); 0055 0056 for (QMap<int, Statistics>::const_iterator it = results.begin() ; 0057 it != results.end() ; ++it) 0058 { 0059 const Statistics& stat = it.value(); 0060 double correctRate = double(stat.correctlyRecognized) / stat.knownFaces; 0061 s += TagsCache::instance()->tagName(it.key()); 0062 s += QString::fromUtf8(": %1 faces, %2 (%3%) correctly recognized<br/>") 0063 .arg(stat.knownFaces).arg(stat.correctlyRecognized).arg(correctRate * 100); 0064 } 0065 0066 s += QLatin1String("</p>"); 0067 0068 return s; 0069 } 0070 0071 // TODO: investigate this method 0072 void RecognitionBenchmarker::process(const FacePipelineExtendedPackage::Ptr& package) 0073 { 0074 FaceUtils utils; 0075 0076 for (int i = 0 ; i < package->databaseFaces.size() ; ++i) 0077 { 0078 Identity identity = utils.identityForTag(package->databaseFaces[i].tagId(), recognizer); 0079 Statistics& result = results[package->databaseFaces[i].tagId()]; 0080 result.knownFaces++; 0081 0082 if (identity == package->recognitionResults[i]) 0083 { 0084 result.correctlyRecognized++; 0085 } 0086 } 0087 0088 Q_EMIT processed(package); 0089 } 0090 0091 } // namespace Digikam 0092 0093 #include "moc_recognitionbenchmarker.cpp"