if save_vid: if vid_path != save_path: # new video print("save=", save_path) vid_path = save_path if isinstance(vid_writer, cv2.VideoWriter): vid_writer.release() # release previous video writer if vid_cap: # video fps = vid_cap.get(cv2.CAP_PROP_FPS) w = int(vid_cap.get(cv2.CAP_PROP_FRAME_WIDTH)) h = int(vid_cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) else: # stream fps, w, h = 30, im0.shape[1], im0.shape[0] save_path += '.mp4' vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h)) vid_writer.write(im0)
时间: 2024-02-10 22:21:33 浏览: 105
USB.rar_USB VID_pid and vid_usb read_vid_vid pid
这段代码是用来保存视频的。它会检查是否需要保存视频,并检查保存路径是否有更改。如果路径改变了,则释放之前的视频写入器,创建一个新的写入器来写入新的视频。如果视频是从文件中读取的,则会从视频中获取帧率、宽度和高度。如果视频是从流中获取的,则会设置默认的帧率为30,宽度和高度为输入图像的宽度和高度。最后,它使用cv2.VideoWriter将帧写入视频。
阅读全文