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 "recognitionworker.h"
0017 
0018 // Local includes
0019 
0020 #include "digikam_debug.h"
0021 
0022 namespace Digikam
0023 {
0024 
0025 RecognitionWorker::RecognitionWorker(FacePipeline::Private* const dd)
0026     : imageRetriever(dd),
0027       d             (dd)
0028 {
0029 }
0030 
0031 RecognitionWorker::~RecognitionWorker()
0032 {
0033     wait();    // protect database
0034 }
0035 
0036 /**
0037  *TODO: investigate this method
0038  */
0039 void RecognitionWorker::process(const FacePipelineExtendedPackage::Ptr& package)
0040 {
0041     FaceUtils      utils;
0042     QList<QImage*> images;
0043 
0044     if      (package->processFlags & FacePipelinePackage::ProcessedByDetector)
0045     {
0046         // assume we have an image
0047 
0048         images = imageRetriever.getDetails(package->image, package->detectedFaces);
0049     }
0050     else if (!package->databaseFaces.isEmpty())
0051     {
0052         images = imageRetriever.getThumbnails(package->filePath, package->databaseFaces.toFaceTagsIfaceList());
0053     }
0054 
0055     // NOTE: cropped faces will be deleted by training provider
0056 
0057     package->recognitionResults  = recognizer.recognizeFaces(images);
0058     package->processFlags       |= FacePipelinePackage::ProcessedByRecognizer;
0059 
0060     Q_EMIT processed(package);
0061 }
0062 
0063 void RecognitionWorker::setThreshold(double threshold, bool)
0064 {
0065     recognizer.setParameter(QLatin1String("threshold"), threshold);
0066 }
0067 
0068 void RecognitionWorker::aboutToDeactivate()
0069 {
0070     imageRetriever.cancel();
0071 }
0072 
0073 } // namespace Digikam
0074 
0075 #include "moc_recognitionworker.cpp"