在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:\dev\sample_video\Superman-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说它也需要一个文件名作为输入。
答案 0 :(得分:-1)
尝试添加str convertion
cap = cv2.VideoCapture(str(the_file))