尝试阅读视频时,Python OpenCV崩溃了

时间:2015-06-21 12:06:54

标签: python python-2.7 opencv

当我调用.read()方法时,我的程序崩溃(使用.avi格式)。我的程序以其他格式(.ogv,.mkv)运行,但在这种情况下type(last_frame) == None。有没有解决这些错误的解决方案?

import cv2
import numpy as np

in_file = r'C:\Users\Johnny\Desktop\zola\animation.avi'
print(in_file)
cap = cv2.VideoCapture(in_file)
print(cap)
ret, last_frame = cap.read() # the program works without this line

try:
    if not cap.isOpened() : raise("damn!")
except TypeError as err:
    print(err)

输出:

C:\Users\Johnny\Desktop\zola\animation.ogv
<VideoCapture 02843110>
exceptions must be old-style classes or derived from BaseException, not str

0 个答案:

没有答案