简体   繁体   English

按时间从视频获取帧(openCV)

[英]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 我得到了FPS ,我得到了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 如果要获取该时间段内的帧,例如这段时间内发生的帧“ frameTime2”:“ 00:00:02.50”,我将执行以下代码

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? 在这种情况下00:00:02.50 = 2500毫秒,而FPS = 29因此,在这种情况下, FrameIndex72.5 ,在这种情况下,我将选择frameNO:72或73,但是我觉得不够准确,更好解?

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? 当您说某个事件发生在2500毫秒时,这一次是从哪里来的? Why is it not aligned with your framerate? 为什么它与您的帧率不一致? You only have video data points at 2483ms and 2517ms, no way around that. 您只有2483ms和2517ms的视频数据点,没有办法解决。

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. 如果要跟踪视频上的对象,并且希望将其位置设置为t = 2500,则可以从已知数据点内插该位置。 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. 如果要在t = 2500时重建一个完整的帧,则要复杂得多,但仍然是一个开放的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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