diff options
| author | adamhrv <adam@ahprojects.com> | 2019-01-16 13:30:16 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2019-01-16 13:30:16 +0100 |
| commit | 65cb506ca182272e2701136097fd00c55dc6bd69 (patch) | |
| tree | cc5be8e61a8d5173745be1d331b210e967e146b5 /megapixels/app/models/bbox.py | |
| parent | fceeb3b7adbc8d522e9fe1c40e12e9a529199068 (diff) | |
change bbox to norm, refine face extractor
Diffstat (limited to 'megapixels/app/models/bbox.py')
| -rw-r--r-- | megapixels/app/models/bbox.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/megapixels/app/models/bbox.py b/megapixels/app/models/bbox.py index f1216698..f65f7373 100644 --- a/megapixels/app/models/bbox.py +++ b/megapixels/app/models/bbox.py @@ -1,4 +1,5 @@ import math +import random from dlib import rectangle as dlib_rectangle import numpy as np @@ -127,9 +128,23 @@ class BBox: d = int(math.sqrt(math.pow(dcx, 2) + math.pow(dcy, 2))) return d + # ----------------------------------------------------------------- # Modify + def jitter(self, amt): + '''Jitters BBox in x,y,w,h values. Used for face feature extraction + :param amt: (float) percentage of BBox for maximum translation + :returns (BBox) + ''' + w = self._width + (self._width * random.uniform(-amt, amt)) + h = self._height + (self._height * random.uniform(-amt, amt)) + cx = self._cx + (self._cx * random.uniform(-amt, amt)) + cy = self._cy + (self._cy * random.uniform(-amt, amt)) + x1, y1 = np.clip((cx - w/2, cy - h/2), 0.0, 1.0) + x2, y2 = np.clip((cx + w/2, cy + h/2), 0.0, 1.0) + return BBox(x1, y1, x2, y2) + def expand(self, per): """Expands BBox by percentage :param per: (float) percentage to expand 0.0 - 1.0 @@ -186,7 +201,7 @@ class BBox: # print(adj) r = np.add(np.array(r), adj) - return BBox(*r) + return BBox(*r) # updats all BBox values # ----------------------------------------------------------------- |
