网站建设工作会议.,地方门户源码,wordpress模板 更换,九狐建设网站python目标检测将视频按照帧率切除成图片
python目标检测将视频按照帧率切除成图片#xff0c;并且允许放入多个多个视频
完整代码如下#xff1a;
import os
import cv2class VideoSplit:将视频分帧为图片source_path: 视频文件存储地址result_path并且允许放入多个多个视频
完整代码如下
import os
import cv2class VideoSplit:将视频分帧为图片source_path: 视频文件存储地址result_path 图片结果文件保存地址frame: 帧率每frame帧保存一张图片def __init__(self, source_path, result_path, frame10):self.source_path source_pathif not os.path.exists(self.source_path):raise Exception(源文件路径不存在)self.result_path result_pathself.frame frameif not os.path.exists(self.result_path):os.makedirs(self.result_path)print(创建文件夹{},.format(self.result_path))def split_video(self):video_list os.listdir(self.source_path)for i, name in enumerate(video_list):video_list[i] os.path.join(self.source_path, name)basename name.split(.)[0]video_result_path os.path.join(self.result_path, basename)if not os.path.exists(video_result_path):os.makedirs(video_result_path)print(创建子文件夹{},.format(basename))cap cv2.VideoCapture(video_list[i])print(视频{}开始分帧....format(name))sum 0i 0while True:ret, frame cap.read()if not ret:breaksum 1# 保存图片if sum self.frame:sum 0i 1imgname basename _ str(i) .jpgimgPath os.path.join(video_result_path, imgname)cv2.imwrite(imgPath, frame)print(imgname)print({}视频文件提取完成.format(basename))print(完成)if __name__ __main__:source_path rC:\Users\videoresult_path rC:\Users\resulttst VideoSplit(source_path, result_path)tst.split_video()
注意尽量手动创建两个文件夹video、result