我正在使用Open cv从目录中的一些视频中提取帧。在遍历文件时,我将获得的帧命名为frame0,frame1等。但是当循环移动到下一个视频时,它再次开始命名帧0,1,2 ...,因此所有旧帧都将被覆盖。
这是我所做的:
finaldata
提取帧的功能:
library(dplyr)
maindata = data.frame(ID=c(1:10), Name=c("a","b","c","d","e","f","g","h","i","j"))
subdata = data.frame(ID=c(1,3,6,2,7), Age=c(26,34,33,55,21))
#This is what I would like to have
finaldata = data.frame(ID=c(1,3,6,2,7), Name=c("a","c","f","b","7"), Age=c(26,34,33,55,21))
# I've tried using dplyr with no luck, This must be very basic :(
finaldata = maindata %>%
filter(ID %in% subdata$ID) %>%
mutate(Age=subdata$Age)
然后我执行代码:
#To make a list of paths to all files in dir
f=[]
for dirpath, subdir, files in os.walk(r'C:\Users\user\Desktop\Files'):
for x in files:
f.append(os.path.join(dirpath, x))
我该如何纠正,以便当循环在创建n帧后遇到下一个视频时,它开始将它们命名为n + 1,n + 2...。而不是从0开始重新覆盖?
答案 0 :(得分:3)
每次调用函数count
时,变量extractFrames
都会被初始化-即每个文件一次。
您需要将初始化放在函数之外:
count = 0
def extractFrames(pathIn, pathOut):
cap = cv.VideoCapture(pathIn)
...