淘宝 客要推广网站怎么做,天津河东做网站哪家好,饰品网站建设规划书,试剂产品商城网站建设视频截取帧
废话不多说直接上代码#xff1a;
from cv2 import VideoCapture
from cv2 import imwrite# 定义保存图片函数
# image:要保存的图片名字
# addr#xff1b;图片地址与相片名字的前部分
# num: 相片#xff0c;名字的后缀。int 类型
def save_image(image, add…视频截取帧
废话不多说直接上代码
from cv2 import VideoCapture
from cv2 import imwrite# 定义保存图片函数
# image:要保存的图片名字
# addr图片地址与相片名字的前部分
# num: 相片名字的后缀。int 类型
def save_image(image, addr, num):address addr str(num) .jpgimwrite(address, image)if __name__ __main__:video_path /home/xxx/桌面/data/wx.mp4 #视频路径out_path /home/xxx/桌面/data/AIswitch/out/img_ #保存图片路径名字is_all_frame False #是否取所有的帧sta_frame 1 #开始帧end_frame 400 #结束帧######time_interval 10 #时间间隔# 读取视频文件videoCapture VideoCapture(video_path)# 读帧success, frame videoCapture.read()print(success)i 0j 0if is_all_frame:time_interval 1while success:# people1start_h 530start_w 90pad_h 283pad_w 240frame frame[start_h:start_hpad_h,start_w:start_wpad_w,:]i i 1if (i % time_interval 0):if is_all_frame False:if i sta_frame and i end_frame:j j 1print(save frame:, i)save_image(frame, out_path, j)elif i end_frame:breakelse:j j 1print(save frame:, i)save_image(frame, out_path, j)success, frame videoCapture.read()