ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Cropping Occupancy Grid Maps directly from msg.Data

asked 2022-06-14 01:30:39 -0600

Nick_JR gravatar image

Hello, I am trying to compare two occupancy grid maps "at runtime", a ground truth map and a map generated from multirobot map merge. The reason I want to crop the generated map is because the map produced by multirobot_map_merge does not have the same dimensions or center with me maps that it merges, they are slightly off. Let's say that I have a 480x480 map. Does anyone know how I can crop this map (edit the tuple given by gm message) to 450x450? I tried making the tuple into a 2d list so it can be more intuitive and then flatten it again but it doesn't work. Has anyone done this before? I would appreciate some tips. Thanks in advance.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-06-14 02:08:32 -0600

electrophod gravatar image

The map is published as a list. First convert that list to a numpy array so it'll be easier for you to play with it.

Create a new numpy zero/ones array of whatever height X width you want and copy the corresponding elements from original map array to it.

edit flag offensive delete link more
2

answered 2022-06-15 15:19:56 -0600

Alex-SSoM gravatar image

updated 2022-06-15 15:20:43 -0600

First from your map_msg create a numpy array then reshape it by using height and width.

You can then use the bellow functions (taken from a class, you might need to modify it a bit):

def find_bounds(self):
    """
    Calculates the bounding box of a map array
    """
    map = self.occupancy_grid
    a = np.where(map != -1)
    bbox = np.min(a[0]), np.max(a[0]), np.min(a[1]), np.max(a[1])
    return Bounds(bbox[0], bbox[1], bbox[2], bbox[3])

def get_submap(self):
    """
    Retrieve the filled sub map that's contained inside the map array
    """
    self.sub_map_bounds = self.find_bounds()
    return self.occupancy_grid[self.sub_map_bounds.xmin:self.sub_map_bounds.xmax+1, self.sub_map_bounds.ymin:self.sub_map_bounds.ymax+1]
edit flag offensive delete link more

Comments

1

Thanks , i fixed my problem already, but the general idea is similar tou yours. The problem in my implementation was that i was searching the 2d array column-wise and not row-wise as the occupancy grid msg says. Moral of the story: read the documentation carefully.

Nick_JR gravatar image Nick_JR  ( 2022-06-15 15:34:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2022-06-14 01:30:39 -0600

Seen: 258 times

Last updated: Jun 15 '22