diff options
| author | adamhrv <adam@ahprojects.com> | 2019-01-06 17:16:18 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2019-01-06 17:16:18 +0100 |
| commit | 4bcb82c0f295d79d3d247252e7e98b2d986ae821 (patch) | |
| tree | a51105698c46ecfcb0a09c5ba294f9d9ffa43e7a /megapixels/app/models/bbox.py | |
| parent | 2efde746810a0264ad2cf09dc9b003bfcd17a4d5 (diff) | |
externalize drawing, cleanup
Diffstat (limited to 'megapixels/app/models/bbox.py')
| -rw-r--r-- | megapixels/app/models/bbox.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/megapixels/app/models/bbox.py b/megapixels/app/models/bbox.py index 55a92512..04ee4a70 100644 --- a/megapixels/app/models/bbox.py +++ b/megapixels/app/models/bbox.py @@ -29,6 +29,7 @@ class BBox: def __init__(self, x1, y1, x2, y2): """Represents a bounding box and provides methods for accessing and modifying + All values are normalized unless otherwise specified :param x1: normalized left coord :param y1: normalized top coord :param x2: normalized right coord @@ -40,8 +41,8 @@ class BBox: self._y2 = y2 self._width = x2 - x1 self._height = y2 - y1 - self._cx = x1 + (self._width // 2) - self._cy = y1 + (self._height // 2) + self._cx = x1 + (self._width / 2) + self._cy = y1 + (self._height / 2) self._tl = (x1, y1) self._br = (x2, y2) self._rect = (self._x1, self._y1, self._x2, self._y2) @@ -111,7 +112,14 @@ class BBox: # # ----------------------------------------------------------------- # # Utils - # def constrain(self, dim): + def contains(self, pt_norm): + '''Returns Checks if this BBox contains the normalized point + :param pt: (int|float, int|float) x, y + :returns (bool) + ''' + x, y = pt_norm + return (x > self._x1 and x < self._x2 and y > self._y1 and y < self._y2) + def distance(self, b): a = self dcx = self._cx - b.cx @@ -168,6 +176,12 @@ class BBox: # ----------------------------------------------------------------- # Convert to + def to_square(self, bounds): + '''Forces bbox to square dimensions + :param bounds: (int, int) w, h of the image + :returns (BBox) in square ratio + ''' + def to_dim(self, dim): """scale is (w, h) is tuple of dimensions""" w, h = dim |
