From 4e3ee5795d03e69a9fe428ae0e52bb126e7c6f4b Mon Sep 17 00:00:00 2001 From: Emiliana <38952746+emilianavt@users.noreply.github.com> Date: Tue, 6 Oct 2020 23:44:23 +0200 Subject: [PATCH] Added a new `--try-hard` flag. --- Examples/OpenSeeWebcamInfo.cs | 8 ++++---- facetracker.py | 3 ++- tracker.py | 9 ++++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Examples/OpenSeeWebcamInfo.cs b/Examples/OpenSeeWebcamInfo.cs index 1a309dd..749e6e1 100644 --- a/Examples/OpenSeeWebcamInfo.cs +++ b/Examples/OpenSeeWebcamInfo.cs @@ -63,14 +63,14 @@ public class OpenSeeWebcam { private List> splitCaps = null; private int CompareCaps(OpenSeeWebcamCapability a, OpenSeeWebcamCapability b) { - if (a.minCX * a.minCY > b.minCX * b.minCY) - return -1; - if (a.minCX * a.minCY < b.minCX * b.minCY) - return 1; if (a.rating < b.rating) return -1; if (a.rating > b.rating) return 1; + if (a.minCX * a.minCY > b.minCX * b.minCY) + return -1; + if (a.minCX * a.minCY < b.minCX * b.minCY) + return 1; if (a.minInterval < b.minInterval) return -1; if (a.minInterval > b.minInterval) diff --git a/facetracker.py b/facetracker.py index 98ef5f0..ed2b383 100644 --- a/facetracker.py +++ b/facetracker.py @@ -32,6 +32,7 @@ parser.add_argument("--scan-every", type=int, help="Set after how many frames a parser.add_argument("--discard-after", type=int, help="Set the how long the tracker should keep looking for lost faces", default=10) parser.add_argument("--max-feature-updates", type=int, help="This is the number of seconds after which feature min/max/medium values will no longer be updated once a face has been detected.", default=900) parser.add_argument("--no-3d-adapt", type=int, help="When set to 1, the 3D face model will not be adapted to increase the fit", default=1) +parser.add_argument("--try-hard", type=int, help="When set to 1, the tracker will try harder to find a face", default=0) parser.add_argument("--video-out", help="Set this to the filename of an AVI file to save the tracking visualization as a video", default=None) parser.add_argument("--video-scale", type=int, help="This is a resolution scale factor applied to the saved AVI file", default=1, choices=[1,2,3,4]) parser.add_argument("--video-fps", type=float, help="This sets the frame rate of the output AVI file", default=24) @@ -244,7 +245,7 @@ try: first = False height, width, channels = frame.shape sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - tracker = Tracker(width, height, threshold=args.threshold, max_threads=args.max_threads, max_faces=args.faces, discard_after=args.discard_after, scan_every=args.scan_every, silent=False if args.silent == 0 else True, model_type=args.model, model_dir=args.model_dir, no_gaze=False if args.gaze_tracking != 0 and args.model >= 0 else True, detection_threshold=args.detection_threshold, use_retinaface=args.scan_retinaface, max_feature_updates=args.max_feature_updates, static_model=True if args.no_3d_adapt == 1 else False) + tracker = Tracker(width, height, threshold=args.threshold, max_threads=args.max_threads, max_faces=args.faces, discard_after=args.discard_after, scan_every=args.scan_every, silent=False if args.silent == 0 else True, model_type=args.model, model_dir=args.model_dir, no_gaze=False if args.gaze_tracking != 0 and args.model >= 0 else True, detection_threshold=args.detection_threshold, use_retinaface=args.scan_retinaface, max_feature_updates=args.max_feature_updates, static_model=True if args.no_3d_adapt == 1 else False, try_hard=args.try_hard == 1) if not args.video_out is None: out = cv2.VideoWriter(args.video_out, cv2.VideoWriter_fourcc('F','F','V','1'), args.video_fps, (width * args.video_scale, height * args.video_scale)) diff --git a/tracker.py b/tracker.py index a0ef7a6..57bc705 100644 --- a/tracker.py +++ b/tracker.py @@ -494,7 +494,7 @@ def get_model_base_path(model_dir): return model_base_path class Tracker(): - def __init__(self, width, height, model_type=3, detection_threshold=0.6, threshold=None, max_faces=1, discard_after=5, scan_every=3, bbox_growth=0.0, max_threads=4, silent=False, model_dir=None, no_gaze=False, use_retinaface=False, max_feature_updates=0, static_model=False, feature_level=2): + def __init__(self, width, height, model_type=3, detection_threshold=0.6, threshold=None, max_faces=1, discard_after=5, scan_every=3, bbox_growth=0.0, max_threads=4, silent=False, model_dir=None, no_gaze=False, use_retinaface=False, max_feature_updates=0, static_model=False, feature_level=2, try_hard=False): options = onnxruntime.SessionOptions() options.inter_op_num_threads = 1 options.intra_op_num_threads = max(max_threads,4) @@ -661,6 +661,7 @@ class Tracker(): self.scan_every = scan_every self.bbox_growth = bbox_growth self.silent = silent + self.try_hard = try_hard self.res = 224. self.mean_res = self.mean_224 @@ -1014,11 +1015,13 @@ class Tracker(): self.wait_count += 1 if self.detected == 0: start_fd = time.perf_counter() - if self.use_retinaface > 0: + if self.use_retinaface > 0 or self.try_hard: retinaface_detections = self.retinaface.detect_retina(frame) new_faces.extend(retinaface_detections) - else: + if self.use_retinaface == 0 or self.try_hard: new_faces.extend(self.detect_faces(frame)) + if self.try_hard: + new_faces.extend([(0, 0, self.width, self.height)]) duration_fd = 1000 * (time.perf_counter() - start_fd) self.wait_count = 0 elif self.detected < self.max_faces: