the below code calculates the number of processed frames per second for a video and display it on the output processed frame using opencv:
import cv2 as cv
import numpy as np
from collections import deque
from imutils.video import FPS
# matplotlib.pyplot as plt
import datetime
from class22 import pre_processing
pts1 = deque(maxlen=40)
pts2 = deque(maxlen=40)
#ceate a capture object-------------------------------------------------------------------
cap=cv.VideoCapture(r'C:/Users/kjbaili/Documents/Masterarbeit/Praxis/Erste
_Videoeinsatz/Basler_acA 1920-40uc__22823716__20200724_145423423.mp4')
fps_start_time = datetime.datetime.now() #start timer
FPs= 0
total_frames = 0
#-------------------------------------------------------------------
ob1=pre_processing()
ob2=pre_processing()
fps = FPS().start()
#start reading frames
while cap.isOpened:
ret,frame=cap.read(())
#----------------------------------------------------------------------------
total_frames = total_frames + 1 #collect the total number of frames
fps_end_time = datetime.datetime.now() #stop timer
time_diff = fps_end_time - fps_start_time
if time_diff.seconds == 0:
FBs = 0.0
else:
FBs = (total_frames / time_diff.seconds) #estimate the frame per second
fps_text = "FPS: {:.2f}".format(FBs)
cv.rectangle(frame, (10, 2), (100,20), (255,255,255), -1)
cv.putText(frame, fps_text, (15, 15),cv.FONT_HERSHEY_SIMPLEX, 0.5 , (0,0,0))# display the fps
on the output image
#----------------------------------------------------------------------------
However, I'm trying to plot the fps over time using matplotlib for better illustration, so that the plot would look like the following:
So can anyone tells me how can i plot the data shown in the above code using e.g matplotlib as it doesn't seem to be easy since the number of frames changes as time elapses.
Thanks in advance
