【发布时间】:2020-05-13 05:05:31
【问题描述】:
思路如下,脚本需要递归识别文件夹中的所有DAV文件,并使用OPENCV将5秒的转换成JPEG。到目前为止一切正常。然而,该脚本列出了 AVI 文件,但只转换了 1 个文件,而不是所有列出的文件。
import os
import cv2
path = 'C:\\Users\\coleta 1\\Desktop\\SNAPSHOT'
files = []
for r, d, f in os.walk(path):
for file in f:
if '.avi' in file:
files.append(os.path.join(r, file))
for f in files:
print(f)
vidcap = cv2.VideoCapture(f)
def Printar(sec):
vidcap.set(cv2.CAP_PROP_POS_MSEC,sec*10000)
hasFrames,image = vidcap.read()
if hasFrames:
cv2.imwrite("image"+str(count)+".jpg", image)
return hasFrames
sec = 0
frameRate = 0.5
count=1
success = Printar(sec)
while success:
count = count + 1
sec = sec + frameRate
sec = round(sec, 2)
success = Printar(sec)
continue
【问题讨论】:
标签: python opencv for-loop avi