| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2010-08-08 |
| 7 |
* Description : FacesEngine database interface allowing easy manipulation of face tags |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2010-2011 by Aditya Bhatt <adityabhatt1991 at gmail dot com> |
| 10 |
* SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> |
| 11 |
* SPDX-FileCopyrightText: 2012-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 12 |
* SPDX-FileCopyrightText: 2024-2025 by Michael Miller <michael underscore miller at msn dot com> |
| 13 |
* |
| 14 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 15 |
* |
| 16 |
* ============================================================ */ |
| 17 |
|
| 18 |
#pragma once |
| 19 |
|
| 20 |
// Qt includes |
| 21 |
|
| 22 |
#include <QStringList> |
| 23 |
|
| 24 |
// Local includes |
| 25 |
|
| 26 |
#include "identity.h" |
| 27 |
#include "iteminfo.h" |
| 28 |
#include "facetagseditor.h" |
| 29 |
#include "digikam_export.h" |
| 30 |
|
| 31 |
class QImage; |
| 32 |
|
| 33 |
namespace Digikam |
| 34 |
{ |
| 35 |
|
| 36 |
class DImg; |
| 37 |
class ThumbnailLoadThread; |
| 38 |
class ThumbnailImageCatcher; |
| 39 |
|
| 40 |
class FaceUtils : public QObject, |
| 41 |
public FaceTagsEditor |
| 42 |
{ |
| 43 |
Q_OBJECT |
| 44 |
|
| 45 |
public: |
| 46 |
|
| 47 |
enum FaceRecognitionSteps |
| 48 |
{ |
| 49 |
DetectFaceRegions, |
| 50 |
DetectAndRecognize |
| 51 |
}; |
| 52 |
|
| 53 |
public: |
| 54 |
|
| 55 |
explicit FaceUtils(QObject* const parent = nullptr); |
| 56 |
~FaceUtils() override = default; |
| 57 |
|
| 58 |
// --- Face detection and recognition --- |
| 59 |
|
| 60 |
/** |
| 61 |
* The given face list is a result of automatic detection and possibly recognition. |
| 62 |
* The results are written to the database and merged with existing entries. |
| 63 |
* The returned list contains the faces written to the database and has the same size as the given list. |
| 64 |
* If a face was skipped (because of an existing entry), a null FaceTagsIface will be at this place. |
| 65 |
*/ |
| 66 |
QList<FaceTagsIface> writeUnconfirmedResults(qlonglong imageid, |
| 67 |
const QList<QRectF>& detectedFaces, |
| 68 |
const QList<Identity>& recognitionResults, |
| 69 |
const QSize& fullSize); |
| 70 |
|
| 71 |
QList<FaceTagsIface> writeUnconfirmedResults(qlonglong imageid, |
| 72 |
QList<FaceTagsIface>& detectedFaces, // cannot be const |
| 73 |
const QList<Identity>& recognitionResults); |
| 74 |
|
| 75 |
QList<FaceTagsIface> writeUnconfirmedResults(qlonglong imageid, |
| 76 |
QList<FaceTagsIface>& detectedFaces); |
| 77 |
|
| 78 |
// --- Status flags --- |
| 79 |
|
| 80 |
/** |
| 81 |
* Tells if the image has been scanned for faces or not |
| 82 |
*/ |
| 83 |
bool hasBeenScanned(const ItemInfo& info) const; |
| 84 |
bool hasBeenScanned(qlonglong imageid) const; |
| 85 |
bool normalTagChanged() const; |
| 86 |
|
| 87 |
/** |
| 88 |
* Marks the image as scanned for faces. |
| 89 |
*/ |
| 90 |
void markAsScanned(qlonglong imageid, bool hasBeenScanned = true) const; |
| 91 |
void markAsScanned(const ItemInfo& info, bool hasBeenScanned = true) const; |
| 92 |
|
| 93 |
// --- Utilities --- |
| 94 |
|
| 95 |
/** |
| 96 |
* This uses a thumbnail load thread to load the image detail. |
| 97 |
* If requested, the faces will be scaled to the given (fixed) size. |
| 98 |
*/ |
| 99 |
/* |
| 100 |
void fillImageInFaces(ThumbnailImageCatcher* const catcher, |
| 101 |
const QString& filePath, |
| 102 |
QList<Face>& faceList, |
| 103 |
const QSize& scaleSize = QSize()) const; |
| 104 |
*/ |
| 105 |
|
| 106 |
/** |
| 107 |
* Store the needed thumbnails for the given faces. This can be a huge optimization |
| 108 |
* when the has already been loaded anyway. |
| 109 |
*/ |
| 110 |
void storeThumbnails(ThumbnailLoadThread* const thread, |
| 111 |
const QString& filePath, |
| 112 |
const QList<FaceTagsIface>& databaseFaces, |
| 113 |
const DImg& image); |
| 114 |
|
| 115 |
/** |
| 116 |
* Conversion. |
| 117 |
*/ |
| 118 |
QList<FaceTagsIface> toFaceTagsIfaces(qlonglong imageid, |
| 119 |
const QList<QRectF>& detectedFaces, |
| 120 |
const QList<Identity>& recognitionResults, |
| 121 |
const QSize& fullSize) const; |
| 122 |
|
| 123 |
/** |
| 124 |
* For display, it may be desirable to display a slightly larger region than the strict |
| 125 |
* face rectangle. This returns a pixel margin commonly used to increase the rectangle size |
| 126 |
* in all four directions. |
| 127 |
*/ |
| 128 |
static QRect faceRectToDisplayRect(const QRect& rect); |
| 129 |
|
| 130 |
/* |
| 131 |
TODO: investigate this method. |
| 132 |
|
| 133 |
Identity identityForTag(int tagId, FacialRecognitionWrapper& recognizer) const; |
| 134 |
*/ |
| 135 |
Identity identityForTag(int tagId) const; |
| 136 |
int tagForIdentity(const Identity& identity) const; |
| 137 |
|
| 138 |
protected: |
| 139 |
|
| 140 |
/** |
| 141 |
* Reimplemented from parent class. |
| 142 |
*/ |
| 143 |
void addNormalTag(qlonglong imageId, int tagId) override; |
| 144 |
void removeNormalTag(qlonglong imageId, int tagId) override; |
| 145 |
void removeNormalTags(qlonglong imageId, const QList<int>& tagIds) override; |
| 146 |
|
| 147 |
private: |
| 148 |
|
| 149 |
bool m_normalTagChanged = false; |
| 150 |
|
| 151 |
private: |
| 152 |
|
| 153 |
/// @note disabled |
| 154 |
FaceUtils(const FaceUtils&) = delete; |
| 155 |
FaceUtils& operator=(const FaceUtils&) = delete; |
| 156 |
}; |
| 157 |
|
| 158 |
} // Namespace Digikam |