Commit
·
b68fc7d
1
Parent(s):
b0d277a
Distinguish ambigouity mapping'
Browse files
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
app.py
CHANGED
@@ -84,7 +84,7 @@ ade_palette = np.array([
|
|
84 |
], dtype=np.uint8)
|
85 |
|
86 |
custom_class_map = {
|
87 |
-
"Garbage": [(
|
88 |
"Water": [(0, 102, 200), (11, 102, 255), (31, 0, 255)],
|
89 |
"Grass / Vegetation": [(10, 255, 71), (143, 255, 140)],
|
90 |
"Tree / Natural Obstacle": [(4, 200, 3), (235, 12, 255), (255, 6, 82), (255, 163, 0)],
|
@@ -96,6 +96,13 @@ custom_class_map = {
|
|
96 |
}
|
97 |
TOL = 30 # RGB tolerance
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
# Masking zones (Garbage and Water zone to be travelable)
|
100 |
def build_masks(seg):
|
101 |
"""
|
@@ -107,6 +114,16 @@ def build_masks(seg):
|
|
107 |
decoded = ade_palette[seg]
|
108 |
water_mask = np.zeros(seg.shape, np.uint8)
|
109 |
garbage_mask = np.zeros_like(water_mask)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
# Append water pixels to water_mask
|
111 |
for rgb in custom_class_map["Water"]:
|
112 |
water_mask |= (np.abs(decoded - rgb).max(axis=-1) <= TOL)
|
@@ -117,7 +134,7 @@ def build_masks(seg):
|
|
117 |
return water_mask, garbage_mask, movable_mask
|
118 |
|
119 |
# Garbage mask can be highlighted in red
|
120 |
-
def highlight_chunk_masks_on_frame(frame, labels, objs, color_uncollected=(0, 0, 128), color_collected=(0, 128, 0), alpha=0.
|
121 |
"""
|
122 |
Overlays semi-transparent colored regions for garbage chunks on the frame.
|
123 |
`objs` must have 'pos' and 'col' keys. The collection status changes the overlay color.
|
@@ -175,7 +192,7 @@ def knn_path(start, targets, occ):
|
|
175 |
|
176 |
# ── Robot sprite/class -──────────────────────────────────────────────────
|
177 |
class Robot:
|
178 |
-
def __init__(self, sprite, speed=
|
179 |
self.png = np.array(Image.open(sprite).convert("RGBA").resize((40,40)))
|
180 |
self.pos = [0,0]; self.speed=speed
|
181 |
def step(self, path):
|
|
|
84 |
], dtype=np.uint8)
|
85 |
|
86 |
custom_class_map = {
|
87 |
+
"Garbage": [(255, 8, 41)],
|
88 |
"Water": [(0, 102, 200), (11, 102, 255), (31, 0, 255)],
|
89 |
"Grass / Vegetation": [(10, 255, 71), (143, 255, 140)],
|
90 |
"Tree / Natural Obstacle": [(4, 200, 3), (235, 12, 255), (255, 6, 82), (255, 163, 0)],
|
|
|
96 |
}
|
97 |
TOL = 30 # RGB tolerance
|
98 |
|
99 |
+
# Segment class [150, 5, 61] is only detectable as garbage if it's large enough
|
100 |
+
def interpret_rgb_class(decoded_img):
|
101 |
+
ambiguous_rgb = np.array([150, 5, 61])
|
102 |
+
matches = np.all(np.abs(decoded_img - ambiguous_rgb) <= TOL, axis=-1)
|
103 |
+
match_ratio = np.count_nonzero(matches) / matches.size
|
104 |
+
return "garbage" if match_ratio > 0.15 else "sand"
|
105 |
+
|
106 |
# Masking zones (Garbage and Water zone to be travelable)
|
107 |
def build_masks(seg):
|
108 |
"""
|
|
|
114 |
decoded = ade_palette[seg]
|
115 |
water_mask = np.zeros(seg.shape, np.uint8)
|
116 |
garbage_mask = np.zeros_like(water_mask)
|
117 |
+
# Resolve ambiguity: (150,5,61) → Sand or Garbage?
|
118 |
+
context_label = interpret_rgb_class(decoded)
|
119 |
+
resolved_map = custom_class_map.copy()
|
120 |
+
# Dynamically re-assign the ambiguous RGB class
|
121 |
+
if context_label == "garbage":
|
122 |
+
resolved_map["Garbage"].append((150, 5, 61))
|
123 |
+
resolved_map["Sand / Soil / Ground"] = [rgb for rgb in resolved_map["Sand / Soil / Ground"] if rgb != (150, 5, 61)]
|
124 |
+
else: # Fall back as appointed to be sth else
|
125 |
+
resolved_map["Sand / Soil / Ground"].append((150, 5, 61))
|
126 |
+
resolved_map["Garbage"] = [rgb for rgb in resolved_map["Garbage"] if rgb != (150, 5, 61)]
|
127 |
# Append water pixels to water_mask
|
128 |
for rgb in custom_class_map["Water"]:
|
129 |
water_mask |= (np.abs(decoded - rgb).max(axis=-1) <= TOL)
|
|
|
134 |
return water_mask, garbage_mask, movable_mask
|
135 |
|
136 |
# Garbage mask can be highlighted in red
|
137 |
+
def highlight_chunk_masks_on_frame(frame, labels, objs, color_uncollected=(0, 0, 128), color_collected=(0, 128, 0), alpha=0.6):
|
138 |
"""
|
139 |
Overlays semi-transparent colored regions for garbage chunks on the frame.
|
140 |
`objs` must have 'pos' and 'col' keys. The collection status changes the overlay color.
|
|
|
192 |
|
193 |
# ── Robot sprite/class -──────────────────────────────────────────────────
|
194 |
class Robot:
|
195 |
+
def __init__(self, sprite, speed=2000): # Declare the robot's physical stats and routing (position, speed, movement, path)
|
196 |
self.png = np.array(Image.open(sprite).convert("RGBA").resize((40,40)))
|
197 |
self.pos = [0,0]; self.speed=speed
|
198 |
def step(self, path):
|