python cv2跳帧保存图片
作者:互联网
def save_img():
video_path = '/home/sg-ai/桌面/keras训练/reportfile/test.mp4'
# videos = os.listdir(video_path)
# for video_name in videos:
# file_name = video_name.split('.')[0]
# folder_name = file_name
# os.makedirs(folder_name,exist_ok=True)
vc = cv2.VideoCapture(video_path) #读入视频文件
c = 1
if vc.isOpened(): # 判断是否正常打开
rval, frame = vc.read()
else:
rval = False
timeF = 300 # 视频帧计数间隔频率
while rval: # 循环读取视频帧
rval, frame = vc.read()
pic_path = '/home/sg-ai/桌面/keras训练/reportfile/' + '/'
if (c % timeF == 0): # 每隔timeF帧进行存储操作
cv2.imwrite(pic_path + '_' + str(c) + '.jpg', frame) # 存储为图像,保存名为 文件夹名_数字(第几个文件).jpg
c = c + 1
cv2.waitKey(1)
vc.release()
save_img()
标签:vc,name,python,rval,cv2,video,path,跳帧 来源: https://blog.csdn.net/weixin_43883907/article/details/90637570