当我调用.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