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

« back to all changes in this revision

Viewing changes to extra/libkface/libface/Haarcascades.cpp

  • 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
 * @file
 
3
 *
 
4
 * This file is a part of libface project
 
5
 * <a href="http://libface.sourceforge.net">http://libface.sourceforge.net</a>
 
6
 *
 
7
 * @date    2010-03-14
 
8
 * @brief   Haar cascades parser
 
9
 * @section DESCRIPTION
 
10
 *
 
11
 * @author Copyright (C) 2010 by Aditya Bhatt
 
12
 *         <a href="adityabhatt at gmail dot com">adityabhatt at gmail dot com</a>
 
13
 * @author Copyright (C) 2010 by Gilles Caulier
 
14
 *         <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
 
15
 *
 
16
 * @section LICENSE
 
17
 *
 
18
 * This program is free software; you can redistribute it
 
19
 * and/or modify it under the terms of the GNU General
 
20
 * Public License as published by the Free Software Foundation;
 
21
 * either version 2, or (at your option)
 
22
 * any later version.
 
23
 *
 
24
 * This program is distributed in the hope that it will be useful,
 
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
27
 * GNU General Public License for more details.
 
28
 *
 
29
 * ============================================================ */
 
30
 
 
31
#include <string>
 
32
#include <cstdio>
 
33
#include <cstdlib>
 
34
#include <cassert>
 
35
#include <cmath>
 
36
#include <cfloat>
 
37
#include <climits>
 
38
#include <ctime>
 
39
#include <cctype>
 
40
 
 
41
#if defined (__APPLE__)
 
42
#include <cv.h>
 
43
#include <highgui.h>
 
44
#else
 
45
#include <opencv/cv.h>
 
46
#include <opencv/highgui.h>
 
47
#endif
 
48
 
 
49
#include "Haarcascades.h"
 
50
 
 
51
// TODO: Free memory before erasing cascades from vector, LOTS of exception handling
 
52
 
 
53
using namespace std;
 
54
 
 
55
namespace libface
 
56
{
 
57
 
 
58
class Haarcascades::HaarcascadesPriv
 
59
{
 
60
 
 
61
public:
 
62
 
 
63
    HaarcascadesPriv()
 
64
    {
 
65
        size = 0;
 
66
    }
 
67
 
 
68
    std::string          cascadePath;
 
69
    std::vector<Cascade> cascades;
 
70
    std::vector<int>     weights;
 
71
    int                  size;
 
72
};
 
73
 
 
74
Haarcascades::Haarcascades(const string& path)
 
75
            : d(new HaarcascadesPriv)
 
76
{
 
77
    this->d->cascadePath = path;
 
78
}
 
79
 
 
80
Haarcascades::~Haarcascades()
 
81
{
 
82
    this->clear();
 
83
    d->size = 0;
 
84
    delete d;
 
85
}
 
86
 
 
87
void Haarcascades::addCascade(const Cascade& newCascade, int newWeight)
 
88
{
 
89
    if (this->hasCascade(newCascade.name))
 
90
        return;
 
91
 
 
92
    d->cascades.push_back(newCascade);
 
93
    d->weights.push_back(newWeight);
 
94
    d->size++;
 
95
}
 
96
 
 
97
void Haarcascades::addCascade(const string& name, int newWeight)
 
98
{
 
99
    if (this->hasCascade(name))
 
100
        return;
 
101
 
 
102
    Cascade newCascade;
 
103
    newCascade.name     = name;
 
104
    newCascade.haarcasc = (CvHaarClassifierCascade*) cvLoad((d->cascadePath + string("/") + name).data(), 0, 0, 0);
 
105
    this->addCascade(newCascade, newWeight);
 
106
}
 
107
 
 
108
bool Haarcascades::hasCascade(const string& name) const
 
109
{
 
110
    for (int i = 0; i < d->size-1; ++i)
 
111
    {
 
112
        if (name == d->cascades[i].name)
 
113
            return true;
 
114
    }
 
115
    return false;
 
116
}
 
117
 
 
118
void Haarcascades::removeCascade(const string& name)
 
119
{
 
120
    int i;
 
121
    for (i = 0; i < d->size-1; ++i)
 
122
    {
 
123
        if (name == d->cascades[i].name)
 
124
            break;
 
125
    }
 
126
 
 
127
    d->cascades.erase(d->cascades.begin() + i);
 
128
    d->weights.erase(d->weights.begin() + i);
 
129
    d->size--;
 
130
}
 
131
 
 
132
void Haarcascades::removeCascade(int index)
 
133
{
 
134
    d->cascades.erase(d->cascades.begin() + index);
 
135
    d->weights.erase(d->weights.begin() + index);
 
136
    d->size--;
 
137
}
 
138
 
 
139
int Haarcascades::getWeight(const string& name) const
 
140
{
 
141
    for (int i = 0; i < d->size-1; ++i)
 
142
    {
 
143
        if (name == d->cascades[i].name)
 
144
            return d->weights[i];
 
145
    }
 
146
    return -1;  // No such name found, return -1
 
147
}
 
148
 
 
149
int Haarcascades::getWeight(int index) const
 
150
{
 
151
    return d->weights[index];
 
152
}
 
153
 
 
154
void Haarcascades::setWeight(const string& name, int weight)
 
155
{
 
156
    int i;
 
157
    for (i = 0; i < d->size-1; ++i)
 
158
    {
 
159
        if (name == d->cascades[i].name)
 
160
            break;
 
161
    }
 
162
 
 
163
    d->weights[i] = weight;
 
164
}
 
165
 
 
166
void Haarcascades::setWeight(int index, int weight)
 
167
{
 
168
    d->weights[index] = weight;
 
169
}
 
170
 
 
171
const Cascade& Haarcascades::getCascade(const string& name) const
 
172
{
 
173
    int i;
 
174
    for (i = 0; i < d->size-1; ++i)
 
175
    {
 
176
        if (name == d->cascades[i].name)
 
177
            break;
 
178
    }
 
179
    return d->cascades[i];
 
180
}
 
181
 
 
182
const Cascade& Haarcascades::getCascade(int index) const
 
183
{
 
184
    return d->cascades[index];
 
185
}
 
186
 
 
187
int Haarcascades::getSize() const
 
188
{
 
189
    return d->size;
 
190
}
 
191
 
 
192
void Haarcascades::clear()
 
193
{
 
194
    for(unsigned int i = 0; i < d->cascades.size(); ++i)
 
195
    {
 
196
        cvReleaseHaarClassifierCascade(&d->cascades[i].haarcasc);
 
197
    }
 
198
    d->cascades.clear();
 
199
    d->weights.clear();
 
200
    d->size = 0;
 
201
}
 
202
 
 
203
} // namespace libface