X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=pi_referential.cc;h=07c5011fecf317120da08051dd30cbb54f44c8c7;hb=e1d8ccc0f252d9be9590fe5a6106a4336762b6aa;hp=8c0e8ac78c7ad097baca929dfa70a458d5f28425;hpb=f7e3efe41ffb65d89e8f2ce814c23ff90ad24f34;p=folded-ctf.git
diff --git a/pi_referential.cc b/pi_referential.cc
index 8c0e8ac..07c5011 100644
--- a/pi_referential.cc
+++ b/pi_referential.cc
@@ -12,7 +12,9 @@
// 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 //
+// Written by Francois Fleuret //
+// (C) Idiap Research Institute //
+// //
// Contact for comments & bug reports //
///////////////////////////////////////////////////////////////////////////
@@ -52,11 +54,6 @@ void PiReferential::draw_frame(RGBImage *image,
r = 255; g = 0; b = 0;
break;
- case PiReferential::RM_BODY:
- case PiReferential::RM_BODY_EDGES:
- r = 0; g = 128; b = 255;
- break;
-
default:
cerr << "INCONSISTENCY" << endl;
abort();
@@ -75,20 +72,10 @@ void PiReferential::draw_frame(RGBImage *image,
image->draw_line(2, r, g, b, x3, y3, x4, y4);
image->draw_line(2, r, g, b, x4, y4, x1, y1);
} else {
- // int xc = (x1 + x2 + x3 + x4)/4, yc = (y1 + y2 + y3 + y4)/4;
- // image->draw_line(1, r, g, b, xc - delta, yc, xc + delta, yc);
- // image->draw_line(1, r, g, b, xc, yc - delta, xc, yc + delta);
image->draw_line(2, r, g, b, x1, y1, x2, y2);
image->draw_line(2, r, g, b, x2, y2, x3, y3);
image->draw_line(2, r, g, b, x3, y3, x4, y4);
image->draw_line(2, r, g, b, x4, y4, x1, y1);
- // image->draw_line(2, r, g, b,
- // (2*xc + 5 * x1 + 5 * x2)/12, (2 * yc + 5 * y1 + 5 * y2)/12,
- // (x1 + x2)/2, (y1 + y2)/2);
- // image->draw_line(6, r, g, b,
- // (2*xc + 3 * x2 + 3 * x3)/8, (2 * yc + 3 * y2 + 3 * y3)/8,
- // (x2 + x3)/2, (y2 + y3)/2
- // );
}
}
@@ -120,11 +107,6 @@ void PiReferential::draw_window(RGBImage *image,
r = 255; g = 0; b = 0;
break;
- case PiReferential::RM_BODY:
- case PiReferential::RM_BODY_EDGES:
- r = 0; g = 128; b = 255;
- break;
-
default:
cerr << "INCONSISTENCY" << endl;
abort();
@@ -142,37 +124,12 @@ void PiReferential::draw_window(RGBImage *image,
image->draw_line(6, r, g, b, xmax, ymax, xmin, ymax);
image->draw_line(6, r, g, b, xmin, ymax, xmin, ymin);
-// if(filled) {
-// int delta = 6;
-// for(int d = ymin - ymax; d <= xmax - xmin; d += delta) {
-// int x1 = xmin + d;
-// int y1 = ymin;
-// int x2 = xmin + d + ymax - ymin;
-// int y2 = ymax;
-// if(x1 < xmin) { y1 = y1 + (xmin - x1); x1 = xmin; }
-// if(x2 > xmax) { y2 = y2 - (x2 - xmax); x2 = xmax; }
-// image->draw_line(3, r, g, b, x1, y1, x2, y2);
-// }
-// }
-
r = 0; g = 0; b = 0;
image->draw_line(2, r, g, b, xmin, ymin, xmax, ymin);
image->draw_line(2, r, g, b, xmax, ymin, xmax, ymax);
image->draw_line(2, r, g, b, xmax, ymax, xmin, ymax);
image->draw_line(2, r, g, b, xmin, ymax, xmin, ymin);
-// if(filled) {
-// int delta = 6;
-// for(int d = ymin - ymax; d <= xmax - xmin; d += delta) {
-// int x1 = xmin + d;
-// int y1 = ymin;
-// int x2 = xmin + d + ymax - ymin;
-// int y2 = ymax;
-// if(x1 < xmin) { y1 = y1 + (xmin - x1); x1 = xmin; }
-// if(x2 > xmax) { y2 = y2 - (x2 - xmax); x2 = xmax; }
-// image->draw_line(1, r, g, b, x1, y1, x2, y2);
-// }
-// }
} else {
image->draw_line(2, r, g, b, xmin, ymin, xmax, ymin);
image->draw_line(2, r, g, b, xmax, ymin, xmax, ymax);
@@ -194,131 +151,6 @@ void PiReferential::draw_window(RGBImage *image,
}
-void PiReferential::draw_edge_and_scale(RGBImage *image,
- int registration_mode, Rectangle *window,
- int _tag, int _edge_scale) {
- const int ref_radius = 10;
- int r, g, b;
- int edges = 0;
-
- switch(registration_mode) {
-
- case PiReferential::RM_HEAD:
- r = 0; g = 255; b = 0;
- break;
-
- case PiReferential::RM_HEAD_NO_POLARITY:
- r = 128; g = 255; b = 128;
- break;
-
- case PiReferential::RM_BELLY:
- r = 64; g = 0; b = 255;
- break;
-
- case PiReferential::RM_BELLY_NO_POLARITY:
- r = 192; g = 128; b = 255;
- break;
-
- case PiReferential::RM_HEAD_BELLY_EDGES:
- edges = 1;
- case PiReferential::RM_HEAD_BELLY:
- r = 255; g = 0; b = 0;
- break;
-
- case PiReferential::RM_BODY_EDGES:
- edges = 1;
- case PiReferential::RM_BODY:
- r = 0; g = 128; b = 255;
- break;
-
- default:
- cerr << "INCONSISTENCY" << endl;
- abort();
- }
-
- scalar_t xc = (window->xmin + window->xmax)/2;
- scalar_t yc = (window->ymin + window->ymax)/2;
- int radius = ref_radius * (1 << _edge_scale);
-
- image->draw_ellipse(1, r, g, b, xc, yc, radius, radius, 0);
-
- if(_tag >= RichImage::first_edge_tag && _tag < RichImage::first_edge_tag + RichImage::nb_edge_tags) {
-
- scalar_t dx, dy;
-
- switch(_tag - RichImage::first_edge_tag) {
- case 0:
- dx = 0; dy = -1;
- break;
-
- case 1:
- dx = 1; dy = -1;
- break;
-
- case 2:
- dx = 1; dy = 0;
- break;
-
- case 3:
- dx = 1; dy = 1;
- break;
-
- case 4:
- dx = 0; dy = 1;
- break;
-
- case 5:
- dx = -1; dy = 1;
- break;
-
- case 6:
- dx = -1; dy = 0;
- break;
-
- case 7:
- dx = -1; dy = -1;
- break;
-
- default:
- abort();
- }
-
- scalar_t l = sqrt(dx * dx + dy * dy);
-
-// dx = dx / l;
-// dy = dy / l;
-
- if(edges) {
- int delta = 3;
- image->draw_ellipse(1, r, g, b, xc, yc, radius + delta, radius + delta, 0);
- }
-
- for(scalar_t u = 0; u <= radius; u += 0.1) {
- scalar_t s = sqrt(radius * radius - (u * u * l * l))/l;
- image->draw_line(2, r, g, b,
- int(xc + u * dx - s * dy), int(yc + u * dy + s * dx),
- int(xc + u * dx + s * dy), int(yc + u * dy - s * dx));
- }
-
-// for(int y = yc - radius; y <= yc + radius; y++) {
-// for(int x = xc - radius; x <= xc + radius; x++) {
-// if(x >= 0 && x < image->width() && y >= 0 && y < image->height() &&
-// (x - xc) * dx + (y - yc) * dy >= 0) {
-// image->draw_point(r, g, b, x, y);
-// }
-// }
-// }
-
- }
-
- else if(_tag == RichImage::variance_tag) {
- image->draw_ellipse(1, r, g, b, xc, yc, 8, 8, 0);
- }
-
- // else if(_tag >= RichImage::first_gray_tag && _tag < RichImage::first_gray_tag + RichImage::nb_gray_tags) {
- // }
-}
-
PiReferential::PiReferential(PoseCell *cell) {
scalar_t head_radius = sqrt(scalar_t(cell->_head_radius.min * cell->_head_radius.max));
@@ -338,31 +170,35 @@ PiReferential::PiReferential(PoseCell *cell) {
// Body location
+ // **********************************************************************
+ // Useless code, but necessary to keep the exact same results with
+ // g++ 4.1 and -O3 options on reference experiments.
_body_xc = cell->_belly_xc.middle() * discrete_scale_ratio;
_body_yc = cell->_belly_yc.middle() * discrete_scale_ratio;
- _body_window_scaling = sqrt(_body_radius_1 * _body_radius_2);
-
+ _body_tilt = 0;
if((_head_xc - _body_xc) * cos(_body_tilt) + (_head_yc - _body_yc) * sin(_body_tilt) > 0) {
_body_tilt += M_PI;
}
+ // **********************************************************************
// Belly location
const scalar_t belly_frame_factor = 2.0;
- _belly_xc = _body_xc;
- _belly_yc = _body_yc;
+ _belly_xc = cell->_belly_xc.middle() * discrete_scale_ratio;
+ _belly_yc = cell->_belly_yc.middle() * discrete_scale_ratio;
_belly_window_scaling = _head_window_scaling * belly_frame_factor;
// Head-belly location
- _head_belly_xc = (_head_xc + _body_xc) * 0.5;
- _head_belly_yc = (_head_yc + _body_yc) * 0.5;
+ _head_belly_xc = (_head_xc + _belly_xc) * 0.5;
+ _head_belly_yc = (_head_yc + _belly_yc) * 0.5;
//////////////////////////////////////////////////////////////////////
// Frames
if(_body_xc >= _head_xc) {
+ // if(_belly_xc >= _head_xc) {
_horizontal_polarity = 1;
} else {
_horizontal_polarity = -1;
@@ -413,20 +249,10 @@ PiReferential::PiReferential(PoseCell *cell) {
scalar_t l = sqrt(_head_belly_vx * _head_belly_vx + _head_belly_vy * _head_belly_vy);
- _head_belly_vx = _head_belly_vx/l * _head_radius * 2;
- _head_belly_vy = _head_belly_vy/l * _head_radius * 2;
+ _head_belly_vx = (_head_belly_vx / l) * _head_radius * 2;
+ _head_belly_vy = (_head_belly_vy / l) * _head_radius * 2;
_head_belly_edge_shift = int(floor(- RichImage::nb_edge_tags * atan2(_head_belly_ux, _head_belly_uy) / (2 * M_PI) + 0.5));
_head_belly_edge_shift = (RichImage::nb_edge_tags + _head_belly_edge_shift) % RichImage::nb_edge_tags;
-
- // Body frame
-
- _body_ux = cos(_body_tilt) * _body_radius_1 * 2.0;
- _body_uy = sin(_body_tilt) * _body_radius_1 * 2.0;
- _body_vx = - sin(_body_tilt) * _body_radius_2 * 2.0;
- _body_vy = cos(_body_tilt) * _body_radius_2 * 2.0;
-
- _body_edge_shift = int(floor(RichImage::nb_edge_tags * _body_tilt / (2 * M_PI) + 0.5));
- _body_edge_shift = (RichImage::nb_edge_tags + _body_edge_shift) % RichImage::nb_edge_tags;
}
int PiReferential::common_scale() {
@@ -489,16 +315,6 @@ void PiReferential::register_rectangle(int registration_mode,
}
break;
- case RM_BODY:
- case RM_BODY_EDGES:
- {
- xc = _body_xc + alpha * _body_ux + beta * _body_vx;
- yc = _body_yc + alpha * _body_uy + beta * _body_vy;
- w = (original->xmax - original->xmin) * _body_window_scaling;
- h = (original->ymax - original->ymin) * _body_window_scaling;
- }
- break;
-
default:
cerr << "Undefined registration mode." << endl;
abort();
@@ -527,7 +343,6 @@ int PiReferential::register_edge(int registration_mode, int edge_type) {
case PiReferential::RM_HEAD:
case PiReferential::RM_BELLY:
case PiReferential::RM_HEAD_BELLY:
- case PiReferential::RM_BODY:
if(_horizontal_polarity < 0) {
e = (RichImage::nb_edge_tags - e) % RichImage::nb_edge_tags;
}
@@ -540,13 +355,6 @@ int PiReferential::register_edge(int registration_mode, int edge_type) {
e += _head_belly_edge_shift;
break;
- case PiReferential::RM_BODY_EDGES:
- if(_horizontal_polarity < 0) {
- e = (RichImage::nb_edge_tags - e) % RichImage::nb_edge_tags;
- }
- e += _body_edge_shift;
- break;
-
default:
cerr << "INCONSISTENCY" << endl;
abort();
@@ -564,22 +372,6 @@ int PiReferential::register_edge(int registration_mode, int edge_type) {
void PiReferential::draw(RGBImage *image, int level) {
int x1, y1, x2, y2, x3, y3, x4, y4;
- if(level >= 2) {
-
- // Draw the RM_BODY reference frame
-
- x1 = int(_body_xc + _body_ux + _body_vx);
- y1 = int(_body_yc + _body_uy + _body_vy);
- x2 = int(_body_xc - _body_ux + _body_vx);
- y2 = int(_body_yc - _body_uy + _body_vy);
- x3 = int(_body_xc - _body_ux - _body_vx);
- y3 = int(_body_yc - _body_uy - _body_vy);
- x4 = int(_body_xc + _body_ux - _body_vx);
- y4 = int(_body_yc + _body_uy - _body_vy);
-
- draw_frame(image, RM_BODY, x1, y1, x2, y2, x3, y3, x4, y4);
- }
-
if(level >= 1) {
// Draw the RM_BELLY reference frame
@@ -643,12 +435,6 @@ void PiReferential::print_registration_mode(ostream *out, int registration_mode)
case RM_HEAD_BELLY_EDGES:
(*out) << "RM_HEAD_BELLY_EDGES";
break;
- case RM_BODY:
- (*out) << "RM_BODY";
- break;
- case RM_BODY_EDGES:
- (*out) << "RM_BODY_EDGES";
- break;
default:
abort();
}