X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=folded-ctf.git;a=blobdiff_plain;f=materials.cc;h=df7abbba30d6ef2c5c1827b012bf5b20a5770e4a;hp=bbb6cbf437eb9b542e983c83e467a6080c9e3813;hb=8a90240a648bc6328c887e10cc31e4b6d6ea9497;hpb=d922ad61d35e9a6996730bec24b16f8bf7bc426c diff --git a/materials.cc b/materials.cc index bbb6cbf..df7abbb 100644 --- a/materials.cc +++ b/materials.cc @@ -1,20 +1,27 @@ - -/////////////////////////////////////////////////////////////////////////// -// This program is free software: you can redistribute it and/or modify // -// it under the terms of the version 3 of the GNU General Public License // -// as published by the Free Software Foundation. // -// // -// This program is distributed in the hope that it will be useful, but // -// WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // -// General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with this program. If not, see . // -// // -// Written by Francois Fleuret, (C) IDIAP // -// Contact for comments & bug reports // -/////////////////////////////////////////////////////////////////////////// +/* + * folded-ctf is an implementation of the folded hierarchy of + * classifiers for object detection, developed by Francois Fleuret + * and Donald Geman. + * + * Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of folded-ctf. + * + * folded-ctf is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * folded-ctf is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with folded-ctf. If not, see . + * + */ #include "materials.h" #include "boosted_classifier.h" @@ -75,26 +82,7 @@ void write_referential_png(char *filename, referential->draw(&result_sp, level); } - (*global.log_stream) << "Writing " << filename << endl; - result_sp.write_png(filename); -} - -void write_one_pi_feature_png(char *filename, - LabelledImage *image, - PoseCellHierarchy *hierarchy, - int nb_target, - int level, - PiFeature *pf) { - - PoseCell target_cell; - hierarchy->get_containing_cell(image, level, - image->get_target_pose(nb_target), &target_cell); - PiReferential referential(&target_cell); - RGBImage result(image->width(), image->height()); - image->to_rgb(&result); - RGBImageSubpixel result_sp(&result); - referential.draw(&result_sp, level); - // pf->draw(&result_sp, 255, 255, 0, &referential); + cout << "Writing " << filename << endl; result_sp.write_png(filename); } @@ -109,102 +97,85 @@ void write_pool_images_with_poses_and_referentials(LabelledImagePool *pool, PoseCellHierarchy *hierarchy = new PoseCellHierarchy(pool); - for(int i = 0; i < min(global.nb_images, pool->nb_images()); i++) { - image = pool->grab_image(i); - RGBImage result(image->width(), image->height()); - image->to_rgb(&result); - RGBImageSubpixel result_sp(&result); + if(global.material_feature_nb < 0) { + for(int i = 0; i < min(global.nb_images, pool->nb_images()); i++) { + image = pool->grab_image(i); + RGBImage result(image->width(), image->height()); + image->to_rgb(&result); + RGBImageSubpixel result_sp(&result); - if(global.pictures_for_article) { - for(int t = 0; t < image->nb_targets(); t++) { - image->get_target_pose(t)->draw(8, 255, 255, 255, - hierarchy->nb_levels() - 1, &result_sp); + if(global.pictures_for_article) { + for(int t = 0; t < image->nb_targets(); t++) { + image->get_target_pose(t)->draw(8, 255, 255, 255, + hierarchy->nb_levels() - 1, &result_sp); + } + for(int t = 0; t < image->nb_targets(); t++) { + image->get_target_pose(t)->draw(4, 0, 0, 0, + hierarchy->nb_levels() - 1, &result_sp); + } + } else { + for(int t = 0; t < image->nb_targets(); t++) { + image->get_target_pose(t)->draw(4, 255, 128, 0, + hierarchy->nb_levels() - 1, &result_sp); + } } - for(int t = 0; t < image->nb_targets(); t++) { - image->get_target_pose(t)->draw(4, 0, 0, 0, - hierarchy->nb_levels() - 1, &result_sp); - } - } else { - for(int t = 0; t < image->nb_targets(); t++) { - image->get_target_pose(t)->draw(4, 255, 128, 0, - hierarchy->nb_levels() - 1, &result_sp); - } - } - sprintf(buffer, "/tmp/truth-%05d.png", i); - cout << "Writing " << buffer << endl; - result_sp.write_png(buffer); - pool->release_image(i); + sprintf(buffer, "/tmp/truth-%05d.png", i); + cout << "Writing " << buffer << endl; + result_sp.write_png(buffer); + pool->release_image(i); + } } for(int i = 0; i < min(global.nb_images, pool->nb_images()); i++) { - image = pool->grab_image(i); + image = pool->grab_image(i); + + RGBImage result(image->width(), image->height()); + image->to_rgb(&result); + RGBImageSubpixel result_sp(&result); - RGBImage result(image->width(), image->height()); - image->to_rgb(&result); - RGBImageSubpixel result_sp(&result); + // image->compute_rich_structure(); - int u = 0; + for(int t = 0; t < image->nb_targets(); t++) { - // image->compute_rich_structure(); + image->get_target_pose(t)->draw(4, 255, 0, 0, + hierarchy->nb_levels() - 1, &result_sp); - for(int t = 0; t < image->nb_targets(); t++) { + hierarchy->get_containing_cell(image, + hierarchy->nb_levels() - 1, + image->get_target_pose(t), &target_cell); - image->get_target_pose(t)->draw(4, 255, 0, 0, - hierarchy->nb_levels() - 1, &result_sp); + target_cell.get_centroid(&p); - hierarchy->get_containing_cell(image, - hierarchy->nb_levels() - 1, - image->get_target_pose(t), &target_cell); - - target_cell.get_centroid(&p); - - p.draw(4, 0, 255, 0, hierarchy->nb_levels() - 1, &result_sp); - - PiReferential referential(&target_cell); - - sprintf(buffer, "/tmp/referential-%05d-%02d.png", i, u); - image->compute_rich_structure(); - write_referential_png(buffer, hierarchy->nb_levels() - 1, image, &referential, 0); - - if(detector) { - int nb_features = 100; - for(int f = 0; f < nb_features; f++) - if(f == 0 || f ==50 || f == 53) { - int n_family, n_feature; - if(f < nb_features/2) { - n_family = 0; - n_feature = f; - } else { - n_family = detector->_nb_classifiers_per_level; - n_feature = f - nb_features/2; - } - pf = detector->_pi_feature_families[n_family]->get_feature(n_feature); - sprintf(buffer, "/tmp/pf-%05d-%02d-%03d.png", i, u, f); - write_referential_png(buffer, - hierarchy->nb_levels() - 1, - image, - &referential, - pf); - } - } - u++; - } + p.draw(4, 0, 255, 0, hierarchy->nb_levels() - 1, &result_sp); - // sprintf(buffer, "/tmp/image-%05d.png", i); - // cout << "Writing " << buffer << endl; - // result_sp.write_png(buffer); + PiReferential referential(&target_cell); - // if(global.write_tag_images) { - // sprintf(buffer, "/tmp/image-%05d_tags.png", i); - // cout << "Writing " << buffer << endl; - // image->compute_rich_structure(); - // image->write_tag_png(buffer); - // } + image->compute_rich_structure(); - pool->release_image(i); + if(global.material_feature_nb < 0) { + sprintf(buffer, "/tmp/referential-%05d-%02d.png", i, t); + write_referential_png(buffer, hierarchy->nb_levels() - 1, image, &referential, 0); + } else if(detector) { + int n_family = 0; + int n_feature = global.material_feature_nb; + while(n_feature > detector->_pi_feature_families[n_family]->nb_features()) { + n_family++; + n_feature -= detector->_pi_feature_families[n_family]->nb_features(); + } + pf = detector->_pi_feature_families[n_family]->get_feature(n_feature); + sprintf(buffer, "/tmp/pf-%05d-%02d-%05d.png", i, t, global.material_feature_nb); + write_referential_png(buffer, + hierarchy->nb_levels() - 1, + image, + &referential, + pf); } + } + + pool->release_image(i); + } delete hierarchy; } @@ -244,7 +215,6 @@ void write_image_with_detections(const char *filename, } } - (*global.log_stream) << "Writing " << filename << endl; - + cout << "Writing " << filename << endl; result_sp.write_png(filename); }