1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : Haar Database interface
9
* Copyright (C) 2003 by Ricardo Niederberger Cabral <nieder at mail dot ru>
10
* Copyright (C) 2009-2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
* Copyright (C) 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
12
* Copyright (C) 2009-2011 by Andi Clemens <andi dot clemens at gmx dot net>
14
* This program is free software; you can redistribute it
15
* and/or modify it under the terms of the GNU General
16
* Public License as published by the Free Software Foundation;
17
* either version 2, or (at your option)
20
* This program is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
* GNU General Public License for more details.
25
* ============================================================ */
39
#include "digikam_export.h"
48
class HaarProgressObserver
52
virtual ~HaarProgressObserver() {};
54
virtual void totalNumberToScan(int number) = 0;
55
virtual void processedNumber(int numberThatHasBeenProcessed) = 0;
58
// --------------------------------------------------------------------------
60
class DIGIKAM_DATABASE_EXPORT HaarIface
76
static int preferredSize();
78
/** Adds an image to the index in the database.
80
bool indexImage(const QString& filename);
81
bool indexImage(const QString& filename, const QImage& image);
82
bool indexImage(const QString& filename, const DImg& image);
83
bool indexImage(qlonglong imageid, const QImage& image);
84
bool indexImage(qlonglong imageid, const DImg& image);
86
/** Searches the database for the best matches for the specified query image.
87
* The numberOfResults best matches are returned.
89
QList<qlonglong> bestMatchesForImage(qlonglong imageid, int numberOfResults=20, SketchType type=ScannedSketch);
90
QList<qlonglong> bestMatchesForImage(const QImage& image, int numberOfResults=20, SketchType type=ScannedSketch);
91
QList<qlonglong> bestMatchesForFile(const QString& filename, int numberOfResults=20, SketchType type=ScannedSketch);
92
QList<qlonglong> bestMatchesForSignature(const QString& signature, int numberOfResults=20, SketchType type=ScannedSketch);
94
/** Searches the database for the best matches for the specified query image.
95
* All matches with a similarity above a given threshold are returned.
96
* The threshold is in the range 0..1, with 1 meaning identical signature.
98
QList<qlonglong> bestMatchesForImageWithThreshold(qlonglong imageid,
99
double requiredPercentage, SketchType type=ScannedSketch);
101
/** Calculates the Haar signature, bring it in a form as stored in the DB,
102
* and encode it to Ascii data. Can be used for bestMatchesForSignature.
104
QString signatureAsText(const QImage& image);
106
/** For a given signature, find out the highest and lowest possible score
107
* that any other signature could reach, compared to the given signature.
109
void getBestAndWorstPossibleScore(Haar::SignatureData* querySig, SketchType type,
110
double* lowestAndBestScore, double* highestAndWorstScore);
112
/** Fill a map of duplicates images found over a list of image to scan.
113
* For each map item, the result values is list of candidate images which are duplicates of the key image.
114
* All images are referenced by id from database.
115
* The threshold is in the range 0..1, with 1 meaning identical signature.
117
QMap< qlonglong, QList<qlonglong> > findDuplicates(const QSet<qlonglong>& images2Scan, double requiredPercentage,
118
HaarProgressObserver* observer = 0);
120
/** Calls findDuplicates with all images in the given album ids */
121
QMap< qlonglong, QList<qlonglong> > findDuplicatesInAlbums(const QList<int>& albums2Scan, double requiredPercentage,
122
HaarProgressObserver* observer = 0);
124
/** Calls findDuplicates with all images in the given album and tag ids */
125
QMap< qlonglong, QList<qlonglong> > findDuplicatesInAlbumsAndTags(const QList<int>& albums2Scan,
126
const QList<int>& tags2Scan,
127
double requiredPercentage,
128
HaarProgressObserver* observer = 0);
130
/** Rebuilds the special search albums in the database that contain a list of possible candidates
131
* for duplicate images (one album per group of duplicates)
133
void rebuildDuplicatesAlbums(const QList<int>& albums2Scan, const QList<int>& tags2Scan,
134
double requiredPercentage, HaarProgressObserver* observer = 0);
136
/** Retrieve the Haar signature from database using image id.
137
* Return true if item signature exist else false.
139
bool retrieveSignatureFromDB(qlonglong imageid, Haar::SignatureData* sig);
141
/** Give a list of albumRoots to which the search shall be limited.
142
* Calling with an empty list will disable filtering.
144
void setAlbumRootsToSearch(QList<int> albumRootIds);
145
void setAlbumRootsToSearch(QSet<int> albumRootIds);
149
QImage loadQImage(const QString& filename);
151
bool indexImage(qlonglong imageid);
153
QList<qlonglong> bestMatches(Haar::SignatureData* data, int numberOfResults, SketchType type);
154
QList<qlonglong> bestMatchesWithThreshold(Haar::SignatureData* querySig,
155
double requiredPercentage, SketchType type);
157
QMap<qlonglong, double> searchDatabase(Haar::SignatureData* data, SketchType type);
158
double calculateScore(Haar::SignatureData& querySig, Haar::SignatureData& targetSig,
159
Haar::Weights& weights, Haar::SignatureMap** queryMaps);
164
HaarIfacePriv* const d;
167
} // namespace Digikam
169
#endif // HAARIFACE_H