2 * folded-ctf is an implementation of the folded hierarchy of
3 * classifiers for object detection, developed by Francois Fleuret
6 * Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
7 * Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 * This file is part of folded-ctf.
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.
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.
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/>.
25 #include "error_rates.h"
26 #include "fusion_sort.h"
27 #include "pose_cell_hierarchy.h"
28 #include "boosted_classifier.h"
29 #include "parsing_pool.h"
30 #include "materials.h"
32 void compute_errors_on_one_image(int level,
34 PoseCellSet *cell_set,
35 int *nb_fns, int *nb_fas) {
37 int hit[image->nb_targets()];
39 for(int t = 0; t < image->nb_targets(); t++) {
45 for(int c = 0; c < cell_set->nb_cells(); c++) {
46 cell_set->get_cell(c)->get_centroid(&pose);
48 int false_positive = 1;
50 for(int t = 0; t < image->nb_targets(); t++) {
51 if(pose.hit(level, image->get_target_pose(t))) {
57 if(false_positive) (*nb_fas)++;
60 for(int t = 0; t < image->nb_targets(); t++) {
61 if(!hit[t]) (*nb_fns)++;
65 void print_decimated_error_rate(int level, LabelledImagePool *pool, Detector *detector) {
67 PoseCellScoredSet result_cell_set;
69 int nb_fns = 0, nb_fas = 0, nb_targets = 0;
70 long int total_surface = 0;
72 cout << "Testing the detector." << endl;
74 global.bar.init(&cout, pool->nb_images());
75 for(int i = 0; i < pool->nb_images(); i++) {
76 image = pool->grab_image(i);
77 total_surface += image->width() * image->height();
78 image->compute_rich_structure();
80 detector->parse(image, &result_cell_set);
81 result_cell_set.decimate_collide(level);
82 result_cell_set.decimate_hit(level);
84 compute_errors_on_one_image(level, image, &result_cell_set, &nb_fns, &nb_fas);
86 if(global.write_parse_images) {
87 char buffer[buffer_size];
88 sprintf(buffer, "%s/parse-%04d.png", global.result_path, i);
89 write_image_with_detections(buffer,
91 &result_cell_set, level);
94 nb_targets += image->nb_targets();
95 pool->release_image(i);
96 global.bar.refresh(&cout, i);
98 global.bar.finish(&cout);
100 scalar_t fn_rate = scalar_t(nb_fns)/scalar_t(nb_targets);
101 scalar_t nb_fas_per_vga = (scalar_t(nb_fas) / scalar_t(total_surface)) * scalar_t(640 * 480);
104 << "INFO DECIMATED_NB_FALSE_NEGATIVES " << nb_fns << endl
105 << "INFO DECIMATED_NB_TARGETS " << nb_targets << endl
106 << "INFO DECIMATED_FALSE_NEGATIVE_RATE " << fn_rate << endl
107 << "INFO DECIMATED_NB_FALSE_POSITIVES " << nb_fas << endl
108 << "INFO DECIMATED_NB_FALSE_POSITIVES_PER_VGA " << nb_fas_per_vga << endl
109 << "INFO NB_SCENES " << pool->nb_images() << endl
110 << "INFO TOTAL_SURFACE " << total_surface << endl;