| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2024-11-10 |
| 7 |
* Description : Integrated, multithread face detection / recognition |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2024-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 10 |
* SPDX-FileCopyrightText: 2024-2025 by Michael Miller <michael underscore miller at msn dot com> |
| 11 |
* |
| 12 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 13 |
* |
| 14 |
* ============================================================ */ |
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
// Qt includes |
| 19 |
|
| 20 |
#include <QImage> |
| 21 |
#include <QSemaphore> |
| 22 |
#include <QAtomicInteger> |
| 23 |
#include <QMutex> |
| 24 |
#include <QMutexLocker> |
| 25 |
#include <QThreadPool> |
| 26 |
#include <QFuture> |
| 27 |
#include <QFutureWatcher> |
| 28 |
|
| 29 |
// Local includes |
| 30 |
|
| 31 |
#include "mlpipelinefoundation.h" |
| 32 |
#include "facescansettings.h" |
| 33 |
#include "dnnmodelbase.h" |
| 34 |
|
| 35 |
namespace Digikam |
| 36 |
{ |
| 37 |
|
| 38 |
class FacePipelineBase : public MLPipelineFoundation |
| 39 |
{ |
| 40 |
Q_OBJECT |
| 41 |
|
| 42 |
public: |
| 43 |
|
| 44 |
enum FilterMode |
| 45 |
{ |
| 46 |
/// Will read any given image. |
| 47 |
ScanAll, |
| 48 |
|
| 49 |
/// Scan new images, will skip any image that is already marked as scanned. |
| 50 |
ScanNew, |
| 51 |
|
| 52 |
/// Adds new face(s) to training |
| 53 |
TrainNew, |
| 54 |
|
| 55 |
/// Retrains the face DB |
| 56 |
TrainAll, |
| 57 |
|
| 58 |
/// Removes the face(s) from training |
| 59 |
TrainRemove, |
| 60 |
|
| 61 |
/// Removes all face training, sets all images to not scanned |
| 62 |
TrainReset |
| 63 |
}; |
| 64 |
|
| 65 |
enum WriteMode |
| 66 |
{ |
| 67 |
/// Write results. Merge with existing entries. |
| 68 |
NormalWrite, |
| 69 |
|
| 70 |
/// Add new results. Previous all results will be cleared. |
| 71 |
OverwriteAllFaces, |
| 72 |
|
| 73 |
/// Add new results. Previous unconfirmed results will be cleared. |
| 74 |
OverwriteUnconfirmed |
| 75 |
}; |
| 76 |
|
| 77 |
public: |
| 78 |
|
| 79 |
explicit FacePipelineBase(const FaceScanSettings& _settings); |
| 80 |
virtual ~FacePipelineBase() override; |
| 81 |
|
| 82 |
protected: |
| 83 |
|
| 84 |
DNNModelBase* detectorModel = nullptr; |
| 85 |
double blurThreshold = 4.87F; |
| 86 |
double noiseThreshold1 = 3.7; |
| 87 |
double noiseThreshold2 = 1.89; |
| 88 |
const float minThumbnailSize = 0.4F; |
| 89 |
|
| 90 |
FaceScanSettings settings; |
| 91 |
|
| 92 |
protected: |
| 93 |
|
| 94 |
double detectNoise1(const cv::Mat& cvGrayImage) const; |
| 95 |
double detectNoise2(const cv::Mat& cvGrayImage) const; |
| 96 |
double detectBlur(const cv::Mat& cvGrayImage) const; |
| 97 |
bool useForTraining(const QSize& faceSize, const cv::Mat& image); |
| 98 |
|
| 99 |
bool commonFaceThumbnailLoader(const QString& pipelineName, |
| 100 |
QThread::Priority stagePriority, |
| 101 |
MLPipelineFoundation::MLPipelineStage thisStage, |
| 102 |
MLPipelineFoundation::MLPipelineStage nextStage); |
| 103 |
|
| 104 |
bool commonFaceThumbnailExtractor(const QString& pipelineName, |
| 105 |
QThread::Priority stagePriority, |
| 106 |
MLPipelineFoundation::MLPipelineStage thisStage, |
| 107 |
MLPipelineFoundation::MLPipelineStage nextStage, |
| 108 |
bool trainingQualityCheck = false); |
| 109 |
|
| 110 |
// queue helper functions |
| 111 |
|
| 112 |
bool enqueue(MLPipelineQueue* thisQueue, MLPipelinePackageFoundation* package) override; |
| 113 |
|
| 114 |
private: |
| 115 |
|
| 116 |
/// @note disabled |
| 117 |
|
| 118 |
FacePipelineBase() = delete; |
| 119 |
FacePipelineBase(QObject* const) = delete; |
| 120 |
FacePipelineBase(const FacePipelineBase&) = delete; |
| 121 |
FacePipelineBase& operator=(const FacePipelineBase&) = delete; |
| 122 |
|
| 123 |
private: |
| 124 |
|
| 125 |
static const int BLOCK = 20; |
| 126 |
}; |
| 127 |
|
| 128 |
} // namespace Digikam |