Skip to content

Commit

Permalink
Added average frame rate output
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardalee authored and lhstrh committed May 1, 2024
1 parent f71224c commit d925f34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions examples/Python/src/YOLOv5/Video.lf
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
2 changes: 1 addition & 1 deletion examples/Python/src/YOLOv5/YOLOv5_Webcam_Timer.lf
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d925f34

Please sign in to comment.