如何使用OpenCV从视频中读取特定的框架?
我想从视频中的特定帧读取到特定帧。例如,我的视频由 150 帧组成,但我想读取该视频中从第 5 帧到第 134 帧的视频。是否可以?
I want to read from a specific frame to a specific frame in a video. For example , my video consists of 150 frames, but I want to read the video from frame 5th to frame 134th in that video. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您必须读取视频并将其存储到多维 numpy 数组中。之后,您可以根据您的要求对 numpy 数组进行切片,
请参阅 https://stackoverflow.com/a/42166299/4141279如何将视频读入 numpy 数组。
然后,切片是通过以下方式完成的:
如果您有内存限制,您还可以在初始创建 numpy 数组期间删除所有不必要的帧。
First you have to read your video and store it into a multi-dimensional numpy array. Afterwards you can slice the numpy array according to your requirements
See https://stackoverflow.com/a/42166299/4141279 on how to read a video into a numpy array.
Slicing is then done by:
You could also drop all the unnecessary frames during initial creation of the numpy array if you have memory limitations.
我会做这样的事情:
这可能使用的opencv比你想要的要少,但我个人认为ffmpeg更适合这种操作
源1:openCV 指南
来源 2 : 关于堆栈溢出的另一个问题
I would do something like this :
This probably uses less opencv than you want, but I personally believe that ffmpeg is more adapted to this kind of operation
source 1 : an openCV guide
source 2 : another question on stack overflow