npy转png png转mp4
def npy2jpg(dir, dest_dir):
if os.path.exists(dir) == False:
os.makedirs(dir)
if os.path.exists(dest_dir) == False:
os.makedirs(dest_dir)
file = dir + 'npy.npy'
arrList = np.load(file)
arrList = arrList * 255
for row in arrList: #注意本例是多图 5行40列 480 560
for arr in row:
arr = np.reshape(arr, (1, 480, 560))
r = Image.fromarray(arr[0]).convert("L")
r.save(dest_dir + str(count) + ".png")
def png2video():
fsp = 5
fourcc = cv2.VideoWriter_fourcc(*'avc1')
video_path = "D:/train.mp4" # 修改视频存放路径
video_out = cv2.VideoWriter(video_path, fourcc, fsp, (560, 480))
# 路径不能含中文
img_path = "D:/" # 图片存放地址
for i in range(1218, 4584, 1): # 这里需设置图片数量
filename = img_path+"radar_3" + str(i) + ".png"
if os.path.exists(filename):
frame = cv2.imread(filename) # 改 ⑤
video_out.write(frame)
print(filename + "已录入")
video_out.release()
if __name__ == '__main__':
dir = "D:/" # npy文件路径
dest_dir = "D:/" # 图片存储路径
npy2jpg(dir, dest_dir)
png2video()