| 93 | |
| 94 | |
| 95 | def write2video(results_dir, *video_list): |
| 96 | cat_video = None |
| 97 | |
| 98 | for video in video_list: |
| 99 | video_numpy = video[:, :3, :, :].cpu().float().detach().numpy() |
| 100 | video_numpy = (np.transpose(video_numpy, (0, 2, 3, 1)) + 1) / 2.0 * 255.0 |
| 101 | video_numpy = video_numpy.astype(np.uint8) |
| 102 | cat_video = np.concatenate([cat_video, video_numpy], 2) if cat_video is not None else video_numpy |
| 103 | |
| 104 | image_array = [] |
| 105 | for i in range(cat_video.shape[0]): |
| 106 | image_array.append(cat_video[i]) |
| 107 | |
| 108 | out_name = results_dir + '.mp4' |
| 109 | _, height, width, layers = cat_video.shape |
| 110 | size = (width, height) |
| 111 | out = cv2.VideoWriter(out_name, cv2.VideoWriter_fourcc(*'mp4v'), 15, size) |
| 112 | |
| 113 | for i in range(len(image_array)): |
| 114 | out.write(image_array[i][:, :, ::-1]) |
| 115 | out.release() |