-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
I'm not 100% sure but I think this would improve the performance of nav2 because it wont confuse insides and outsides of objects as much of course one could also make the insides black as they theoretically are but i wanted to make it look like a slam map
I have written a post processing script to do this based on a floodfill algorithm starting from a known-empty space on the map.
I don't know if you want to include something similar into your version, if not you can still keep this open for others to look at.
| before | after |
|---|---|
![]() |
![]() |
# Load the pgm map as text and convert it to a numpy array
import numpy as np
def flood_fill(map, x, y):
# check if the cell is out of bounds
if x < 0 or y < 0 or x >= map.shape[0] or y >= map.shape[1]:
return map, []
# check if the cell is already filled
if map[x, y] != 255:
return map, []
# fill the cell
map[x, y] = -1
# return the neighbors as a list of tuples
candidates = [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]
return map, candidates
filename = 'map.pgm'
with open(filename, 'r') as file:
lines = file.readlines()
# split the lines into a list of lists
map_data = [line.split() for line in lines]
# remove the first 3 lines of the header
map_data = map_data[3:]
# flood fill the map starting from the center
map_data_np = np.array(map_data, dtype=int)
candidates = [(map_data_np.shape[0]//2, map_data_np.shape[1]//2)]
while candidates:
x, y = candidates.pop(0)
map_data_np, new_candidates = flood_fill(map_data_np, x, y)
candidates.extend(new_candidates)
# invert colors: 255 -> 100, -1 -> 255
map_data_np[map_data_np == 255] = 205 # make empty cells gray
map_data_np[map_data_np == -1] = 255 # make filled cells white
# save the numpy array as a new pgm file
new_filename = 'map_filled.pgm'
with open(new_filename, 'w') as file:
# write the same header
file.write(lines[0])
file.write(lines[1])
file.write(lines[2])
# write the data
for row in map_data_np:
file.write(' '.join([f'{cell:0>2f}' for cell in row]))
file.write('\n')Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels

