X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=folded-ctf.git;a=blobdiff_plain;f=pose.cc;h=6ac5b39a75df5da4796edd3cc65c290dc315826f;hp=ed6c7058afc321edac0301f2e8e9e964d8a8876d;hb=HEAD;hpb=d922ad61d35e9a6996730bec24b16f8bf7bc426c diff --git a/pose.cc b/pose.cc index ed6c705..6ac5b39 100644 --- a/pose.cc +++ b/pose.cc @@ -1,20 +1,26 @@ - -/////////////////////////////////////////////////////////////////////////// -// 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 version 3 as + * published by the Free Software Foundation. + * + * 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 @@ -26,30 +32,7 @@ Pose::Pose() { void Pose::horizontal_flip(scalar_t scene_width) { _head_xc = scene_width - 1 - _head_xc; - _body_xc = scene_width - 1 - _body_xc; -} - -void Pose::translate(scalar_t dx, scalar_t dy) { - _bounding_box_xmin += dx; - _bounding_box_ymin += dy; - _bounding_box_xmax += dx; - _bounding_box_ymax += dy; - _head_xc += dx; - _head_yc += dy; - _body_xc += dx; - _body_yc += dy; -} - -void Pose::scale(scalar_t factor) { - _bounding_box_xmin *= factor; - _bounding_box_ymin *= factor; - _bounding_box_xmax *= factor; - _bounding_box_ymax *= factor; - _head_xc *= factor; - _head_yc *= factor; - _head_radius *= factor; - _body_xc *= factor; - _body_yc *= factor; + _belly_xc = scene_width - 1 - _belly_xc; } const scalar_t tolerance_scale_ratio_for_hit = 1.5; @@ -74,7 +57,7 @@ bool Pose::hit(int level, Pose *pose) { // Belly location - if(sq(_body_xc - pose->_body_xc) + sq(_body_yc - pose->_body_yc) > 4 * sq_delta) + if(sq(_belly_xc - pose->_belly_xc) + sq(_belly_yc - pose->_belly_yc) > 4 * sq_delta) return false; if(level == 1) return true; @@ -106,7 +89,7 @@ bool Pose::collide(int level, Pose *pose) { // Belly location - if(sq(_body_xc - pose->_body_xc) + sq(_body_yc - pose->_body_yc) <= sq_delta) + if(sq(_belly_xc - pose->_belly_xc) + sq(_belly_yc - pose->_belly_yc) <= sq_delta) return true; if(level == 1) return false; @@ -117,43 +100,33 @@ bool Pose::collide(int level, Pose *pose) { } void Pose::draw(int thickness, int r, int g, int b, int level, RGBImage *image) { + // Draw the head circle image->draw_ellipse(thickness, r, g, b, _head_xc, _head_yc, _head_radius, _head_radius, 0); - // int vx = int(cos(_head_tilt) * _head_radius); - // int vy = int(sin(_head_tilt) * _head_radius); - // image->draw_line(thickness, r, g, b, _head_xc, _head_yc, _head_xc + vx, _head_yc + vy); - if(level == 1) { - // image->draw_line(thickness, r, g, b, - // int(_body_xc) - delta, int(_body_yc), - // int(_body_xc) + delta, int(_body_yc)); - - // image->draw_line(thickness, r, g, b, - // int(_body_xc), int(_body_yc) - delta, - // int(_body_xc), int(_body_yc) + delta); - - scalar_t vx = _body_xc - _head_xc, vy = _body_yc - _head_yc; + scalar_t vx = _belly_xc - _head_xc, vy = _belly_yc - _head_yc; scalar_t l = sqrt(vx * vx + vy * vy); vx /= l; vy /= l; - scalar_t body_radius = 12 + thickness / 2; + scalar_t belly_radius = 12 + thickness / 2; - if(l > _head_radius + thickness + body_radius) { + if(l > _head_radius + thickness + belly_radius) { image->draw_line(thickness, r, g, b, _head_xc + vx * (_head_radius + thickness/2), _head_yc + vy * (_head_radius + thickness/2), - _body_xc - vx * (body_radius - thickness/2), - _body_yc - vy * (body_radius - thickness/2)); + _belly_xc - vx * (belly_radius - thickness/2), + _belly_yc - vy * (belly_radius - thickness/2)); } // An ugly way to make a filled disc - for(scalar_t u = 0; u < body_radius; u += thickness / 2) { - image->draw_ellipse(thickness, r, g, b, _body_xc, _body_yc, u, u, 0); + + for(scalar_t u = 0; u < belly_radius; u += thickness / 2) { + image->draw_ellipse(thickness, r, g, b, _belly_xc, _belly_yc, u, u, 0); } } @@ -163,8 +136,8 @@ void Pose::print(ostream *out) { (*out) << " _head_xc " << _head_xc << endl; (*out) << " _head_yc " << _head_yc << endl; (*out) << " _head_radius " << _head_radius << endl; - (*out) << " _body_xc " << _body_xc << endl; - (*out) << " _body_yc " << _body_yc << endl; + (*out) << " _belly_xc " << _belly_xc << endl; + (*out) << " _belly_yc " << _belly_yc << endl; } void Pose::write(ostream *out) { @@ -174,8 +147,8 @@ void Pose::write(ostream *out) { write_var(out, &_bounding_box_ymax); write_var(out, &_head_xc); write_var(out, &_head_yc); write_var(out, &_head_radius); - write_var(out, &_body_xc); - write_var(out, &_body_yc); + write_var(out, &_belly_xc); + write_var(out, &_belly_yc); } void Pose::read(istream *in) { @@ -185,6 +158,6 @@ void Pose::read(istream *in) { read_var(in, &_bounding_box_ymax); read_var(in, &_head_xc); read_var(in, &_head_yc); read_var(in, &_head_radius); - read_var(in, &_body_xc); - read_var(in, &_body_yc); + read_var(in, &_belly_xc); + read_var(in, &_belly_yc); }