From 87236c0549b01aa519d9bc0d74abc3b533ca8766 Mon Sep 17 00:00:00 2001 From: Emiliana <38952746+emilianavt@users.noreply.github.com> Date: Fri, 21 Aug 2020 22:47:02 +0200 Subject: [PATCH] Fixed bug with `--gaze-tracking 0` and added explicit gc calls at end of frame. --- facetracker.py | 16 +++++++++++++--- input_reader.py | 8 +++++++- tracker.py | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/facetracker.py b/facetracker.py index 9456bb7..5e4fe25 100644 --- a/facetracker.py +++ b/facetracker.py @@ -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: diff --git a/input_reader.py b/input_reader.py index 511be3c..8eb3542 100644 --- a/input_reader.py +++ b/input_reader.py @@ -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: diff --git a/tracker.py b/tracker.py index bb57236..a025391 100644 --- a/tracker.py +++ b/tracker.py @@ -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)