From 83e400a1d11088f2d423b131e62af752aada56d6 Mon Sep 17 00:00:00 2001 From: Emiliana <38952746+emilianavt@users.noreply.github.com> Date: Sat, 8 Feb 2020 00:13:28 +0100 Subject: [PATCH] Face ids can now be displayed. --- facetracker.py | 4 +++- tracker.py | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/facetracker.py b/facetracker.py index e221229..1be3bf0 100644 --- a/facetracker.py +++ b/facetracker.py @@ -16,7 +16,7 @@ else: 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=0.4) -parser.add_argument("-v", "--visualize", type=int, help="Set this to 1 to visualize the tracking or to 2 to add numbers to the point display", default=0) +parser.add_argument("-v", "--visualize", type=int, help="Set this to 1 to visualize the tracking, to 2 to also show face ids or to 3 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) parser.add_argument("--faces", type=int, help="Set the maximum number of faces (slow)", default=1) @@ -156,6 +156,8 @@ try: continue if args.visualize != 0 or not out is None: if args.visualize > 1: + frame = cv2.putText(frame, str(f.id), (int(f.bbox[0]), int(f.bbox[1])), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (255,0,255)) + if args.visualize > 2: frame = cv2.putText(frame, str(pt_num), (int(y), int(x)), cv2.FONT_HERSHEY_SIMPLEX, 0.25, (255,255,0)) if not (x < 0 or y < 0 or x >= height or y >= width): frame[int(x), int(y)] = (0, 0, 255) diff --git a/tracker.py b/tracker.py index 0923fb8..3273d75 100644 --- a/tracker.py +++ b/tracker.py @@ -309,7 +309,7 @@ class Tracker(): image_pts = np.empty((21 if self.high_quality_3d else 18, 2), np.float32) image_pts[0:17] = np.array(lms)[0:17,0:2] - if (self.high_quality_3d): + if self.high_quality_3d: image_pts[17:21] = np.array(lms)[27:31,0:2] else: image_pts[17] = np.array(lms)[30,0:2] @@ -391,6 +391,8 @@ class Tracker(): x2 = x1 + dist y2 = y1 + dist im = np.float32(frame[int(y1):int(y2), int(x1):int(x2),::-1]) + if np.prod(im.shape) < 1: + return None, None, None, None im = cv2.resize(im, (32, 32), interpolation=cv2.INTER_LINEAR) / self.std - self.mean im = np.expand_dims(im, 0) im = np.transpose(im, (0,3,1,2)) @@ -405,6 +407,8 @@ class Tracker(): scale = [0,0] (right_eye, e_x[0], e_y[0], scale[0]) = self.prepare_eye(frame, lms[36:42,0:2]) (left_eye, e_x[1], e_y[1], scale[1]) = self.prepare_eye(frame, lms[42:48,0:2]) + if right_eye is None or left_eye is None: + return [(1.0, 0.0, 0.0, 0.0), (1.0, 0.0, 0.0, 0.0)] both_eyes = np.concatenate((right_eye, left_eye)) results = np.array(self.gaze_model.run([], {self.input_name: both_eyes})[0]) open = [0, 0]