From cb4d6d6f5be213edbc4f3b1e4452e5b7ce5e9378 Mon Sep 17 00:00:00 2001 From: adamhrv Date: Thu, 17 Jan 2019 11:26:41 +0100 Subject: updates for batch processing --- megapixels/app/processors/face_detector.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'megapixels/app/processors') 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)) -- cgit v1.2.3-70-g09d2