|  | 
 
 楼主|
发表于 2025-5-16 17:24:42
|
显示全部楼层 
| #!/usr/bin/python3 import numpy as np
 import cv2
 import os
 import sys
 
 argv = sys.argv[1:]
 tc_name = argv[0]
 
 src_path = os.path.join(tc_name, 'image/')
 sav_path = os.path.join(tc_name, 'video.avi')
 
 image_size = (18,18)
 video_size = (18*20,18*20)
 image_length = image_size[0]*image_size[1]
 fps = 1
 color = 0
 fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
 videowrite = cv2.VideoWriter(sav_path, fourcc, fps, video_size, color)
 print("Picture size: {}".format(image_size))
 print("Video size: {}".format(video_size))
 
 all_files = os.listdir(src_path)
 index = len(all_files)
 print("Picture num:" + str(index))
 
 img_array=[]
 for filename in [src_path + r'{0}.raw'.format(i) for i in range(0,index)]:
 with open(filename, 'rb') as file:
 raw_data = file.read()
 img = np.frombuffer(raw_data, dtype=np.uint8)
 img = np.pad(img, (0, image_length - len(img)))     # when img_length is not enough, add 0 to fill the size
 img = img.reshape(image_size)
 img_array.append(img)
 
 for i in range(0,index):
 img_array[i] = cv2.resize(img_array[i],video_size,interpolation=cv2.INTER_NEAREST)
 videowrite.write(img_array[i])
 #print(img_array[i])
 videowrite.release()
 print('------done!!!-------')
 
 | 
 |