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
This commit is contained in:
parent
8dd4c163b8
commit
dbf5f6ab78
3 changed files with 15 additions and 9 deletions
17
eyes.py
17
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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue