From 0d61b061a363f727fd68e2a8dbe1523a0487abbb Mon Sep 17 00:00:00 2001 From: Emiliana <38952746+emilianavt@users.noreply.github.com> Date: Wed, 2 Sep 2020 18:42:25 +0200 Subject: [PATCH] Added a separate detection threshold parameter. --- facetracker.py | 5 +++-- tracker.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/facetracker.py b/facetracker.py index f8433fb..668befc 100644 --- a/facetracker.py +++ b/facetracker.py @@ -18,7 +18,8 @@ else: parser.add_argument("-H", "--height", type=int, help="Set raw RGB height", default=360) parser.add_argument("-c", "--capture", help="Set camera ID (0, 1...) or video file", default="0") parser.add_argument("-m", "--max-threads", type=int, help="Set the maximum number of threads", default=1) -parser.add_argument("-t", "--threshold", type=float, help="Set minimum confidence threshold for face detection", default=None) +parser.add_argument("-t", "--threshold", type=float, help="Set minimum confidence threshold for face tracking", default=None) +parser.add_argument("-d", "--detection-threshold", type=float, help="Set minimum confidence threshold for face detection", default=0.6) parser.add_argument("-v", "--visualize", type=int, help="Set this to 1 to visualize the tracking, to 2 to also show face ids, to 3 to add confidence values or to 4 to add numbers to the point display", default=0) parser.add_argument("-P", "--pnp-points", type=int, help="Set this to 1 to add the 3D fitting points to the visualization", default=0) parser.add_argument("-s", "--silent", type=int, help="Set this to 1 to prevent text output on the console", default=0) @@ -180,7 +181,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 else True, 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 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) if not args.video_out is None: out = cv2.VideoWriter(args.video_out, cv2.VideoWriter_fourcc('F','F','V','1'), 24, (width,height)) diff --git a/tracker.py b/tracker.py index f29b042..4c140a4 100644 --- a/tracker.py +++ b/tracker.py @@ -485,7 +485,7 @@ class FaceInfo(): self.eye_blink.append(1 - min(max(0, -self.current_features["eye_l"]), 1)) class Tracker(): - def __init__(self, width, height, model_type=3, 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): options = onnxruntime.SessionOptions() options.inter_op_num_threads = 1 options.intra_op_num_threads = max(max_threads,4) @@ -647,6 +647,7 @@ class Tracker(): self.width = width self.height = height self.threshold = threshold + self.detection_threshold = detection_threshold self.max_faces = max_faces self.max_threads = max_threads self.discard = 0 @@ -700,7 +701,7 @@ class Tracker(): x *= 4 y *= 4 r *= 1.0 - if c < self.threshold: + if c < self.detection_threshold: break results.append((x - r, y - r, 2 * r, 2 * r * 1.0)) results = np.array(results).astype(np.float32)