From d925f345f1f27ad4f476909f638491a26b9dd061 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Fri, 12 Apr 2024 18:17:45 -0700 Subject: [PATCH] Added average frame rate output --- examples/Python/src/YOLOv5/Video.lf | 6 ++++++ examples/Python/src/YOLOv5/YOLOv5_Webcam_Timer.lf | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/Python/src/YOLOv5/Video.lf b/examples/Python/src/YOLOv5/Video.lf index 3b9e145f..0fbc0e5a 100644 --- a/examples/Python/src/YOLOv5/Video.lf +++ b/examples/Python/src/YOLOv5/Video.lf @@ -46,12 +46,18 @@ reactor WebCam(webcam_id=0, offset = 0 s, period = 100 ms) { /** Display video frames. */ reactor Display { input frame + state frame_count = 0 reaction(startup) {= print("\n******* Press 'q' in the video window to exit *******\n") =} reaction(frame) {= + self.frame_count += 1 + # Every hundred or so frames, report the frame rate. + if (self.frame_count % 100 == 0): + print(f"** Average frame rate: {self.frame_count * SEC(1) / lf.time.physical_elapsed()} f/s") + cv2.imshow("frame", frame.value) # press 'Q' if you want to exit if cv2.waitKey(1) & 0xFF == ord('q'): diff --git a/examples/Python/src/YOLOv5/YOLOv5_Webcam_Timer.lf b/examples/Python/src/YOLOv5/YOLOv5_Webcam_Timer.lf index f4aa255c..bda05c3a 100644 --- a/examples/Python/src/YOLOv5/YOLOv5_Webcam_Timer.lf +++ b/examples/Python/src/YOLOv5/YOLOv5_Webcam_Timer.lf @@ -15,7 +15,7 @@ import WebCam, Display from "Video.lf" main reactor { # Offset prevents deadline violations during startup. - webcam = new WebCam(webcam_id=0, offset = 2 s) + webcam = new WebCam(webcam_id=0, offset = 3 s) dnn = new DNN() plotter = new Plotter(label_deadline = 100 msec) display = new Display()