-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparse_to_videos.py
executable file
·55 lines (44 loc) · 2.17 KB
/
parse_to_videos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import cv2 as cv
from tqdm import tqdm
from pathlib import Path
from modules import utils, helpers
from modules.carla_utils import labelmap
if __name__ == "__main__":
# Load the args
args = utils.ArgParser(script="parse_to_videos").parse()
fps = args.fps
root_dir = args.root_dir
# Define the colormap to be used
cmap = labelmap.cmap[...,::-1] #flip to bgr for opencv
# Load all the dataset folders
folders = helpers.folders_loader(root_dir)
# For each main folder (town + slen)
pbar = tqdm(folders.keys(), desc="Generating the videos")
for key in pbar:
pbar.set_description(f"Generating the videos for {key}")
# Iter over all the weathers
in_pbar = tqdm(folders[key], desc="Considering the weather-daytime", leave=False)
for weather_folder in in_pbar:
in_pbar.set_description(f"Considering the weather-daytime: {weather_folder.stem}")
# Define the input paths
rgb_folder = Path(weather_folder / "rgb")
semantic_folder = Path(weather_folder / "semantic")
# Define the output paths
rgb_out_path, semantic_out_path = helpers.videos_out_path(weather_folder)
# Initialize the videos
rgb_video = cv.VideoWriter(str(rgb_out_path), cv.VideoWriter.fourcc(*'mp4v'), fps, (1920,1080))
semantic_video = cv.VideoWriter(str(semantic_out_path), cv.VideoWriter.fourcc(*'mp4v'), fps, (1920,1080))
# Generate the videos
fnames = [os.path.splitext(f)[0] for f in sorted(os.listdir(rgb_folder)) if not f.startswith('.') and os.path.isfile(str(rgb_folder / f))]
for fname in tqdm(fnames, desc="Generating the videos", leave=False):
rgb_video.write(
cv.imread(str(rgb_folder / (fname + ".jpg")), cv.IMREAD_UNCHANGED)
)
semantic_video.write(
cmap[
cv.imread(str(semantic_folder / (fname + ".png")), cv.IMREAD_UNCHANGED)
]
)
rgb_video.release()
semantic_video.release()