24 #include <fvutils/base/roi.h>
30 namespace firevision {
44 ROI *ROI::roi_full_image = NULL;
50 start.x = start.y = width = height = image_width = image_height = line_step = pixel_step = 0;
62 ROI::ROI(
unsigned int start_x,
66 unsigned int image_width,
67 unsigned int image_height)
73 this->height = height;
74 this->image_width = image_width;
75 this->image_height = image_height;
76 line_step = image_width;
84 ROI::ROI(
const ROI &roi)
130 ROI::set_start(
unsigned int x,
unsigned int y)
140 ROI::set_width(
unsigned int width)
149 ROI::get_width()
const
158 ROI::set_height(
unsigned int height)
160 this->height = height;
167 ROI::get_height()
const
177 ROI::set_image_width(
unsigned int image_width)
179 this->image_width = image_width;
187 ROI::get_image_width()
const
197 ROI::set_image_height(
unsigned int image_height)
199 this->image_height = image_height;
207 ROI::get_image_height()
const
218 ROI::set_line_step(
unsigned int step)
228 ROI::get_line_step()
const
239 ROI::set_pixel_step(
unsigned int step)
249 ROI::get_pixel_step()
const
260 ROI::get_hint()
const
270 ROI::set_hint(
unsigned int hint)
281 ROI::contains(
unsigned int x,
unsigned int y)
283 if ((x >= start.x) && (x < start.x + width) && (y >= start.y) && (y < start.y + height)) {
284 num_hint_points += 1;
297 ROI::intersect(
ROI const &roi)
const
331 ROI::neighbours(
unsigned int x,
unsigned int y,
unsigned int margin)
const
333 return ((
static_cast<int>(x) >=
static_cast<int>(start.x) -
static_cast<int>(margin))
334 && (x <= start.x + width + margin)
335 && (
static_cast<int>(y) >=
static_cast<int>(start.y) -
static_cast<int>(margin))
336 && (y <= start.y + height + margin));
347 ROI::neighbours(
ROI *roi,
unsigned int margin)
const
350 bool overlapping_x = neighbours(roi->
start.
x, start.y, margin)
351 || neighbours(roi->
start.
x + roi->
width, start.y, margin)
358 || neighbours(start.x, roi->
start.
y, margin)
359 || neighbours(start.x, roi->
start.
y + roi->
height, margin);
361 return overlapping_x && overlapping_y;
369 ROI::extend(
unsigned int x,
unsigned int y)
372 width += start.x - x;
376 height += start.y - y;
379 if (x >= start.x + width) {
380 width += (x - (start.x + width) + 1);
382 if (y >= start.y + height) {
383 height += (y - (start.y + height) + 1);
386 num_hint_points += 1;
393 ROI::grow(
unsigned int margin)
395 if (start.x < margin) {
401 if (start.y < margin) {
407 if ((start.x + width + margin) > image_width) {
408 width += (image_width - (start.x + width));
413 if ((start.y + height + margin) > image_height) {
414 height += (image_height - (start.y + height));
429 if (roi.
start.
x < start.x) {
430 width += start.x - roi.
start.
x;
433 if (roi.
start.
y < start.y) {
434 height += start.y - roi.
start.
y;
438 width += roi.
start.
x + roi.
width - (start.x + width);
441 height += roi.
start.
y + roi.
height - (start.y + height);
454 ROI::operator<(
const ROI &roi)
const
464 ROI::operator>(
const ROI &roi)
const
476 ROI::operator==(
const ROI &roi)
const
478 return (start.x == roi.
start.
x) && (start.y == roi.
start.
y) && (width == roi.
width)
492 ROI::operator!=(
const ROI &roi)
const
502 ROI::operator=(
const ROI &roi)
504 this->start.x = roi.
start.
x;
505 this->start.y = roi.
start.
y;
506 this->width = roi.
width;
507 this->height = roi.
height;
512 this->hint = roi.
hint;
513 this->color = roi.
color;
526 ROI::get_roi_buffer_start(
unsigned char *buffer)
const
528 return (buffer + (start.y * line_step) + (start.x * pixel_step));
549 ROI::get_num_hint_points()
const
551 return num_hint_points;
565 ROI::full_image(
unsigned int width,
unsigned int height)
567 if (roi_full_image == NULL) {
568 roi_full_image =
new ROI();
569 roi_full_image->start.x = 0;
570 roi_full_image->start.y = 0;
571 roi_full_image->pixel_step = 1;
573 roi_full_image->width = width;
574 roi_full_image->height = height;
575 roi_full_image->image_width = roi_full_image->width;
576 roi_full_image->image_height = roi_full_image->height;
577 roi_full_image->line_step = roi_full_image->width;
579 return roi_full_image;
unsigned int height
ROI height.
fawkes::upoint_t start
ROI start.
unsigned int line_step
line step
unsigned int width
ROI width.
unsigned int hint
ROI hint.
unsigned int image_width
width of image that contains this ROI
color_t color
ROI primary color.
unsigned int pixel_step
pixel step
bool neighbours(unsigned int x, unsigned int y, unsigned int margin) const
Check if this ROI neighbours a pixel.
unsigned int num_hint_points
Minimum estimate of points in ROI that are attributed to the ROI hint.
unsigned int image_height
height of image that contains this ROI
Fawkes library namespace.
Point with cartesian coordinates as unsigned integers.
unsigned int x
x coordinate
unsigned int y
y coordinate