1
/** ===========================================================
4
* This file is a part of digiKam project
5
* <a href="http://www.digikam.org">http://www.digikam.org</a>
8
* @brief Wrapper class for face recongition
10
* @author Copyright (C) 2010 by Marcel Wiesweg
11
* <a href="mailto:marcel dot wiesweg at gmx dot de">marcel dot wiesweg at gmx dot de</a>
12
* @author Copyright (C) 2010 by Aditya Bhatt
13
* <a href="mailto:adityabhatt1991 at gmail dot com">adityabhatt1991 at gmail dot com</a>
14
* @author Copyright (C) 2010 by Gilles Caulier
15
* <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
17
* This program is free software; you can redistribute it
18
* and/or modify it under the terms of the GNU General
19
* Public License as published by the Free Software Foundation;
20
* either version 2, or (at your option)
23
* This program is distributed in the hope that it will be useful,
24
* but WITHOUT ANY WARRANTY; without even the implied warranty of
25
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
* GNU General Public License for more details.
28
* ============================================================ */
30
#ifndef KFACE_RECOGNITIONDATABASE_H
31
#define KFACE_RECOGNITIONDATABASE_H
35
#include <QtCore/QExplicitlySharedDataPointer>
39
#include <kstandarddirs.h>
43
#include "libkface_export.h"
50
class KFACE_EXPORT RecognitionDatabase
56
* A wrapper around Database for face recongition.
57
* Additionally provides the following guarantees:
58
* - deferred creation: The backend is created only when used first.
59
* - only one instance per configuration path is created
60
* - an instance of this class is thread-safe
61
* (this class is also reentrant, for different objects and paths)
65
* Returns an instance of RecognitionDatabase for the given configuration path.
66
* When called multiple times with the same path, will return the same database.
67
* The database is closed and configuration written after the last object is destroyed.
68
* @param configurationPath The path where the RecognitionDatabase configuration file will be stored.
69
* If null, a default path is located by KStandardDirs.
71
static RecognitionDatabase addDatabase(const QString& configurationPath = QString());
73
/// Constructs a null database
74
RecognitionDatabase();
76
RecognitionDatabase(const RecognitionDatabase& other);
77
~RecognitionDatabase();
78
RecognitionDatabase& operator=(const RecognitionDatabase& other);
83
* Explicitly save configuration. Automatically done in destructor.
88
* Update the training database with a QList of Faces which hold the face images
89
* Faces that have not been given any ID by the caller will automatically be given the next available ID,
90
* and this ID will be updated in the Face objects.
91
* @param faces A QList of Face's, which hold the face image too, for updating the DB.
92
* @return False if no faces were updated, due to an argument of size zero
94
bool updateFaces(QList<Face>& faces);
97
* Function to recognize faces in a QList of Faces which hold the face images.
98
* Recognized faces will have their ID's changed in the Face objects
99
* @param faces A QList of Face's, which hold the face image too, for recongition.
100
* @return A QList of "closeness" of recognized faces, in the same order as the argument;
101
* or an empty list, if an error occurred or no recognition data is available.
103
QList<double> recognizeFaces(QList<Face>& faces);
106
* Clear the training database for a single name or id.
107
* Use with care, this can deleted carefully accumulated data!
109
void clearTraining(const QString& name);
110
void clearTraining(int id);
111
void clearAllTraining();
114
* Returns the directory path of the config file
117
QString configPath() const;
120
* Get the number of people in the database
121
* @return Number of unique ID's in the database
123
int peopleCount() const;
126
* Returns all ids in the database
128
QList<int> allIds() const;
131
* Returns all names in the database
133
QStringList allNames() const;
136
* Returns the first name associated with the given id, or
137
* a null string. Note there may be multiple names per id.
139
QString nameForId(int id) const;
142
* Returns the id for the given name, or -1 if this name is not know.
144
int idForName(const QString& name) const;
147
* Returns the recommended size if you want to scale images for recognition.
148
* Larger images can be passed, but may be downscaled.
150
QSize recommendedImageSize(const QSize& availableSize = QSize()) const;
154
class RecognitionDatabasePriv;
156
RecognitionDatabase(QExplicitlySharedDataPointer<RecognitionDatabasePriv> d);
158
QExplicitlySharedDataPointer<RecognitionDatabasePriv> d;
160
friend class RecognitionDatabaseStaticPriv;
163
} // namespace KFaceIface
165
#endif // KFACE_RECOGNITIONDATABASE_H