前言在之前的文章里,我找了用一个python程序把延时摄影的很多张照片合成视频,那个时候用来合成树莓派摄像头拍的几百张照片问题不大,但是今天尝试合成手机拍的照片,瞬间内存爆满,一看代码,气死个人,把所有照片存进一个数组再从数组里一个个取出来写入视频,搁这搁这呢属于是,所以自己重写一个,顺便去掉文件名限制,直接默认排序 程序直接读取图片写入视频,内存占用就下来了 12345678910111213141516171819import cv2import osphotos = os.listdir(r'cam_3D')photo = cv2.imread('cam_3D\\' + photos[0])size = (photo.shape[1], photo.shape[0])videowrite = cv2.VideoWriter(r'test.mp4', -1, 30, size)i=0for filename in photos: path = 'cam_3D\\' + filename img = cv2.imread(path) if img is None: print(filename + " is error!") continue videowrite.write(img) i += 1 print(i)videowrite.release()print('finished')