Calculate dwell time of a person in a video

1.2k views Asked by At

I am working on some Machine Learning project where I have tracked people with Kalman Filter tracker. I want to calculate that how much time each person is there in the video.

I tried using the following logic : Suppose the person is present in the 5 frames and the video FPS is 15, then we can say that the person is (5*15) for 75 seconds in the video.

Note:- I have assumed & hard coded the FPS value in the code. I didn't find any way to get the FPS because I am passing frames of video for tracking.

But the problem is if I hard code the FPS value, so whenever the FPS changes (which I don't know when), I have to change in code, otherwise it will give wrong result.

2

There are 2 answers

0
Totoro On

My suggestion is to calculated elapsed time for processing each captured frame and maintaining an accumulator to calculate the on-screen time for each person detected. The frame rate depends on the amount of processing you do, for this type of projects.

0
S Andrew On

You don't need to hard code fps and you infact dont need fps for this. I believe your tracker will assign unique id to each person detected. Once you have the id, you can sinply start counting the number of seconds for that id. Once that person moves out of the frame, tracker id will be lost and you can stop the timer and thus you will have the total time person spent in the frame.

Have a look at this code: https://github.com/mailrocketsystems/AIComputerVision/blob/master/dwell_time_calculation.py

and maybe this video for explanation: https://www.youtube.com/watch?v=qn26XSinYfg