File indexing completed on 2025-01-19 03:57:57
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-09-03 0007 * Description : Integrated, multithread face detection / recognition 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 "detectionworker.h" 0017 0018 // Local includes 0019 0020 #include "digikam_debug.h" 0021 0022 namespace Digikam 0023 { 0024 0025 DetectionWorker::DetectionWorker(FacePipeline::Private* const dd) 0026 : d(dd) 0027 { 0028 } 0029 0030 DetectionWorker::~DetectionWorker() 0031 { 0032 wait(); // protect detector 0033 } 0034 0035 void DetectionWorker::process(const FacePipelineExtendedPackage::Ptr& package) 0036 { 0037 if (!package->image.isNull()) 0038 { 0039 /* 0040 QImage detectionImage = scaleForDetection(package->image); 0041 package->detectedFaces = detector.detectFaces(detectionImage, package->image.originalSize()); 0042 */ 0043 package->detectedFaces = detector.detectFaces(package->image); 0044 0045 qCDebug(DIGIKAM_GENERAL_LOG) << "Found" << package->detectedFaces.size() << "faces in" 0046 << package->info.name() << package->image.size() 0047 << package->image.originalSize(); 0048 } 0049 0050 package->processFlags |= FacePipelinePackage::ProcessedByDetector; 0051 0052 Q_EMIT processed(package); 0053 } 0054 0055 QImage DetectionWorker::scaleForDetection(const DImg& image) const 0056 { 0057 int recommendedSize = detector.recommendedImageSize(image.size()); 0058 0059 if (qMax(image.width(), image.height()) > (uint)recommendedSize) 0060 { 0061 return image.smoothScale(recommendedSize, recommendedSize, Qt::KeepAspectRatio).copyQImage(); 0062 } 0063 0064 return image.copyQImage(); 0065 } 0066 0067 void DetectionWorker::setAccuracyAndModel(double accuracy, bool yolo) 0068 { 0069 QVariantMap params; 0070 params[QLatin1String("accuracy")] = accuracy; 0071 params[QLatin1String("useyolov3")] = yolo; 0072 params[QLatin1String("specificity")] = 0.8; // TODO: add UI for sensitivity - specificity 0073 detector.setParameters(params); 0074 } 0075 0076 } // namespace Digikam 0077 0078 #include "moc_detectionworker.cpp"