python用opencv打开视频_用openCV+python打开视频

您可以使用OpenCV(cv2)的新接口,这个面向对象的接口是从c++绑定的。

我觉得它更容易阅读。

注意:如果你用这个打开一张图片,fps没有任何意义,所以图片保持静止。import cv2

import sys

try:

vidFile = cv2.VideoCapture(sys.argv[1])

except:

print "problem opening input stream"

sys.exit(1)

if not vidFile.isOpened():

print "capture stream not open"

sys.exit(1)

nFrames = int(vidFile.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)) # one good way of namespacing legacy openCV: cv2.cv.*

print "frame number: %s" %nFrames

fps = vidFile.get(cv2.cv.CV_CAP_PROP_FPS)

print "FPS value: %s" %fps

ret, frame = vidFile.read() # read first frame, and the return code of the function.

while ret: # note that we don't have to use frame number here, we could read from a live written file.

print "yes"

cv2.imshow("frameWindow", frame)

cv2.waitKey(int(1/fps*1000)) # time to wait between frames, in mSec

ret, frame = vidFile.read() # read next frame, get next return code

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值