我是靠谱客的博主 过时飞机,这篇文章主要介绍python一帧一帧读取视频_如何使用Opencv python在视频流中逐帧处理视频的图像,现在分享给大家,希望可以做个参考。

在阅读了

VideoCapture的文档之后,我发现可以告诉VideoCapture,下一次我们调用

VideoCapture.read()(或

VideoCapture.grab())时要处理哪一帧。

问题是当您想要读取()尚未准备好的帧时,VideoCapture对象卡在该帧上,从不继续。所以你必须强制它从前一帧重新开始。

这里是代码

import cv2

cap = cv2.VideoCapture("./out.mp4")

while not cap.isOpened():

cap = cv2.VideoCapture("./out.mp4")

cv2.waitKey(1000)

print "Wait for the header"

pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)

while True:

flag, frame = cap.read()

if flag:

# The frame is ready and already captured

cv2.imshow('video', frame)

pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)

print str(pos_frame)+" frames"

else:

# The next frame is not ready, so we try to read it again

cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos_frame-1)

print "frame is not ready&#

最后

以上就是过时飞机最近收集整理的关于python一帧一帧读取视频_如何使用Opencv python在视频流中逐帧处理视频的图像的全部内容,更多相关python一帧一帧读取视频_如何使用Opencv内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部