how to correctly convert OccupancyGrid format message to image ?
Hello,all
I want to convert OccupancyGrid
format message to 'mono8' formt image. Actually,I subscribed /move_base/local_costmap/costmap
topic ,but the result look like weird, compared with map showed in rviz,it was inversed and rotated .
here is code relative converting proccess :
def callback(self,data):
self.width = data.info.width
self.height = data.info.height
self.resolution = data.info.resolution
self.length = len(data.data)
#self.min_line = []
#creat an mat to load costmap
costmap_mat = cv.CreateMat(self.height,self.width,cv.CV_8UC1)
for i in range(1,self.height):
for j in range(1,self.width):
cv.Set2D(costmap_mat,i-1,j-1,255-int(float(data.data[(i-1)*self.width+j])/100*255))
Any answer is appreciated .-
edit:
the code given by @Stefan Kohlbrecher shed light on my problem . It was wrong with order i-1
and j-1
。here is modified code and it works,
for i in range(1,self.height):
for j in range(1,self.width):
cv.Set2D(costmap_mat,self.width-j,self.height-i,255-int(float(data.data[(i-1)*self.width+j])/100*255))
Althrough my problem was solved , I am still confused that the sequence is self.height-1--->0
rather than 0--->self.height-1
.