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/>.
31 memset(this, 0, sizeof(*this));
34 void Pose::horizontal_flip(scalar_t scene_width) {
35 _head_xc = scene_width - 1 - _head_xc;
36 _belly_xc = scene_width - 1 - _belly_xc;
39 const scalar_t tolerance_scale_ratio_for_hit = 1.5;
40 const scalar_t tolerance_distance_factor_for_hit = 1.0;
42 bool Pose::hit(int level, Pose *pose) {
46 if(_head_radius/pose->_head_radius > tolerance_scale_ratio_for_hit ||
47 pose->_head_radius/_head_radius > tolerance_scale_ratio_for_hit)
50 scalar_t sq_delta = _head_radius * pose->_head_radius * sq(tolerance_distance_factor_for_hit);
54 if(sq(_head_xc - pose->_head_xc) + sq(_head_yc - pose->_head_yc) > sq_delta)
57 if(level == 0) return true;
61 if(sq(_belly_xc - pose->_belly_xc) + sq(_belly_yc - pose->_belly_yc) > 4 * sq_delta)
64 if(level == 1) return true;
66 cerr << "Hit criterion is undefined for level " << level << endl;
71 const scalar_t tolerance_scale_ratio_for_collide = 1.2;
72 const scalar_t tolerance_distance_factor_for_collide = 0.25;
74 bool Pose::collide(int level, Pose *pose) {
78 if(_head_radius/pose->_head_radius > tolerance_scale_ratio_for_collide ||
79 pose->_head_radius/_head_radius > tolerance_scale_ratio_for_collide)
82 scalar_t sq_delta = _head_radius * pose->_head_radius * sq(tolerance_distance_factor_for_collide);
86 if(sq(_head_xc - pose->_head_xc) + sq(_head_yc - pose->_head_yc) <= sq_delta)
89 if(level == 0) return false;
93 if(sq(_belly_xc - pose->_belly_xc) + sq(_belly_yc - pose->_belly_yc) <= sq_delta)
96 if(level == 1) return false;
98 cerr << "Colliding criterion is undefined for level " << level << endl;
103 void Pose::draw(int thickness, int r, int g, int b, int level, RGBImage *image) {
105 // Draw the head circle
107 image->draw_ellipse(thickness, r, g, b,
108 _head_xc, _head_yc, _head_radius, _head_radius, 0);
112 scalar_t vx = _belly_xc - _head_xc, vy = _belly_yc - _head_yc;
113 scalar_t l = sqrt(vx * vx + vy * vy);
117 scalar_t belly_radius = 12 + thickness / 2;
119 if(l > _head_radius + thickness + belly_radius) {
120 image->draw_line(thickness, r, g, b,
121 _head_xc + vx * (_head_radius + thickness/2),
122 _head_yc + vy * (_head_radius + thickness/2),
123 _belly_xc - vx * (belly_radius - thickness/2),
124 _belly_yc - vy * (belly_radius - thickness/2));
127 // An ugly way to make a filled disc
129 for(scalar_t u = 0; u < belly_radius; u += thickness / 2) {
130 image->draw_ellipse(thickness, r, g, b, _belly_xc, _belly_yc, u, u, 0);
136 void Pose::print(ostream *out) {
137 (*out) << " _head_xc " << _head_xc << endl;
138 (*out) << " _head_yc " << _head_yc << endl;
139 (*out) << " _head_radius " << _head_radius << endl;
140 (*out) << " _belly_xc " << _belly_xc << endl;
141 (*out) << " _belly_yc " << _belly_yc << endl;
144 void Pose::write(ostream *out) {
145 write_var(out, &_bounding_box_xmin);
146 write_var(out, &_bounding_box_ymin);
147 write_var(out, &_bounding_box_xmax);
148 write_var(out, &_bounding_box_ymax);
149 write_var(out, &_head_xc); write_var(out, &_head_yc);
150 write_var(out, &_head_radius);
151 write_var(out, &_belly_xc);
152 write_var(out, &_belly_yc);
155 void Pose::read(istream *in) {
156 read_var(in, &_bounding_box_xmin);
157 read_var(in, &_bounding_box_ymin);
158 read_var(in, &_bounding_box_xmax);
159 read_var(in, &_bounding_box_ymax);
160 read_var(in, &_head_xc); read_var(in, &_head_yc);
161 read_var(in, &_head_radius);
162 read_var(in, &_belly_xc);
163 read_var(in, &_belly_yc);