-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualization.py
More file actions
77 lines (63 loc) · 2.03 KB
/
visualization.py
File metadata and controls
77 lines (63 loc) · 2.03 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""Quick visualizer for all lane label JSONs.
Usage:
python visualization.py
Iterates over every JSON in ./data/label/image and shows the image with lane
annotations. Press any key (or close the window) to advance to the next
sample. Press Ctrl+C to stop.
"""
import glob
import json
import os
import cv2
import matplotlib.pyplot as plt
import numpy as np
# Folder containing label JSONs
LABEL_DIR = "./data/label/"
color_map = {
"yellow_lane": (255, 255, 0),
"white_lane": (255, 255, 255),
"white_dash_lane": (180, 180, 180),
}
def visualize_sample(json_path: str):
with open(json_path, "r") as f:
data = json.load(f)
img_path = data["file_path"]
img = cv2.imread(img_path)
if img is None:
print(f"[WARN] Image not found: {img_path}")
return
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.clf()
plt.imshow(img_rgb)
shown_labels = set()
for lane in data.get("lane_lines", []):
uv = np.asarray(lane.get("uv", []))
if uv.size == 0:
continue
cat = lane.get("category", "Unknown")
color = np.asarray(color_map.get(cat, (0, 255, 0))) / 255.0
label = cat if cat not in shown_labels else None
plt.scatter(uv[:, 0], uv[:, 1], color=color, s=50, label=label,
edgecolors="black", linewidths=1)
shown_labels.add(cat)
plt.title(os.path.basename(json_path))
plt.axis("off")
if shown_labels:
plt.legend()
plt.tight_layout()
plt.draw()
def main():
json_files = sorted(glob.glob(os.path.join(LABEL_DIR, "*.json")))
if not json_files:
print(f"No JSON files found in {LABEL_DIR}")
return
plt.figure(figsize=(16, 9))
for jp in json_files:
visualize_sample(jp)
print(f"Showing {jp}. Close figure or press any key to continue …")
# Wait until a key press or figure closed
plt.waitforbuttonpress()
if not plt.fignum_exists(plt.gcf().number): # Figure closed
break
if __name__ == "__main__":
main()