Fixed bug with --gaze-tracking 0 and added explicit gc calls at end of frame.

This commit is contained in:
Emiliana 2020-08-21 22:47:02 +02:00
parent db43cf8096
commit 87236c0549
3 changed files with 22 additions and 6 deletions

View file

@ -3,6 +3,7 @@ import os
import sys
import argparse
import traceback
import gc
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-i", "--ip", help="Set IP address for sending tracking data", default="127.0.0.1")
@ -234,9 +235,9 @@ try:
packet.extend(bytearray(struct.pack("f", x)))
if not log is None:
log.write(f",{y},{x},{c}")
if pt_num == 66 and f.eye_blink[0] < 0.30:
if pt_num == 66 and (f.eye_blink[0] < 0.30 or c < 0.30):
continue
if pt_num == 67 and f.eye_blink[1] < 0.30:
if pt_num == 67 and (f.eye_blink[1] < 0.30 or c < 0.30):
continue
x = int(x + 0.5)
y = int(y + 0.5)
@ -360,9 +361,18 @@ try:
if failures > 30:
break
collected = False
del frame
duration = time.perf_counter() - frame_time
while duration < target_duration:
time.sleep(target_duration - duration)
if not collected:
gc.collect()
collected = True
duration = time.perf_counter() - frame_time
sleep_time = target_duration - duration
if sleep_time > 0:
time.sleep(sleep_time)
duration = time.perf_counter() - frame_time
frame_time = time.perf_counter()
except KeyboardInterrupt:

View file

@ -7,6 +7,7 @@ import escapi
import dshowcapture
import time
import traceback
import gc
class VideoReader():
def __init__(self, capture, camera=False):
@ -69,7 +70,12 @@ class DShowCaptureReader(VideoReader):
def is_ready(self):
return self.device.capturing()
def read(self):
img = self.device.get_frame(self.timeout)
img = None
try:
img = self.device.get_frame(self.timeout)
except:
gc.collect()
img = self.device.get_frame(self.timeout)
if img is None:
return False, None
else:

View file

@ -1086,8 +1086,8 @@ class Tracker():
face_info.success, face_info.quaternion, face_info.euler, face_info.pnp_error, face_info.pts_3d, face_info.lms = self.estimate_depth(face_info)
face_info.adjust_3d()
lms = face_info.lms[:, 0:2]
x1, y1 = tuple(lms.min(0))
x2, y2 = tuple(lms.max(0))
x1, y1 = tuple(lms[0:66].min(0))
x2, y2 = tuple(lms[0:66].max(0))
bbox = (y1, x1, y2 - y1, x2 - x1)
face_info.bbox = bbox
detected.append(bbox)