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

how to correctly convert OccupancyGrid format message to image ?

asked 2014-05-11 20:23:25 -0600

zsbhaha gravatar image

updated 2014-05-12 01:14:29 -0600

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 .

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2014-05-11 22:04:58 -0600

AHornung gravatar image

Another option would be to use gridmap_2d, it offers conversions between OccupancyGrid messages and OpenCV images.

edit flag offensive delete link more

Comments

Thank you; I'll check those resources out .

zsbhaha gravatar image zsbhaha  ( 2014-05-12 01:15:15 -0600 )edit
0

answered 2014-05-11 20:39:39 -0600

This conversion is also performed (in C++) in hector_compressed_map_transport. See code here. There are probably some opportunities for making things a bit more readable/elegant, but the conversion should work.

edit flag offensive delete link more

Comments

Thank you; I'll check those resources out

zsbhaha gravatar image zsbhaha  ( 2014-05-11 20:47:25 -0600 )edit

Hi, i am trying to use it but facing a problem.

i am processing it by:

rosrun hector_compressed_map_transport map_to_image_node
rosrun image_view image_view image:=/map_image/full _image_transport:=compressed

However imageview dosenot show anything. It is unresponsive sinc

RoboRos gravatar image RoboRos  ( 2018-09-04 05:41:35 -0600 )edit

okey, so it is working with hector slam but not with other 2d slam algorithms due to poseupdate topic.

RoboRos gravatar image RoboRos  ( 2018-09-04 06:24:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-05-11 20:23:25 -0600

Seen: 5,535 times

Last updated: May 12 '14