Let say I have made a program to detect a green ball in a video. Whenever there is a green ball detected, I want to print out the duration of video at the time the green ball is detected. Is it possible?
In this answer, you will find a solution to determine the frames per second.
so you'd want to use:
fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
and count the number of frames you're at. Then you can compute the video time with
videotime = current_frame_number / fps.
EDIT:
@Miki suggested to use CAP_PROP_POS_MSEC which should result in the same time (in [ms])
Corrected my typo as pointed out by @Swiper-CCCVI
You can simply measure a certain position in the video in milliseconds using
time_milli = cap.get(cv2.CAP_PROP_POS_MSEC)
and then divide time_milli by 1000 to get the time in seconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With