I have a video file that I'm doing image processing on. However I need the time elapsed at each frame.
So far I have
frames = camera.get(cv2.CAP_PROP_FRAME_COUNT)
fps = camera.get(cv2.CAP_PROP_FPS)
seconds_per_frame = fps/frames
counter = 0
while True:
//get frame
counter += seconds_per_frame
Using this code that I have right now is being finicky. It starts off giving me the time for the actual video but then starts being inaccurate. For example it will say that a current frame is at 12 seconds. But when I actually open the video file and go to that frame, its 7 seconds.
How are you guys calculating time when analyzing video?
I can't see your video in order to check, but I suspect you are accumulating floating point errors.
Try using the frame counter and fps
to derive elapsed time like this:
elapsed = frameNumber / fps