With this, the face tracker will actually track at the specified FPS, saving CPU especially at lower tracking frame rates.

This commit is contained in:
Emiliana 2020-03-03 18:48:52 +01:00
parent 0c84f50672
commit 94d2f4fbe0

View file

@ -94,6 +94,10 @@ if args.log_data != "":
log.flush() log.flush()
try: try:
frame_time = time.perf_counter()
target_duration = 0
if fps > 0:
target_duration = 1. / float(fps)
while input_reader.is_open(): while input_reader.is_open():
if not input_reader.is_ready(): if not input_reader.is_ready():
time.sleep(0.001) time.sleep(0.001)
@ -232,6 +236,12 @@ try:
cv2.imshow('OpenSeeFace Visualization', frame) cv2.imshow('OpenSeeFace Visualization', frame)
if cv2.waitKey(1) & 0xFF == ord('q'): if cv2.waitKey(1) & 0xFF == ord('q'):
break 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: except KeyboardInterrupt:
if args.silent == 0: if args.silent == 0:
print("Quitting") print("Quitting")