write results to the output_path.
(outputs, input_path, output_path, fps=30)
| 134 | |
| 135 | |
| 136 | def write(outputs, input_path, output_path, fps=30): |
| 137 | """ |
| 138 | write results to the output_path. |
| 139 | """ |
| 140 | |
| 141 | if osp.exists(output_path) is False: |
| 142 | os.makedirs(output_path) |
| 143 | |
| 144 | size = outputs[0].shape[2:][::-1] |
| 145 | |
| 146 | _, file_name_with_extension = os.path.split(input_path) |
| 147 | file_name, _ = os.path.splitext(file_name_with_extension) |
| 148 | |
| 149 | save_video_path = f"{output_path}/fps{fps}_{file_name}.mp4" |
| 150 | fourcc = cv2.VideoWriter_fourcc(*"mp4v") |
| 151 | writer = cv2.VideoWriter(save_video_path, fourcc, fps, size) |
| 152 | |
| 153 | for i, imgt_pred in enumerate(outputs): |
| 154 | imgt_pred = tensor2img(imgt_pred) |
| 155 | imgt_pred = cv2.cvtColor(imgt_pred, cv2.COLOR_RGB2BGR) |
| 156 | writer.write(imgt_pred) |
| 157 | print(f"Demo video is saved to [{save_video_path}]") |
| 158 | |
| 159 | writer.release() |
| 160 | |
| 161 | |
| 162 | def process( |