import cv2
import time
import os
os.listdir(r’D:\recolasmall\sp’)
i=0
for info in os.listdir(r’D:\recolasmall\sp’):
lis=[‘16’,‘17’,‘19’,‘21’,‘23’,‘25’,‘26’,‘28’,‘30’,‘34’,‘37’,‘39’,‘41’,‘42’,‘43’,‘45’,‘46’,‘48’,‘56’,‘58’,‘62’,‘64’,‘65’]
domain = os.path.abspath(r’D:\recolasmall\sp’) #获取文件夹的路径,此处其实没必要这么写,目的是为了熟悉os的文件夹操作
info = os.path.join(domain,info) #将路径与文件名结合起来就是每个文件的完整路径
info = open(info,‘r’) #读取文件内容
targetPath = r'D:\recolasmall' + os.path.sep + 'p' + lis[i]
i=i+1
print(targetPath)
if not os.path.exists(targetPath):
os.makedirs(targetPath)
else:
print('路径已经存在!')
vct = cv2.VideoCapture(info.name) # 读取每个videocaputer
c = 1
if vct.isOpened(): # 判断是否正常打开
rval, frame = vct.read()
else:
rval = False
timeF = 1 # 视频帧计数间隔频率
while rval: # 循环读取视频帧
rval, frame = vct.read()
if (c % timeF == 0): # 每隔timeF帧进行存储操作
# os.makedirs(outputpath[i]),创建文件路径
cv2.imencode('.jpg', frame)[1].tofile(targetPath + os.path.sep+str(c) + '.jpg') # 存储为图像
c = c + 1
cv2.waitKey(1)
vct.release()
print("*******"+info.name) #使用readline函数得到一条一条的信息,如果使用read获取全部信息亦可;
info.close()