简体   繁体   中英

Get the frame from Video by the time (openCV)

I have a video and I have important times in this video For example:

    "frameTime1": "00:00:01.00"
    "frameTime2": "00:00:02.50"
    "frameTime2": "00:00:03.99"
    .
    .
    .

I get the FPS , and I get the totalFrameCount

If I want to get the frames in that's times for example the frame that's happen in this time "frameTime2": "00:00:02.50" I will do the following code

FrameIndex = (Time*FPS)/1000; //1000 Because 1 second = 100 milli second

In this case 00:00:02.50 = 2500 milli second, and the FPS = 29 So the FrameIndex in this case is 72.5 , in this case I will choose either frameNO: 72 or 73, but I feel that's not accurate enough, any better solution?

What's the best and accurate way to do this?

The most accurate thing you have at your disposal is the frame time. When you say that an event occurred at 2500ms, where is this time coming from? Why is it not aligned with your framerate? You only have video data points at 2483ms and 2517ms, no way around that.

If you are tracking an object on the video, and you want its position at t=2500, then you can interpolate the position from the known data points. You can do that either by doing linear interpolation between the neighboring frames, or possibly by fitting a curve on the object trajectory and solving for the target time.

If you want to rebuild a complete frame at t=2500 then it's much more complicated and still an open problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM