From 94d2f4fbe08bfccfe640ec9bf0d9bc754b5df83a Mon Sep 17 00:00:00 2001 From: Emiliana <38952746+emilianavt@users.noreply.github.com> Date: Tue, 3 Mar 2020 18:48:52 +0100 Subject: [PATCH] With this, the face tracker will actually track at the specified FPS, saving CPU especially at lower tracking frame rates. --- facetracker.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/facetracker.py b/facetracker.py index 9bde89e..a11a739 100644 --- a/facetracker.py +++ b/facetracker.py @@ -94,6 +94,10 @@ if args.log_data != "": log.flush() try: + frame_time = time.perf_counter() + target_duration = 0 + if fps > 0: + target_duration = 1. / float(fps) while input_reader.is_open(): if not input_reader.is_ready(): time.sleep(0.001) @@ -232,6 +236,12 @@ try: cv2.imshow('OpenSeeFace Visualization', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break + + duration = time.perf_counter() - frame_time + while duration < target_duration: + time.sleep(target_duration - duration) + duration = time.perf_counter() - frame_time + frame_time = time.perf_counter() except KeyboardInterrupt: if args.silent == 0: print("Quitting")