digiKam
Loading...
Searching...
No Matches
haariface.h
Go to the documentation of this file.
1/* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2003-01-17
7 * Description : Haar Database interface
8 *
9 * SPDX-FileCopyrightText: 2016-2018 by Mario Frank <mario dot frank at uni minus potsdam dot de>
10 * SPDX-FileCopyrightText: 2003 by Ricardo Niederberger Cabral <nieder at mail dot ru>
11 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
12 * SPDX-FileCopyrightText: 2009-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
13 * SPDX-FileCopyrightText: 2009-2011 by Andi Clemens <andi dot clemens at gmail dot com>
14 *
15 * SPDX-License-Identifier: GPL-2.0-or-later
16 *
17 * ============================================================ */
18
19#pragma once
20
21// Qt includes
22
23#include <QSet>
24#include <QString>
25#include <QMap>
26#include <QList>
27#include <QImage>
28
29// Local includes
30
31#include "haar.h"
32#include "iteminfo.h"
33#include "digikam_export.h"
34
35class QImage;
36
37namespace Digikam
38{
39
40class DImg;
41class ItemInfo;
42
44{
45public:
46
48 virtual ~HaarProgressObserver() = default;
49
50 virtual void imageProcessed(const ItemInfo&, const QImage&, int) = 0;
51
52 virtual bool isCanceled()
53 {
54 return false;
55 };
56
57private:
58
59 Q_DISABLE_COPY(HaarProgressObserver)
60};
61
62// --------------------------------------------------------------------------
63
64class DIGIKAM_DATABASE_EXPORT HaarIface
65{
66
67public:
68
70 {
71 ScannedSketch = 0,
72 HanddrawnSketch = 1
73 };
74
76 {
77 None = 0,
78 SameAlbum = 1,
79 DifferentAlbum = 2
80 };
81
83 {
84 NoMix = 0,
85 Union = 1,
86 Intersection = 2,
87 AlbumExclusive = 3,
88 TagExclusive = 4
89 };
90
99 enum class RefImageSelMethod: unsigned int
100 {
101 OlderOrLarger = 0,
102 PreferFolder = 1,
103 ExcludeFolder = 2,
104 NewerCreationDate = 3,
105 NewerModificationDate = 4
106 };
107
108 using DuplicatesResultsMap = QMap<qlonglong, QPair<double, QList<qlonglong> > >;
109
110public:
111
112 explicit HaarIface();
113 explicit HaarIface(const QSet<qlonglong>& images2Scan);
114 ~HaarIface();
115
116 static int preferredSize();
117
121 bool indexImage(const QString& filename);
122 bool indexImage(const QString& filename, const QImage& image);
123 bool indexImage(const QString& filename, const DImg& image);
124 bool indexImage(qlonglong imageid, const QImage& image);
125 bool indexImage(qlonglong imageid, const DImg& image);
126
127 QMap<qlonglong, double> bestMatchesForSignature(const QString& signature,
128 const QList<int>& targetAlbums,
129 int numberOfResults = 20,
130 SketchType type = ScannedSketch);
131
137 QPair<double, QMap<qlonglong, double> > bestMatchesForImageWithThreshold(
138 qlonglong imageid,
139 double requiredPercentage,
140 double maximumPercentage,
141 const QList<int>& targetAlbums,
142 DuplicatesSearchRestrictions searchResultRestriction = DuplicatesSearchRestrictions::None,
143 SketchType type = ScannedSketch
144 );
145
151 QPair<double, QMap<qlonglong, double> > bestMatchesForImageWithThreshold(
152 const QString& imagePath,
153 double requiredPercentage,
154 double maximumPercentage,
155 const QList<int>& targetAlbums,
156 DuplicatesSearchRestrictions searchResultRestriction = DuplicatesSearchRestrictions::None,
157 SketchType type = ScannedSketch
158 );
159
164 QString signatureAsText(const QImage& image);
165
170 bool fulfillsRestrictions(qlonglong imageId,
171 int albumId,
172 qlonglong originalImageId,
173 int originalAlbumId,
174 const QList<int>& targetAlbums,
175 DuplicatesSearchRestrictions searchResultRestriction);
176
181 void getBestAndWorstPossibleScore(Haar::SignatureData* const querySig,
182 SketchType type,
183 double* const lowestAndBestScore,
184 double* const highestAndWorstScore);
185
192 DuplicatesResultsMap findDuplicates(
193 const QSet<qlonglong>& images2Scan,
194 const QSet<qlonglong>::const_iterator& rangeBegin,
195 const QSet<qlonglong>::const_iterator& rangeEnd,
196 RefImageSelMethod refImageSelectionMethod,
197 const QSet<qlonglong>& refs,
198 double requiredPercentage,
199 double maximumPercentage,
200 DuplicatesSearchRestrictions searchResultRestriction = DuplicatesSearchRestrictions::None,
201 HaarProgressObserver* const observer = nullptr
202 );
203
207 static QSet<qlonglong> imagesFromAlbumsAndTags(const QList<int>& albums2Scan,
208 const QList<int>& tags2Scan,
209 AlbumTagRelation relation);
210
215 static void rebuildDuplicatesAlbums(const DuplicatesResultsMap& results, bool isAlbumUpdate);
216
221 bool retrieveSignatureFromDB(qlonglong imageid, Haar::SignatureData& sig);
222
227 void setAlbumRootsToSearch(const QList<int>& albumRootIds);
228 void setAlbumRootsToSearch(const QSet<int>& albumRootIds);
229
235 QImage loadQImage(const QString& filename);
236
237private:
238
239 bool indexImage(qlonglong imageid);
240
245 static QMap<QString, QString> writeSAlbumQueries(const DuplicatesResultsMap& searchResults);
246
247 QMultiMap<double, qlonglong> bestMatches(Haar::SignatureData* const data,
248 int numberOfResults,
249 const QList<int>& targetAlbums,
250 SketchType type);
251
263 QPair<double, QMap<qlonglong, double> > bestMatchesWithThreshold(qlonglong imageid,
264 Haar::SignatureData* const querySig,
265 double requiredPercentage,
266 double maximumPercentage,
267 const QList<int>& targetAlbums,
268 DuplicatesSearchRestrictions searchResultRestriction,
269 SketchType type);
270
280 QMap<qlonglong, double> searchDatabase(Haar::SignatureData* const data,
281 SketchType type,
282 const QList<int>& targetAlbums,
283 DuplicatesSearchRestrictions searchResultRestriction = None,
284 qlonglong originalImageId = -1,
285 int albumId = -1);
286
287 double calculateScore(const Haar::SignatureData& querySig,
288 const Haar::SignatureData& targetSig,
289 const Haar::Weights& weights,
290 std::reference_wrapper<Haar::SignatureMap>* const queryMaps);
291
292private:
293
294 // Disable
295 HaarIface(const HaarIface&) = delete;
296 HaarIface& operator=(const HaarIface&) = delete;
297
298private:
299
300 class Private;
301 Private* const d = nullptr;
302};
303
304} // namespace Digikam
Definition dimg.h:52
Definition haariface_p.h:95
Definition haariface.h:65
QMap< qlonglong, QPair< double, QList< qlonglong > > > DuplicatesResultsMap
Definition haariface.h:108
RefImageSelMethod
The RefImageSelMethod enum Selection method to determine which image will be the reference in the dup...
Definition haariface.h:100
AlbumTagRelation
Definition haariface.h:83
DuplicatesSearchRestrictions
Definition haariface.h:76
SketchType
Definition haariface.h:70
Definition haariface.h:44
virtual void imageProcessed(const ItemInfo &, const QImage &, int)=0
virtual bool isCanceled()
Definition haariface.h:52
virtual ~HaarProgressObserver()=default
Definition haar.h:113
Definition haar.h:238
Definition iteminfo.h:68
Definition datefolderview.cpp:34