summaryrefslogtreecommitdiff
path: root/megapixels/app/processors/face_detector.py
diff options
context:
space:
mode:
Diffstat (limited to 'megapixels/app/processors/face_detector.py')
-rw-r--r--megapixels/app/processors/face_detector.py27
1 files changed, 9 insertions, 18 deletions
diff --git a/megapixels/app/processors/face_detector.py b/megapixels/app/processors/face_detector.py
index a805a474..6bf27576 100644
--- a/megapixels/app/processors/face_detector.py
+++ b/megapixels/app/processors/face_detector.py
@@ -65,8 +65,6 @@ class DetectorHaar:
class DetectorDLIBCNN:
-
- dnn_size = (300, 300)
pyramids = 0
conf_thresh = 0.85
@@ -79,13 +77,10 @@ class DetectorDLIBCNN:
self.detector = dlib.cnn_face_detection_model_v1(cfg.DIR_MODELS_DLIB_CNN)
os.environ['CUDA_VISIBLE_DEVICES'] = cuda_visible_devices # reset
- def detect(self, im, size=None, conf_thresh=None, pyramids=None, largest=False, zone=None):
+ def detect(self, im, conf_thresh=None, pyramids=None, largest=False, zone=None):
bboxes = []
conf_thresh = self.conf_thresh if conf_thresh is None else conf_thresh
pyramids = self.pyramids if pyramids is None else pyramids
- dnn_size = self.dnn_size if size is None else size
- # resize image
- im = im_utils.resize(im, width=dnn_size[0], height=dnn_size[1])
dim = im.shape[:2][::-1]
im = im_utils.bgr2rgb(im) # convert to RGB for dlib
# run detector
@@ -110,7 +105,6 @@ class DetectorDLIBCNN:
class DetectorDLIBHOG:
- size = (320, 240)
pyramids = 0
conf_thresh = 0.85
@@ -119,12 +113,9 @@ class DetectorDLIBHOG:
self.log = logger_utils.Logger.getLogger()
self.detector = dlib.get_frontal_face_detector()
- def detect(self, im, size=None, conf_thresh=None, pyramids=0, largest=False, zone=False):
+ def detect(self, im, conf_thresh=None, pyramids=0, largest=False, zone=False):
conf_thresh = self.conf_thresh if conf_thresh is None else conf_thresh
- dnn_size = self.size if size is None else size
pyramids = self.pyramids if pyramids is None else pyramids
-
- im = im_utils.resize(im, width=dnn_size[0], height=dnn_size[1])
dim = im.shape[:2][::-1]
im = im_utils.bgr2rgb(im) # ?
hog_results = self.detector.run(im, pyramids)
@@ -153,23 +144,23 @@ class DetectorCVDNN:
dnn_scale = 1.0 # fixed
dnn_mean = (104.0, 177.0, 123.0) # fixed
dnn_crop = False # crop or force resize
- size = (300, 300)
- conf_thresh = 0.85
+ blob_size = (300, 300)
+ conf_thresh = 0.95
def __init__(self):
- import dlib
+ self.log = logger_utils.Logger.getLogger()
fp_prototxt = join(cfg.DIR_MODELS_CAFFE, 'face_detect', 'opencv_face_detector.prototxt')
fp_model = join(cfg.DIR_MODELS_CAFFE, 'face_detect', 'opencv_face_detector.caffemodel')
self.net = cv.dnn.readNet(fp_prototxt, fp_model)
self.net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)
self.net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
- def detect(self, im, size=None, conf_thresh=None, largest=False, pyramids=None, zone=False):
+ def detect(self, im, conf_thresh=None, largest=False, pyramids=None, zone=False):
"""Detects faces and returns (list) of (BBox)"""
conf_thresh = self.conf_thresh if conf_thresh is None else conf_thresh
- dnn_size = self.size if size is None else size
- im = cv.resize(im, dnn_size)
- blob = cv.dnn.blobFromImage(im, self.dnn_scale, dnn_size, self.dnn_mean)
+ im = cv.resize(im, self.blob_size)
+ dim = im.shape[:2][::-1]
+ blob = cv.dnn.blobFromImage(im, self.dnn_scale, dim, self.dnn_mean)
self.net.setInput(blob)
net_outputs = self.net.forward()