2 ///////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation. //
7 // This program is distributed in the hope that it will be useful, but //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
10 // General Public License for more details. //
12 // You should have received a copy of the GNU General Public License //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
15 // Written by Francois Fleuret //
16 // (C) Idiap Research Institute //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
19 ///////////////////////////////////////////////////////////////////////////
21 #include "error_rates.h"
22 #include "fusion_sort.h"
23 #include "pose_cell_hierarchy.h"
24 #include "boosted_classifier.h"
25 #include "parsing_pool.h"
26 #include "materials.h"
28 void compute_errors_on_one_image(int level,
30 PoseCellSet *cell_set,
31 int *nb_fns, int *nb_fas) {
33 int hit[image->nb_targets()];
35 for(int t = 0; t < image->nb_targets(); t++) {
41 for(int c = 0; c < cell_set->nb_cells(); c++) {
42 cell_set->get_cell(c)->get_centroid(&pose);
44 int false_positive = 1;
46 for(int t = 0; t < image->nb_targets(); t++) {
47 if(pose.hit(level, image->get_target_pose(t))) {
53 if(false_positive) (*nb_fas)++;
56 for(int t = 0; t < image->nb_targets(); t++) {
57 if(!hit[t]) (*nb_fns)++;
61 void print_decimated_error_rate(int level, LabelledImagePool *pool, Detector *detector) {
63 PoseCellScoredSet result_cell_set;
65 int nb_fns = 0, nb_fas = 0, nb_targets = 0;
66 long int total_surface = 0;
68 cout << "Testing the detector." << endl;
70 global.bar.init(&cout, pool->nb_images());
71 for(int i = 0; i < pool->nb_images(); i++) {
72 image = pool->grab_image(i);
73 total_surface += image->width() * image->height();
74 image->compute_rich_structure();
76 detector->parse(image, &result_cell_set);
77 result_cell_set.decimate_collide(level);
78 result_cell_set.decimate_hit(level);
80 compute_errors_on_one_image(level, image, &result_cell_set, &nb_fns, &nb_fas);
82 if(global.write_parse_images) {
83 char buffer[buffer_size];
84 sprintf(buffer, "%s/parse-%04d.png", global.result_path, i);
85 write_image_with_detections(buffer,
87 &result_cell_set, level);
90 nb_targets += image->nb_targets();
91 pool->release_image(i);
92 global.bar.refresh(&cout, i);
94 global.bar.finish(&cout);
96 scalar_t fn_rate = scalar_t(nb_fns)/scalar_t(nb_targets);
97 scalar_t nb_fas_per_vga = (scalar_t(nb_fas) / scalar_t(total_surface)) * scalar_t(640 * 480);
100 << "INFO DECIMATED_NB_FALSE_NEGATIVES " << nb_fns << endl
101 << "INFO DECIMATED_NB_TARGETS " << nb_targets << endl
102 << "INFO DECIMATED_FALSE_NEGATIVE_RATE " << fn_rate << endl
103 << "INFO DECIMATED_NB_FALSE_POSITIVES " << nb_fas << endl
104 << "INFO DECIMATED_NB_FALSE_POSITIVES_PER_VGA " << nb_fas_per_vga << endl
105 << "INFO NB_SCENES " << pool->nb_images() << endl
106 << "INFO TOTAL_SURFACE " << total_surface << endl;