From dbf5f6ab78654b2a16ab9c0472c9f21f0c467aac Mon Sep 17 00:00:00 2001 From: Cowwan Date: Thu, 8 Feb 2024 22:49:58 -0500 Subject: [PATCH] fixed an issue that caused the face tracker to crash if I left the frame added a second filter on face detection that requires the faces to be a certain size --- eyes.py | 17 ++++++++++++----- facedetection.py | 5 ++--- tracker.py | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/eyes.py b/eyes.py index 8db04fe..71d25e2 100644 --- a/eyes.py +++ b/eyes.py @@ -2,14 +2,18 @@ import numpy as np import math import cv2 -def clamp_to_im(pt, w, h): #8 times per frame, but that only accounts for 0.005ms - x=max(pt[0],0) - y=max(pt[1],0) +def clamp_to_im(pt, w, h): + x = pt[0] + y = pt[1] + if x < 0: + x = 0 + if y < 0: + y = 0 if x >= w: x = w-1 if y >= h: y = h-1 - return (int(x),int(y+1)) + return (int(x), int(y+1)) def rotate(origin, point, a): #runs 22 times per frame x, y = point - origin @@ -54,15 +58,18 @@ class Eye(): #so I just don't if it's a relatively small angle if math.degrees(a) > 7.5 and math.degrees(a) < 352.5: im = rotate_image(im, a, self.outerPoint) - im = im[int(y1):int(y2), int(x1):int(x2)] + + if np.prod(im.shape) < 1: self.image = None self.info = None + return if self.index == 1: im = cv2.flip(im, 1) scale = [(x2 - x1)/ 32., (y2 - y1)/ 32.] + im = cv2.resize(im, (32, 32), interpolation=cv2.INTER_CUBIC) im = im.astype(np.float32) * self.std + self.mean im = np.expand_dims(im, 0) diff --git a/facedetection.py b/facedetection.py index 7663fba..f3349a1 100644 --- a/facedetection.py +++ b/facedetection.py @@ -9,9 +9,8 @@ def detect_faces(frame, model, detection_threshold ): outputs = outputs[0] maxpool = maxpool[0] mask = outputs[0] == maxpool[0] - mask2 = outputs[1] > 0.2 - mask = mask.astype(int) * mask2.astype(int) - outputs[0] = outputs[0] * mask.astype(int) + mask2 = outputs[1] > 0.15 + outputs[0] = outputs[0] * mask.astype(int) * mask2.astype(int) faceLocation = np.argmax(outputs[0].flatten()) x = faceLocation % 56 y = faceLocation // 56 diff --git a/tracker.py b/tracker.py index 9b1bf77..b4de59d 100644 --- a/tracker.py +++ b/tracker.py @@ -48,7 +48,7 @@ class Models(): self.gazeTracker = onnxruntime.InferenceSession(os.path.join(model_base_path, "mnv3_gaze32_split_opt.onnx"), sess_options=options, providers=providersList) class Tracker(): - def __init__(self, width, height, featureType, threads, model_type=3, detection_threshold=0.5, threshold=0.6, silent=False): + def __init__(self, width, height, featureType, threads, model_type=3, detection_threshold=0.6, threshold=0.6, silent=False): self.detection_threshold = detection_threshold self.EyeTracker = eyes.EyeTracker()