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 "labelled_image.h"
27 LabelledImage::LabelledImage() : RichImage() {
31 LabelledImage::LabelledImage(int width, int height, int nb_targets) : RichImage(width, height) {
32 _nb_targets = nb_targets;
33 _target_poses = new Pose[_nb_targets];
36 LabelledImage::~LabelledImage() {
37 delete[] _target_poses;
40 int LabelledImage::pose_cell_label(PoseCell *cell) {
44 for(int t = 0; t < _nb_targets; t++) {
45 if(cell->contains(_target_poses + t))
47 if(!cell->negative_for_train(_target_poses + t))
51 if(positive) return 1;
52 if(negative) return -1;
56 void LabelledImage::write(ostream *out) {
57 int v = file_format_version;
59 RichImage::write(out);
60 write_var(out, &_nb_targets);
61 for(int t = 0; t < _nb_targets; t++)
62 _target_poses[t].write(out);
65 void LabelledImage::read(istream *in) {
68 if(v != file_format_version) {
69 cerr << "Pool file format version " << file_format_version << " expected,"
70 << " the file is version " << v
75 delete[] _target_poses;
76 read_var(in, &_nb_targets);
77 _target_poses = new Pose[_nb_targets];
78 for(int t = 0; t < _nb_targets; t++)
79 _target_poses[t].read(in);