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 as published
13 * by the Free Software Foundation, either version 3 of the License,
14 * or (at your option) any later version.
16 * folded-ctf is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with folded-ctf. If not, see <http://www.gnu.org/licenses/>.
26 #include "error_rates.h"
27 #include "fusion_sort.h"
28 #include "pose_cell_hierarchy.h"
29 #include "boosted_classifier.h"
30 #include "parsing_pool.h"
31 #include "materials.h"
33 void compute_errors_on_one_image(int level,
35 PoseCellSet *cell_set,
36 int *nb_fns, int *nb_fas) {
38 int hit[image->nb_targets()];
40 for(int t = 0; t < image->nb_targets(); t++) {
46 for(int c = 0; c < cell_set->nb_cells(); c++) {
47 cell_set->get_cell(c)->get_centroid(&pose);
49 int false_positive = 1;
51 for(int t = 0; t < image->nb_targets(); t++) {
52 if(pose.hit(level, image->get_target_pose(t))) {
58 if(false_positive) (*nb_fas)++;
61 for(int t = 0; t < image->nb_targets(); t++) {
62 if(!hit[t]) (*nb_fns)++;
66 void print_decimated_error_rate(int level, LabelledImagePool *pool, Detector *detector) {
68 PoseCellScoredSet result_cell_set;
70 int nb_fns = 0, nb_fas = 0, nb_targets = 0;
71 long int total_surface = 0;
73 cout << "Testing the detector." << endl;
75 global.bar.init(&cout, pool->nb_images());
76 for(int i = 0; i < pool->nb_images(); i++) {
77 image = pool->grab_image(i);
78 total_surface += image->width() * image->height();
79 image->compute_rich_structure();
81 detector->parse(image, &result_cell_set);
82 result_cell_set.decimate_collide(level);
83 result_cell_set.decimate_hit(level);
85 compute_errors_on_one_image(level, image, &result_cell_set, &nb_fns, &nb_fas);
87 if(global.write_parse_images) {
88 char buffer[buffer_size];
89 sprintf(buffer, "%s/parse-%04d.png", global.result_path, i);
90 write_image_with_detections(buffer,
92 &result_cell_set, level);
95 nb_targets += image->nb_targets();
96 pool->release_image(i);
97 global.bar.refresh(&cout, i);
99 global.bar.finish(&cout);
101 scalar_t fn_rate = scalar_t(nb_fns)/scalar_t(nb_targets);
102 scalar_t nb_fas_per_vga = (scalar_t(nb_fas) / scalar_t(total_surface)) * scalar_t(640 * 480);
105 << "INFO DECIMATED_NB_FALSE_NEGATIVES " << nb_fns << endl
106 << "INFO DECIMATED_NB_TARGETS " << nb_targets << endl
107 << "INFO DECIMATED_FALSE_NEGATIVE_RATE " << fn_rate << endl
108 << "INFO DECIMATED_NB_FALSE_POSITIVES " << nb_fas << endl
109 << "INFO DECIMATED_NB_FALSE_POSITIVES_PER_VGA " << nb_fas_per_vga << endl
110 << "INFO NB_SCENES " << pool->nb_images() << endl
111 << "INFO TOTAL_SURFACE " << total_surface << endl;