你可以使用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
有没有其他更简单的方法来做到这一点? – 2014-03-12 09:18:12
这是更简单的方法。 – karlphillip 2014-03-12 12:57:58