~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to core/libs/database/haar/haariface.h

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Rohan Garg, Philip Muškovac, Felix Geyer
  • Date: 2011-09-23 18:18:55 UTC
  • mfrom: (1.2.36 upstream)
  • Revision ID: package-import@ubuntu.com-20110923181855-ifs67wxkugshev9k
Tags: 2:2.1.1-0ubuntu1
[ Rohan Garg ]
* New upstream release (LP: #834190)
  - debian/control
    + Build with libqtwebkit-dev
 - debian/kipi-plugins-common
    + Install libkvkontakte required by kipi-plugins
 - debian/digikam
    + Install panoramagui

[ Philip Muškovac ]
* New upstream release
  - debian/control:
    + Add libcv-dev, libcvaux-dev, libhighgui-dev, libboost-graph1.46-dev,
      libksane-dev, libxml2-dev, libxslt-dev, libqt4-opengl-dev, libqjson-dev,
      libgpod-dev and libqca2-dev to build-deps
    + Add packages for kipi-plugins, libmediawiki, libkface, libkgeomap and
      libkvkontakte
  - debian/rules:
    + Don't build with gphoto2 since it doesn't build with it.
  - Add kubuntu_fix_test_linking.diff to fix linking of the dngconverter test
  - update install files
  - update kubuntu_01_mysqld_executable_name.diff for new cmake layout
    and rename to kubuntu_mysqld_executable_name.diff
* Fix typo in digikam-data description (LP: #804894)
* Fix Vcs links

[ Felix Geyer ]
* Move library data files to the new packages libkface-data, libkgeomap-data
  and libkvkontakte-data.
* Override version of the embedded library packages to 1.0~digikam<version>.
* Exclude the library packages from digikam-dbg to prevent file conflicts in
  the future.
* Call dh_install with --list-missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2003-01-17
 
7
 * Description : Haar Database interface
 
8
 *
 
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>
 
13
 *
 
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)
 
18
 * any later version.
 
19
 *
 
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.
 
24
 *
 
25
 * ============================================================ */
 
26
 
 
27
#ifndef HAARIFACE_H
 
28
#define HAARIFACE_H
 
29
 
 
30
// Qt includes
 
31
 
 
32
#include <QString>
 
33
#include <QMap>
 
34
#include <QList>
 
35
#include <haar.h>
 
36
 
 
37
// Local includes
 
38
 
 
39
#include "digikam_export.h"
 
40
 
 
41
class QImage;
 
42
 
 
43
namespace Digikam
 
44
{
 
45
 
 
46
class DImg;
 
47
 
 
48
class HaarProgressObserver
 
49
{
 
50
public:
 
51
 
 
52
    virtual ~HaarProgressObserver() {};
 
53
 
 
54
    virtual void totalNumberToScan(int number) = 0;
 
55
    virtual void processedNumber(int numberThatHasBeenProcessed) = 0;
 
56
};
 
57
 
 
58
// --------------------------------------------------------------------------
 
59
 
 
60
class DIGIKAM_DATABASE_EXPORT HaarIface
 
61
{
 
62
 
 
63
public:
 
64
 
 
65
    enum SketchType
 
66
    {
 
67
        ScannedSketch   = 0,
 
68
        HanddrawnSketch = 1
 
69
    };
 
70
 
 
71
public:
 
72
 
 
73
    HaarIface();
 
74
    ~HaarIface();
 
75
 
 
76
    static int preferredSize();
 
77
 
 
78
    /** Adds an image to the index in the database.
 
79
     */
 
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);
 
85
 
 
86
    /** Searches the database for the best matches for the specified query image.
 
87
     *  The numberOfResults best matches are returned.
 
88
     */
 
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);
 
93
 
 
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.
 
97
     */
 
98
    QList<qlonglong> bestMatchesForImageWithThreshold(qlonglong imageid,
 
99
            double requiredPercentage, SketchType type=ScannedSketch);
 
100
 
 
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.
 
103
     */
 
104
    QString signatureAsText(const QImage& image);
 
105
 
 
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.
 
108
     */
 
109
    void getBestAndWorstPossibleScore(Haar::SignatureData* querySig, SketchType type,
 
110
                                      double* lowestAndBestScore, double* highestAndWorstScore);
 
111
 
 
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.
 
116
     */
 
117
    QMap< qlonglong, QList<qlonglong> > findDuplicates(const QSet<qlonglong>& images2Scan, double requiredPercentage,
 
118
            HaarProgressObserver* observer = 0);
 
119
 
 
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);
 
123
 
 
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);
 
129
 
 
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)
 
132
     */
 
133
    void rebuildDuplicatesAlbums(const QList<int>& albums2Scan, const QList<int>& tags2Scan,
 
134
                                 double requiredPercentage, HaarProgressObserver* observer = 0);
 
135
 
 
136
    /** Retrieve the Haar signature from database using image id.
 
137
     *  Return true if item signature exist else false.
 
138
     */
 
139
    bool retrieveSignatureFromDB(qlonglong imageid, Haar::SignatureData* sig);
 
140
 
 
141
    /** Give a list of albumRoots to which the search shall be limited.
 
142
     *  Calling with an empty list will disable filtering.
 
143
     */
 
144
    void setAlbumRootsToSearch(QList<int> albumRootIds);
 
145
    void setAlbumRootsToSearch(QSet<int> albumRootIds);
 
146
 
 
147
private:
 
148
 
 
149
    QImage loadQImage(const QString& filename);
 
150
 
 
151
    bool   indexImage(qlonglong imageid);
 
152
 
 
153
    QList<qlonglong> bestMatches(Haar::SignatureData* data, int numberOfResults, SketchType type);
 
154
    QList<qlonglong> bestMatchesWithThreshold(Haar::SignatureData* querySig,
 
155
            double requiredPercentage, SketchType type);
 
156
 
 
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);
 
160
 
 
161
private:
 
162
 
 
163
    class HaarIfacePriv;
 
164
    HaarIfacePriv* const d;
 
165
};
 
166
 
 
167
}  // namespace Digikam
 
168
 
 
169
#endif // HAARIFACE_H