summaryrefslogtreecommitdiff
path: root/megapixels/app/processors/face_detector.py
diff options
context:
space:
mode:
authoradamhrv <adam@ahprojects.com>2019-01-17 11:26:41 +0100
committeradamhrv <adam@ahprojects.com>2019-01-17 11:26:41 +0100
commitcb4d6d6f5be213edbc4f3b1e4452e5b7ce5e9378 (patch)
treea6a66d408e68c9a1401cc729a72952ea8f200762 /megapixels/app/processors/face_detector.py
parenta672dfdfdbac7cdac43e22c5d0bf29550770e2ad (diff)
updates for batch processing
Diffstat (limited to 'megapixels/app/processors/face_detector.py')
-rw-r--r--megapixels/app/processors/face_detector.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/megapixels/app/processors/face_detector.py b/megapixels/app/processors/face_detector.py
index fbf91071..7b5310c5 100644
--- a/megapixels/app/processors/face_detector.py
+++ b/megapixels/app/processors/face_detector.py
@@ -69,6 +69,7 @@ class DetectorMTCNN_TF:
# pip install mtcnn
dnn_size = (300, 300)
+ conf_thresh = 0.9
def __init__(self, size=(400,400), gpu=0):
self.log = logger_utils.Logger.getLogger()
@@ -84,17 +85,33 @@ class DetectorMTCNN_TF:
:param im: (numpy.ndarray) image
:returns list of BBox
'''
+
bboxes = []
dnn_size = self.dnn_size if size is None else size
+ conf_thresh = self.conf_thresh if conf_thresh is None else conf_thresh
im = im_utils.resize(im, width=dnn_size[0], height=dnn_size[1])
dim = im.shape[:2][::-1]
dets = self.detector.detect_faces(im)
+ '''
+ {
+ 'box': [4, 140, 14, 18],
+ 'confidence': 0.9588413834571838,
+ 'keypoints': {
+ 'left_eye': (8, 147),
+ 'right_eye': (14, 146),
+ 'nose': (12, 151),
+ 'mouth_left': (9, 155),
+ 'mouth_right': (14, 154)
+ }
+ }
+ '''
for det in dets:
rect = det['box']
- #keypoints = det['keypoints'] # not using here. see 'face_landmarks.py'
- bbox = BBox.from_xywh_dim(*rect, dim)
- bboxes.append(bbox)
+ conf = det['confidence']
+ if conf > conf_thresh:
+ bbox = BBox.from_xywh_dim(*rect, dim)
+ bboxes.append(bbox)
if largest and len(bboxes) > 1:
# only keep largest
@@ -222,8 +239,11 @@ class DetectorCVDNN:
bboxes = []
for i in range(0, net_outputs.shape[2]):
- conf = net_outputs[0, 0, i, 2]
- if conf > conf_thresh:
+ conf = float(net_outputs[0, 0, i, 2])
+ # BUG: this face detector creates ghost face detections in stage-left from nose-bottom neck
+ # temp fix is to elminate ROI extending outside of frame
+ bounds = np.array(net_outputs[0, 0, i, 3:7])
+ if conf > conf_thresh and np.all(bounds < 1):
rect_norm = net_outputs[0, 0, i, 3:7]
bboxes.append(BBox(*rect_norm))