赞
踩
''' 总结cv2相关内容 ''' import cv2 import numpy as np ''' 读图片 ''' image_path = '/data/weichai/0817_choice_frame/8.4_sortheast/1.jpg' image = cv2.imread(image_path) # image是一个矩阵。shape: (hight, weight, channel) ''' 保存图片 ''' output_path = '/home/liulihao/test/demo.jpg' save_image = np.zeros([200,100,3]) cv2.imwrite(output_path, save_image) # save_image是一个矩阵,shape: (hight, weight, channel) ''' 读视频 ''' input_video = '/data/cylinder_demo/raw_data/qiping_merge_20210824.avi' video_reader = cv2.VideoCapture(input_video) fps = video_reader.get(5) frame_id = 0 have_more_frame, frame = video_reader.read() # have_more_frame是一个布尔变量,代表此帧之后视频中是否还有帧 # frame是图片转化成的矩阵。shape: (hight, weight, channel) while have_more_frame: '''此处添加具体操作''' # print(frame_id) frame_id += 1 have_more_frame, frame = video_reader.read() video_reader.release() ''' 保存视频 ''' output_video_path = "/home/liulihao/test/test.avi" output_fps = 30 output_height, output_width,_ = image.shape video_writer = cv2.VideoWriter( output_video_path, # cv2.VideoWriter_fourcc(*'MP4V'), cv2.VideoWriter_fourcc(*'XVID'), # cv2.VideoWriter_fourcc('I', '4', '2', '0'), # cv2.VideoWriter_fourcc('M','J','P','G'), # https://docs.opencv.org/master/dd/d43/tutorial_py_video_display.html output_fps, # fps 每秒的帧数 (output_width, output_height), # resolution ) for i in range(30): video_writer.write(image) video_writer.release()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。