根据标题,我试图编写代码,循环浏览文件夹中的多个视频以提取它们的帧,然后将每个视频的帧写入它们自己的新文件夹,例如video1到frames\u video1,video2到frames\u video2
这是我的代码:
subclip_video_path = main_path + "\\subclips"
frames_path = main_path + "\\frames"
#loop through videos in file
for subclips in subclip_video_path:
currentVid = cv2.VideoCapture(subclips)
success, image = currentVid.read()
count = 0
while success:
#create new frames folder for each video
newFrameFolder = ("frames_" + subclips)
os.makedirs(newFrameFolder)
我得到这个错误:
[ERROR:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-k8sx3e60\opencv\modules\videoio\src\cap.cpp (142) cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-k8sx3e60\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): P in function 'cv::icvExtractPattern'
这是什么意思?我怎样才能解决这个问题
for subclips in subclip_video_path:
您需要获取视频列表:
这意味着获取所有.mp4扩展名视频文件并将其存储在
sub_clip_video_path
变量中我的结果是:
因为我确定目录包含两个
.mp4
扩展文件,现在我可以继续了VideoCapture
李>声明
VideoCapture
后,读取当前视频中的所有帧,然后为下一个视频声明VideoCapture
while success
这将创建一个无限循环李>如果从视频抓取第一帧,则
success
变量返回True
。当你说:您将为当前帧创建无限量的文件夹
以下是我的结果:
我用
glob
收集了所有的视频读取当前视频时:
如果当前帧成功抓取,则声明文件夹名称。如果文件夹不存在,请创建它
然后声明图像名称并保存它
相关问题 更多 >
编程相关推荐