Box+Poly: Remove direct accessors to {Hi,Lo}{X,Y}
This commit is contained in:
parent
c2a7f7b593
commit
8f685b3d66
26
src/zm_box.h
26
src/zm_box.h
|
@ -32,22 +32,18 @@ class Box {
|
|||
Box() = default;
|
||||
Box(Vector2 p_lo, Vector2 p_hi) : lo(p_lo), hi(p_hi), size(Vector2::Range(hi, lo)) {}
|
||||
|
||||
inline const Vector2 &Lo() const { return lo; }
|
||||
inline int LoX() const { return lo.x_; }
|
||||
inline int LoX(int p_lo_x) { return lo.x_ = p_lo_x; }
|
||||
inline int LoY() const { return lo.y_; }
|
||||
inline int LoY(int p_lo_y) { return lo.y_ = p_lo_y; }
|
||||
inline const Vector2 &Hi() const { return hi; }
|
||||
inline int HiX() const { return hi.x_; }
|
||||
inline int HiX(int p_hi_x) { return hi.x_ = p_hi_x; }
|
||||
inline int HiY() const { return hi.y_; }
|
||||
inline int HiY(int p_hi_y) { return hi.y_ = p_hi_y; }
|
||||
inline const Vector2 &Size() const { return size; }
|
||||
inline int Width() const { return size.x_; }
|
||||
inline int Height() const { return size.y_; }
|
||||
inline int Area() const { return size.x_ * size.y_; }
|
||||
const Vector2 &Lo() const { return lo; }
|
||||
int LoX(int p_lo_x) { return lo.x_ = p_lo_x; }
|
||||
int LoY(int p_lo_y) { return lo.y_ = p_lo_y; }
|
||||
const Vector2 &Hi() const { return hi; }
|
||||
int HiX(int p_hi_x) { return hi.x_ = p_hi_x; }
|
||||
int HiY(int p_hi_y) { return hi.y_ = p_hi_y; }
|
||||
const Vector2 &Size() const { return size; }
|
||||
int Width() const { return size.x_; }
|
||||
int Height() const { return size.y_; }
|
||||
int Area() const { return size.x_ * size.y_; }
|
||||
|
||||
inline const Vector2 Centre() const {
|
||||
Vector2 Centre() const {
|
||||
int mid_x = int(std::round(lo.x_ + (size.x_ / 2.0)));
|
||||
int mid_y = int(std::round(lo.y_ + (size.y_ / 2.0)));
|
||||
return Vector2(mid_x, mid_y);
|
||||
|
|
|
@ -473,10 +473,10 @@ void Event::WriteDbFrames() {
|
|||
stats.alarm_blobs_,
|
||||
stats.min_blob_size_,
|
||||
stats.max_blob_size_,
|
||||
stats.alarm_box_.LoX(),
|
||||
stats.alarm_box_.LoY(),
|
||||
stats.alarm_box_.HiX(),
|
||||
stats.alarm_box_.HiY(),
|
||||
stats.alarm_box_.Lo().x_,
|
||||
stats.alarm_box_.Lo().y_,
|
||||
stats.alarm_box_.Hi().x_,
|
||||
stats.alarm_box_.Hi().y_,
|
||||
stats.score_);
|
||||
} // end foreach zone stats
|
||||
} // end if recording stats
|
||||
|
|
|
@ -1508,7 +1508,7 @@ bool Image::Crop( unsigned int lo_x, unsigned int lo_y, unsigned int hi_x, unsig
|
|||
}
|
||||
|
||||
bool Image::Crop(const Box &limits) {
|
||||
return Crop(limits.LoX(), limits.LoY(), limits.HiX(), limits.HiY());
|
||||
return Crop(limits.Lo().x_, limits.Lo().y_, limits.Hi().x_, limits.Hi().y_);
|
||||
}
|
||||
|
||||
/* Far from complete */
|
||||
|
|
|
@ -94,17 +94,11 @@ public:
|
|||
return coords[index];
|
||||
}
|
||||
|
||||
inline const Box &Extent() const { return extent; }
|
||||
inline int LoX() const { return extent.LoX(); }
|
||||
inline int LoX(int p_lo_x) { return extent.LoX(p_lo_x); }
|
||||
inline int HiX() const { return extent.HiX(); }
|
||||
inline int HiX(int p_hi_x) { return extent.HiX(p_hi_x); }
|
||||
inline int LoY() const { return extent.LoY(); }
|
||||
inline int LoY(int p_lo_y) { return extent.LoY(p_lo_y); }
|
||||
inline int HiY() const { return extent.HiY(); }
|
||||
inline int HiY(int p_hi_y) { return extent.HiY(p_hi_y); }
|
||||
inline int Width() const { return extent.Width(); }
|
||||
inline int Height() const { return extent.Height(); }
|
||||
const Box &Extent() const { return extent; }
|
||||
int LoX(int p_lo_x) { return extent.LoX(p_lo_x); }
|
||||
int HiX(int p_hi_x) { return extent.HiX(p_hi_x); }
|
||||
int LoY(int p_lo_y) { return extent.LoY(p_lo_y); }
|
||||
int HiY(int p_hi_y) { return extent.HiY(p_hi_y); }
|
||||
|
||||
inline int Area() const { return area; }
|
||||
inline const Vector2 &Centre() const {
|
||||
|
|
|
@ -204,10 +204,10 @@ Image *StreamBase::prepareImage(Image *image) {
|
|||
last_crop = Box();
|
||||
|
||||
// Recalculate crop parameters, as %ges
|
||||
int click_x = (last_crop.LoX() * 100 ) / last_act_image_width; // Initial crop offset from last image
|
||||
click_x += ( x * 100 ) / last_virt_image_width;
|
||||
int click_y = (last_crop.LoY() * 100 ) / last_act_image_height; // Initial crop offset from last image
|
||||
click_y += ( y * 100 ) / last_virt_image_height;
|
||||
int click_x = (last_crop.Lo().x_ * 100) / last_act_image_width; // Initial crop offset from last image
|
||||
click_x += (x * 100) / last_virt_image_width;
|
||||
int click_y = (last_crop.Lo().y_ * 100) / last_act_image_height; // Initial crop offset from last image
|
||||
click_y += (y * 100) / last_virt_image_height;
|
||||
Debug(3, "Got adjusted click at %d%%,%d%%", click_x, click_y);
|
||||
|
||||
// Convert the click locations to the current image pixels
|
||||
|
@ -234,7 +234,7 @@ Image *StreamBase::prepareImage(Image *image) {
|
|||
last_crop = Box({lo_x, lo_y}, {hi_x, hi_y});
|
||||
} // end if ( mag != last_mag || x != last_x || y != last_y )
|
||||
|
||||
Debug(3, "Cropping to %d,%d -> %d,%d", last_crop.LoX(), last_crop.LoY(), last_crop.HiX(), last_crop.HiY());
|
||||
Debug(3, "Cropping to %d,%d -> %d,%d", last_crop.Lo().x_, last_crop.Lo().y_, last_crop.Hi().x_, last_crop.Hi().y_);
|
||||
if ( !image_copied ) {
|
||||
static Image copy_image;
|
||||
copy_image.Assign(*image);
|
||||
|
|
|
@ -130,10 +130,10 @@ void Zone::RecordStats(const Event *event) {
|
|||
stats.alarm_blobs_,
|
||||
stats.min_blob_size_,
|
||||
stats.max_blob_size_,
|
||||
stats.alarm_box_.LoX(),
|
||||
stats.alarm_box_.LoY(),
|
||||
stats.alarm_box_.HiX(),
|
||||
stats.alarm_box_.HiY(),
|
||||
stats.alarm_box_.Lo().x_,
|
||||
stats.alarm_box_.Lo().y_,
|
||||
stats.alarm_box_.Hi().x_,
|
||||
stats.alarm_box_.Hi().y_,
|
||||
stats.score_
|
||||
);
|
||||
zmDbDo(sql);
|
||||
|
@ -219,10 +219,10 @@ bool Zone::CheckAlarms(const Image *delta_image) {
|
|||
int alarm_mid_x = -1;
|
||||
int alarm_mid_y = -1;
|
||||
|
||||
unsigned int lo_y = polygon.LoY();
|
||||
unsigned int lo_x = polygon.LoX();
|
||||
unsigned int hi_x = polygon.HiX();
|
||||
unsigned int hi_y = polygon.HiY();
|
||||
unsigned int lo_x = polygon.Extent().Lo().x_;
|
||||
unsigned int lo_y = polygon.Extent().Lo().y_;
|
||||
unsigned int hi_x = polygon.Extent().Hi().x_;
|
||||
unsigned int hi_y = polygon.Extent().Hi().y_;
|
||||
|
||||
Debug(4, "Checking alarms for zone %d/%s in lines %d -> %d", id, label.c_str(), lo_y, hi_y);
|
||||
|
||||
|
@ -630,10 +630,10 @@ bool Zone::CheckAlarms(const Image *delta_image) {
|
|||
stats.score_ = 1; /* Fix for score of 0 when frame meets thresholds but alarmed area is not big enough */
|
||||
Debug(5, "Current score is %d", stats.score_);
|
||||
|
||||
alarm_lo_x = polygon.HiX()+1;
|
||||
alarm_hi_x = polygon.LoX()-1;
|
||||
alarm_lo_y = polygon.HiY()+1;
|
||||
alarm_hi_y = polygon.LoY()-1;
|
||||
alarm_lo_x = polygon.Extent().Hi().x_ + 1;
|
||||
alarm_hi_x = polygon.Extent().Lo().x_ - 1;
|
||||
alarm_lo_y = polygon.Extent().Hi().y_ + 1;
|
||||
alarm_hi_y = polygon.Extent().Lo().y_ - 1;
|
||||
|
||||
for (uint32 i = 1; i < kWhite; i++) {
|
||||
BlobStats *bs = &blob_stats[i];
|
||||
|
@ -872,14 +872,29 @@ std::vector<Zone> Zone::Load(Monitor *monitor) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if ( polygon.LoX() < 0 || polygon.HiX() >= (int)monitor->Width()
|
||||
|| polygon.LoY() < 0 || polygon.HiY() >= (int)monitor->Height() ) {
|
||||
if (polygon.Extent().Lo().x_ < 0 || polygon.Extent().Hi().x_ >= (int) monitor->Width()
|
||||
|| polygon.Extent().Lo().y_ < 0 || polygon.Extent().Hi().y_ >= (int) monitor->Height()) {
|
||||
Error("Zone %d/%s for monitor %s extends outside of image dimensions, (%d,%d), (%d,%d), fixing",
|
||||
Id, Name, monitor->Name(), polygon.LoX(), polygon.LoY(), polygon.HiX(), polygon.HiY());
|
||||
if ( polygon.LoX() < 0 ) polygon.LoX(0);
|
||||
if ( polygon.HiX() >= (int)monitor->Width()) polygon.HiX((int)monitor->Width());
|
||||
if ( polygon.LoY() < 0 ) polygon.LoY(0);
|
||||
if ( polygon.HiY() >= (int)monitor->Height() ) polygon.HiY((int)monitor->Height());
|
||||
Id,
|
||||
Name,
|
||||
monitor->Name(),
|
||||
polygon.Extent().Lo().x_,
|
||||
polygon.Extent().Lo().y_,
|
||||
polygon.Extent().Hi().x_,
|
||||
polygon.Extent().Hi().y_);
|
||||
|
||||
if (polygon.Extent().Lo().x_ < 0) {
|
||||
polygon.LoX(0);
|
||||
}
|
||||
if (polygon.Extent().Hi().x_ >= (int) monitor->Width()) {
|
||||
polygon.HiX((int) monitor->Width());
|
||||
}
|
||||
if (polygon.Extent().Lo().y_ < 0) {
|
||||
polygon.LoY(0);
|
||||
}
|
||||
if (polygon.Extent().Hi().y_ >= (int) monitor->Height()) {
|
||||
polygon.HiY((int) monitor->Height());
|
||||
}
|
||||
}
|
||||
|
||||
if ( false && !strcmp( Units, "Percent" ) ) {
|
||||
|
@ -960,8 +975,8 @@ void Zone::std_alarmedpixels(
|
|||
if ( max_pixel_threshold )
|
||||
calc_max_pixel_threshold = max_pixel_threshold;
|
||||
|
||||
lo_y = polygon.LoY();
|
||||
hi_y = polygon.HiY();
|
||||
lo_y = polygon.Extent().Lo().y_;
|
||||
hi_y = polygon.Extent().Hi().y_;
|
||||
for ( unsigned int y = lo_y; y <= hi_y; y++ ) {
|
||||
unsigned int lo_x = ranges[y].lo_x;
|
||||
unsigned int hi_x = ranges[y].hi_x;
|
||||
|
|
|
@ -62,10 +62,10 @@ class ZoneStats {
|
|||
alarm_blobs_,
|
||||
min_blob_size_,
|
||||
max_blob_size_,
|
||||
alarm_box_.LoX(),
|
||||
alarm_box_.LoY(),
|
||||
alarm_box_.HiX(),
|
||||
alarm_box_.HiY(),
|
||||
alarm_box_.Lo().x_,
|
||||
alarm_box_.Lo().y_,
|
||||
alarm_box_.Hi().x_,
|
||||
alarm_box_.Hi().y_,
|
||||
alarm_centre_.x_,
|
||||
alarm_centre_.y_,
|
||||
score_
|
||||
|
|
Loading…
Reference in New Issue