Removed the definition of basename, which confuses an existing system one.
[folded-ctf.git] / detector.h
1 /*
2  *  folded-ctf is an implementation of the folded hierarchy of
3  *  classifiers for object detection, developed by Francois Fleuret
4  *  and Donald Geman.
5  *
6  *  Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
7  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
8  *
9  *  This file is part of folded-ctf.
10  *
11  *  folded-ctf is free software: you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License version 3 as
13  *  published by the Free Software Foundation.
14  *
15  *  folded-ctf is distributed in the hope that it will be useful, but
16  *  WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *  General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with folded-ctf.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 /*
26
27   This is the main class, a detector as a folded hierarchy of
28   classifiers.
29
30 */
31
32 #ifndef DETECTOR_H
33 #define DETECTOR_H
34
35 #include "storable.h"
36 #include "boosted_classifier.h"
37 #include "labelled_image_pool.h"
38 #include "parsing_pool.h"
39 #include "pose_cell_scored_set.h"
40
41 class Detector : public Storable {
42 public:
43   PoseCellHierarchy *_hierarchy;
44   int _nb_levels, _nb_classifiers_per_level, _nb_classifiers;
45   scalar_t *_thresholds;
46   Classifier **_classifiers;
47   PiFeatureFamily **_pi_feature_families;
48
49   void free();
50
51   virtual void train_classifier(int level,
52                                 LossMachine *loss_machine,
53                                 ParsingPool *parsing,
54                                 PiFeatureFamily *pi_feature_family,
55                                 Classifier *classifier);
56
57   virtual void parse_rec(RichImage *image, int level,
58                          PoseCell *cell, scalar_t response,
59                          PoseCellScoredSet *result);
60
61 public:
62
63   Detector();
64   virtual ~Detector();
65
66   inline int nb_levels() { return _nb_levels; }
67
68   // The validation set is only used to save ROCs curves during
69   // training for monitoring the learning
70
71   virtual void train(LabelledImagePool *train_pool,
72                      LabelledImagePool *validation_pool,
73                      LabelledImagePool *hierarchy_pool);
74
75   // Compute the thresholds at the various levels to reach the desired
76   // overall true positive rate
77
78   virtual void compute_thresholds(LabelledImagePool *validation_pool, scalar_t wanted_tp);
79
80   virtual void parse(RichImage *image, PoseCellScoredSet *result_cell_set);
81
82   virtual void read(istream *is);
83   virtual void write(ostream *os);
84 };
85
86 #endif