delete[] _content;
}
-void Image::crop(int xmin, int ymin, int width, int height) {
- ASSERT(xmin >= 0 && xmin + width <= _width &&
- ymin >= 0 && ymin + height <= _height);
- unsigned char *new_content = new unsigned char[width * height];
- for(int y = 0; y < height; y++) {
- for(int x = 0; x < width; x++) {
- new_content[x + (y * width)] = _content[x + xmin + _width * (y + ymin)];
- }
- }
- delete[] _content;
- _content = new_content;
- _width = width;
- _height = height;
-}
-
void Image::to_rgb(RGBImage *image) {
int c;
for(int y = 0; y < _height; y++) {
virtual ~Image();
- virtual void crop(int xmin, int ymin, int width, int height);
virtual void to_rgb(RGBImage *image);
virtual void read(istream *in);
return 0;
}
-void LabelledImage::crop(int xmin, int ymin, int width, int height) {
- RichImage::crop(xmin, ymin, width, height);
- for(int t = 0; t < _nb_targets; t++) {
- _target_poses[t].translate(- xmin, - ymin);
- }
-}
-
-void LabelledImage::reduce() {
- int xmin = _width, xmax = 0, ymin = _height, ymax = 0;
- if(_nb_targets > 0) {
- for(int t = 0; t < _nb_targets; t++) {
- xmin = min(xmin, int(_target_poses[t]._bounding_box_xmin));
- ymin = min(ymin, int(_target_poses[t]._bounding_box_ymin));
- xmax = max(xmax, int(_target_poses[t]._bounding_box_xmax));
- ymax = max(ymax, int(_target_poses[t]._bounding_box_ymax));
- }
- } else {
- xmin = 0; ymin = 0;
- xmax = 640; ymax = 480;
- }
- xmin = max(0, xmin);
- ymin = max(0, ymin);
- xmax = min(_width, xmax);
- ymax = min(_height, ymax);
- crop(xmin, ymin, xmax - xmin, ymax - ymin);
-}
-
void LabelledImage::write(ostream *out) {
int v = file_format_version;
write_var(out, &v);
// it is far enough from any target
int pose_cell_label(PoseCell *cell);
- void crop(int xmin, int ymin, int width, int height);
- void reduce();
-
virtual void write(ostream *out);
virtual void read(istream *in);
};
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
- // );
}
}
// Frames
if(_body_xc >= _head_xc) {
+// if(_belly_xc >= _head_xc) {
_horizontal_polarity = 1;
} else {
_horizontal_polarity = -1;
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;
}
scalar_t _head_ux, _head_uy, _head_vx, _head_vy;
scalar_t _head_ux_nopolarity, _head_uy_nopolarity, _head_vx_nopolarity, _head_vy_nopolarity;
- // The body frame in that _common_scale. The vectors are of length the radii of the ellipse
+ // Useless fields, but they are necessary so that the optimized code
+ // with g++ gives the same results as some reference
+ // experiments. Sorry for that.
scalar_t _body_xc, _body_yc;
- scalar_t _body_radius_1, _body_radius_2;
+// scalar_t _body_radius_1, _body_radius_2;
scalar_t _body_tilt;
- // The belly frame is defined by the body location and head scale
+ // The belly frame is defined by the belly location and head scale
scalar_t _belly_xc, _belly_yc;
scalar_t _belly_ux, _belly_uy, _belly_vx, _belly_vy;
scalar_t _belly_ux_nopolarity, _belly_uy_nopolarity, _belly_vx_nopolarity, _belly_vy_nopolarity;
scalar_t _belly_window_scaling;
- // The head-belly frame is defined by the head location and the body
- // center location
+ // The head-belly frame is defined by the head location and the belly
scalar_t _head_belly_xc, _head_belly_yc;
scalar_t _head_belly_ux, _head_belly_uy, _head_belly_vx, _head_belly_vy;
int _head_belly_edge_shift;
PiReferential(PoseCell *cell);
enum {
- // A frame centered on the head, of size four times the head radius
- // and, flipped verically if the body center is on the left of the
- // head center
+ // A square frame centered on the head, of size four times the
+ // head radius and, flipped vertically if the belly is on the left
+ // of the head center
RM_HEAD,
// Same as above, without the flipping
RM_HEAD_NO_POLARITY,
- // A frame centered on the body center, of size size times the
- // head rardius, flipped vertically if the body center is on the
- // left of the head center
+
+ // A frame centered on the belly, of size eight times the head
+ // radius, flipped vertically if the belly is on the left of the
+ // head center
RM_BELLY,
// Same as above, without the flipping
RM_BELLY_NO_POLARITY,
// A frame centered on the middle point between the head center
- // and the body center, of size twice the distance head center -
- // body center in the head-body direction, and of four times the
- // head radius in the other
+ // and the belly, of size twice the distance head center - belly
+ // in the head-belly direction, and of four times the head radius
+ // in the other
RM_HEAD_BELLY,
// Same as above with rotation of the edges
- RM_HEAD_BELLY_EDGES,
+ RM_HEAD_BELLY_EDGES
};
int common_scale();
_belly_xc = scene_width - 1 - _belly_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;
- _belly_xc += dx;
- _belly_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;
- _belly_xc *= factor;
- _belly_yc *= factor;
-}
-
const scalar_t tolerance_scale_ratio_for_hit = 1.5;
const scalar_t tolerance_distance_factor_for_hit = 1.0;
bool collide(int level, Pose *pose);
void horizontal_flip(scalar_t scene_width);
- void translate(scalar_t dx, scalar_t dy);
- void scale(scalar_t factor);
void draw(int thickness, int r, int g, int b, int level, RGBImage *image);
}
}
- const unsigned int var_square_size = 16;
+ const int var_square_size = 16;
int k00 = - 2 + width * (- 2);
int k01 = - 1 + width * (- 2);
y - int(var_square_size/2) >= 0 &&
y + int(var_square_size/2) < height) {
- unsigned int s =
+ int s =
+ local_sum_pixel_map[ - var_square_size/2 + width * ( - var_square_size / 2)]
+ local_sum_pixel_map[ + var_square_size/2 + width * ( + var_square_size / 2)]
- local_sum_pixel_map[ - var_square_size/2 + width * ( + var_square_size / 2)]
- local_sum_pixel_map[ + var_square_size/2 + width * ( - var_square_size / 2)];
- unsigned int s_sq =
+ int s_sq =
+ local_sum_sq_pixel_map[ - var_square_size/2 + width * ( - var_square_size / 2)]
+ local_sum_sq_pixel_map[ + var_square_size/2 + width * ( + var_square_size / 2)]
- local_sum_sq_pixel_map[ - var_square_size/2 + width * ( + var_square_size / 2)]
delete[] scale_pixel_maps;
}
-void RichImage::crop(int xmin, int ymin, int width, int height) {
- free();
- Image::crop(xmin, ymin, width, height);
-}
-
RichImage::RichImage() : Image() {
_width_at_scale = 0;
_height_at_scale = 0;
virtual ~RichImage();
virtual void compute_rich_structure();
- virtual void crop(int xmin, int ymin, int width, int height);
virtual void write(ostream *out);
echo
+######################################################################
# Generating the pool file
DATA_PATH=./rmk-data
else
- echo "Can not find the RateMyKitten images in ${DATA_PATH}. You can" >&2
- echo "download them from ${MAIN_URL}" >&2
+ echo "Can not find the RateMyKitten images in ${DATA_PATH}. You can download" >&2
+ echo "them from ${MAIN_URL}" >&2
exit 1
fi
+######################################################################
# Running the computation per se
RESULT_DIR=./results