在openCV中,使用python,如何打开视频文件?
目前我有:
cap = cv2.VideoCapture('Superman-01-The_Mad_Scientist.mp4')
和我的。mp4与这个脚本在同一个文件夹中。当我计算print cap.isOpened()
时,我得到假。如何正确地打开这个文件?
我试过的另一件事:
BASE = os.path.dirname(os.path.abspath(__file__))
the_file = open(os.path.join(BASE, 'sample_video','Superman-01-The_Mad_Scientist.mp4'))
print the_file.__str__()
cap = cv2.VideoCapture(the_file)
print cap.isOpened()
输出:Traceback (most recent call last):
<open file 'C:devsample_videoSuperman-01-The_Mad_Scientist.mp4', mode 'r' at 0x02482288>
File "C:/dev/test.py", line 9, in <module>
cap = cv2.VideoCapture(the_file)
TypeError: an integer is required
这意味着它在寻找一个相机,但教程和API说它需要一个文件名作为输入
尝试添加STR转换
cap = cv2.VideoCapture(str(the_file))