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 "labelled_image.h"
28 LabelledImage::LabelledImage() : RichImage() {
32 LabelledImage::LabelledImage(int width, int height, int nb_targets) : RichImage(width, height) {
33 _nb_targets = nb_targets;
34 _target_poses = new Pose[_nb_targets];
37 LabelledImage::~LabelledImage() {
38 delete[] _target_poses;
41 int LabelledImage::pose_cell_label(PoseCell *cell) {
45 for(int t = 0; t < _nb_targets; t++) {
46 if(cell->contains(_target_poses + t))
48 if(!cell->negative_for_train(_target_poses + t))
52 if(positive) return 1;
53 if(negative) return -1;
57 void LabelledImage::write(ostream *out) {
58 int v = file_format_version;
60 RichImage::write(out);
61 write_var(out, &_nb_targets);
62 for(int t = 0; t < _nb_targets; t++)
63 _target_poses[t].write(out);
66 void LabelledImage::read(istream *in) {
69 if(v != file_format_version) {
70 cerr << "Pool file format version " << file_format_version << " expected,"
71 << " the file is version " << v
76 delete[] _target_poses;
77 read_var(in, &_nb_targets);
78 _target_poses = new Pose[_nb_targets];
79 for(int t = 0; t < _nb_targets; t++)
80 _target_poses[t].read(in);