Show Grid line of 2d Map in image

122 views Asked by At

i had search through anywhere on google and forums but i couldnt found what i wanted. hope someone could help me here...

i had generated a 2d map from octomap using map_server map_saver from a pcd file it generated 2 file which is pgm and yaml file

however the generated pgm file does not have grid line on it.

my question is is it possible to show grid line on the image generated from map_saver? or is there any other way to generate an image with grid line from a 2D map?

1

There are 1 answers

0
GPrathap On

You may try this, change the map dimension and if you have a different orientation rotate the map accordingly.

  import pylab as plt
  import numpy as np
  # Load the image
  img =  np.array(plt.imread("g_map.pgm"))

  # assume dimension of map 20mx20m
  map_dim_x = 20 
  map_dim_y = 20 

  # relationship between pixel and map  
  dx, dy = int(img.shape[0]/map_dim_x),int(img.shape[1]/map_dim_y)

  grid_color = 0

  img[:,::dy,] = grid_color
  img[::dx,] = grid_color

  plt.imshow(img)
  plt.show()

enter image description here