#include "gaussian.h"
PoseCellHierarchy::PoseCellHierarchy() {
- _body_cells = 0;
+ _belly_cells = 0;
}
PoseCellHierarchy::PoseCellHierarchy(LabelledImagePool *train_pool) {
train_pool->release_image(i);
}
- RelativeBodyPoseCell targets[nb_total_targets];
+ RelativeBellyPoseCell targets[nb_total_targets];
int u = 0;
for(int i = 0; i < train_pool->nb_images(); i++) {
cell_set.get_containing_cell(&pose)->get_centroid(&coarse);
- targets[u]._body_xc.set((pose._belly_xc - coarse._head_xc) / coarse._head_radius);
- targets[u]._body_yc.set((pose._belly_yc - coarse._head_yc) / coarse._head_radius);
+ targets[u]._belly_xc.set((pose._belly_xc - coarse._head_xc) / coarse._head_radius);
+ targets[u]._belly_yc.set((pose._belly_yc - coarse._head_yc) / coarse._head_radius);
u++;
pose.horizontal_flip(image->width());
cell_set.get_containing_cell(&pose)->get_centroid(&coarse);
- targets[u]._body_xc.set((pose._belly_xc - coarse._head_xc) / coarse._head_radius);
- targets[u]._body_yc.set((pose._belly_yc - coarse._head_yc) / coarse._head_radius);
+ targets[u]._belly_xc.set((pose._belly_xc - coarse._head_xc) / coarse._head_radius);
+ targets[u]._belly_yc.set((pose._belly_yc - coarse._head_yc) / coarse._head_radius);
u++;
}
scalar_t fattening = 1.1;
- Interval body_rxc, body_ryc;
+ Interval belly_rxc, belly_ryc;
- body_rxc.set(&targets[0]._body_xc);
- body_ryc.set(&targets[0]._body_yc);
+ belly_rxc.set(&targets[0]._belly_xc);
+ belly_ryc.set(&targets[0]._belly_yc);
for(int t = 0; t < nb_total_targets; t++) {
- body_rxc.swallow(&targets[t]._body_xc);
- body_ryc.swallow(&targets[t]._body_yc);
+ belly_rxc.swallow(&targets[t]._belly_xc);
+ belly_ryc.swallow(&targets[t]._belly_yc);
}
- body_rxc.min *= fattening;
- body_rxc.max *= fattening;
- body_ryc.min *= fattening;
- body_ryc.max *= fattening;
+ belly_rxc.min *= fattening;
+ belly_rxc.max *= fattening;
+ belly_ryc.min *= fattening;
+ belly_ryc.max *= fattening;
- scalar_t body_rxc_min = body_resolution * floor(body_rxc.min / body_resolution);
- int nb_body_rxc = int(ceil((body_rxc.max - body_rxc_min) / body_resolution));
+ scalar_t belly_rxc_min = belly_resolution * floor(belly_rxc.min / belly_resolution);
+ int nb_belly_rxc = int(ceil((belly_rxc.max - belly_rxc_min) / belly_resolution));
- scalar_t body_ryc_min = body_resolution * floor(body_ryc.min / body_resolution);
- int nb_body_ryc = int(ceil((body_ryc.max - body_ryc_min) / body_resolution));
+ scalar_t belly_ryc_min = belly_resolution * floor(belly_ryc.min / belly_resolution);
+ int nb_belly_ryc = int(ceil((belly_ryc.max - belly_ryc_min) / belly_resolution));
- (*global.log_stream) << "body_rxc = " << body_rxc << endl
- << "body_rxc_min = " << body_rxc_min << endl
- << "body_rxc_min + nb_body_rxc * body_resolution = " << body_rxc_min + nb_body_rxc * body_resolution << endl
+ (*global.log_stream) << "belly_rxc = " << belly_rxc << endl
+ << "belly_rxc_min = " << belly_rxc_min << endl
+ << "belly_rxc_min + nb_belly_rxc * belly_resolution = " << belly_rxc_min + nb_belly_rxc * belly_resolution << endl
<< endl
- << "body_ryc = " << body_ryc << endl
- << "body_ryc_min = " << body_ryc_min << endl
- << "body_ryc_min + nb_body_ryc * body_resolution = " << body_ryc_min + nb_body_ryc * body_resolution << endl;
+ << "belly_ryc = " << belly_ryc << endl
+ << "belly_ryc_min = " << belly_ryc_min << endl
+ << "belly_ryc_min + nb_belly_ryc * belly_resolution = " << belly_ryc_min + nb_belly_ryc * belly_resolution << endl;
- int used[nb_body_rxc * nb_body_rxc];
+ int used[nb_belly_rxc * nb_belly_rxc];
- for(int k = 0; k < nb_body_rxc * nb_body_ryc; k++) {
+ for(int k = 0; k < nb_belly_rxc * nb_belly_ryc; k++) {
used[k] = 1;
}
scalar_t rho = 0;
for(int t = 0; t < nb_total_targets; t++) {
- rho = min(rho, vx * targets[t]._body_xc.middle() + vy * targets[t]._body_yc.middle());
+ rho = min(rho, vx * targets[t]._belly_xc.middle() + vy * targets[t]._belly_yc.middle());
}
rho *= fattening;
- for(int j = 0; j < nb_body_ryc; j++) {
- for(int i = 0; i < nb_body_rxc; i++) {
+ for(int j = 0; j < nb_belly_ryc; j++) {
+ for(int i = 0; i < nb_belly_rxc; i++) {
if(
- vx * (scalar_t(i + 0) * body_resolution + body_rxc_min) +
- vy * (scalar_t(j + 0) * body_resolution + body_ryc_min) < rho
+ vx * (scalar_t(i + 0) * belly_resolution + belly_rxc_min) +
+ vy * (scalar_t(j + 0) * belly_resolution + belly_ryc_min) < rho
&&
- vx * (scalar_t(i + 1) * body_resolution + body_rxc_min) +
- vy * (scalar_t(j + 0) * body_resolution + body_ryc_min) < rho
+ vx * (scalar_t(i + 1) * belly_resolution + belly_rxc_min) +
+ vy * (scalar_t(j + 0) * belly_resolution + belly_ryc_min) < rho
&&
- vx * (scalar_t(i + 0) * body_resolution + body_rxc_min) +
- vy * (scalar_t(j + 1) * body_resolution + body_ryc_min) < rho
+ vx * (scalar_t(i + 0) * belly_resolution + belly_rxc_min) +
+ vy * (scalar_t(j + 1) * belly_resolution + belly_ryc_min) < rho
&&
- vx * (scalar_t(i + 1) * body_resolution + body_rxc_min) +
- vy * (scalar_t(j + 1) * body_resolution + body_ryc_min) < rho
+ vx * (scalar_t(i + 1) * belly_resolution + belly_rxc_min) +
+ vy * (scalar_t(j + 1) * belly_resolution + belly_ryc_min) < rho
) {
- used[i + j * nb_body_rxc] = 0;
+ used[i + j * nb_belly_rxc] = 0;
}
}
}
}
- _nb_body_cells = 0;
- for(int j = 0; j < nb_body_ryc; j++) {
- for(int i = 0; i < nb_body_rxc; i++) {
- if(used[i + nb_body_rxc * j]) {
- _nb_body_cells++;
+ _nb_belly_cells = 0;
+ for(int j = 0; j < nb_belly_ryc; j++) {
+ for(int i = 0; i < nb_belly_rxc; i++) {
+ if(used[i + nb_belly_rxc * j]) {
+ _nb_belly_cells++;
}
}
}
- _body_cells = new RelativeBodyPoseCell[_nb_body_cells];
+ _belly_cells = new RelativeBellyPoseCell[_nb_belly_cells];
- for(int j = 0; j < nb_body_ryc; j++) {
- for(int i = 0; i < nb_body_rxc; i++) {
- if(used[i + nb_body_rxc * j]) {
- if(sq(scalar_t(i) * body_resolution + body_resolution/2 + body_rxc_min) +
- sq(scalar_t(j) * body_resolution + body_resolution/2 + body_ryc_min) <= 1) {
+ for(int j = 0; j < nb_belly_ryc; j++) {
+ for(int i = 0; i < nb_belly_rxc; i++) {
+ if(used[i + nb_belly_rxc * j]) {
+ if(sq(scalar_t(i) * belly_resolution + belly_resolution/2 + belly_rxc_min) +
+ sq(scalar_t(j) * belly_resolution + belly_resolution/2 + belly_ryc_min) <= 1) {
(*global.log_stream) << "*";
} else {
(*global.log_stream) << "X";
}
int k = 0;
- for(int j = 0; j < nb_body_ryc; j++) {
- for(int i = 0; i < nb_body_rxc; i++) {
+ for(int j = 0; j < nb_belly_ryc; j++) {
+ for(int i = 0; i < nb_belly_rxc; i++) {
- if(used[i + nb_body_rxc * j]) {
+ if(used[i + nb_belly_rxc * j]) {
- RelativeBodyPoseCell mother;
+ RelativeBellyPoseCell mother;
- scalar_t x = scalar_t(i) * body_resolution + body_rxc_min;
- scalar_t y = scalar_t(j) * body_resolution + body_ryc_min;
+ scalar_t x = scalar_t(i) * belly_resolution + belly_rxc_min;
+ scalar_t y = scalar_t(j) * belly_resolution + belly_ryc_min;
- mother._body_xc.set(x, x + body_resolution);
- mother._body_yc.set(y, y + body_resolution);
+ mother._belly_xc.set(x, x + belly_resolution);
+ mother._belly_yc.set(y, y + belly_resolution);
- _body_cells[k++] = mother;
+ _belly_cells[k++] = mother;
}
}
}
- (*global.log_stream) << _nb_body_cells << " body cells." << endl;
+ (*global.log_stream) << _nb_belly_cells << " belly cells." << endl;
}
PoseCellHierarchy::~PoseCellHierarchy() {
- delete[] _body_cells;
+ delete[] _belly_cells;
}
int PoseCellHierarchy::nb_levels() {
case 1:
{
- // Here we split the body-center coordinate cell part
+ // Here we split the belly-center coordinate cell part
PoseCell cell = *root;
scalar_t r = sqrt(cell._head_radius.min * cell._head_radius.max);
scalar_t x = (cell._head_xc.min + cell._head_xc.max) / 2.0;
scalar_t y = (cell._head_yc.min + cell._head_yc.max) / 2.0;
- for(int k = 0; k < _nb_body_cells; k++) {
- cell._belly_xc.min = (_body_cells[k]._body_xc.min * r) + x;
- cell._belly_xc.max = (_body_cells[k]._body_xc.max * r) + x;
- cell._belly_yc.min = (_body_cells[k]._body_yc.min * r) + y;
- cell._belly_yc.max = (_body_cells[k]._body_yc.max * r) + y;
+ for(int k = 0; k < _nb_belly_cells; k++) {
+ cell._belly_xc.min = (_belly_cells[k]._belly_xc.min * r) + x;
+ cell._belly_xc.max = (_belly_cells[k]._belly_xc.max * r) + x;
+ cell._belly_yc.min = (_belly_cells[k]._belly_yc.min * r) + y;
+ cell._belly_yc.max = (_belly_cells[k]._belly_yc.max * r) + y;
cell_set->add_cell(&cell);
}
}
write_var(os, &_min_head_radius);
write_var(os, &_max_head_radius);
write_var(os, &_root_cell_nb_xy_per_scale);
- write_var(os, &_nb_body_cells);
- for(int k = 0; k < _nb_body_cells; k++)
- write_var(os, &_body_cells[k]);
+ write_var(os, &_nb_belly_cells);
+ for(int k = 0; k < _nb_belly_cells; k++)
+ write_var(os, &_belly_cells[k]);
}
void PoseCellHierarchy::read(istream *is) {
- delete[] _body_cells;
+ delete[] _belly_cells;
read_var(is, &_min_head_radius);
read_var(is, &_max_head_radius);
read_var(is, &_root_cell_nb_xy_per_scale);
- read_var(is, &_nb_body_cells);
- delete[] _body_cells;
- _body_cells = new RelativeBodyPoseCell[_nb_body_cells];
- for(int k = 0; k < _nb_body_cells; k++) {
- read_var(is, &_body_cells[k]);
+ read_var(is, &_nb_belly_cells);
+ delete[] _belly_cells;
+ _belly_cells = new RelativeBellyPoseCell[_nb_belly_cells];
+ for(int k = 0; k < _nb_belly_cells; k++) {
+ read_var(is, &_belly_cells[k]);
}
}