Rosanswers logo


I am playing a bag of 16 bits-per-pixel depth and 8 bit rgb images. While playing the bag, I can extract both the rgb and the depth images into files (to verify that the data is ok) (I used the thread here to create and extract the depth images)

The way the depth image is stored in the bag is by using a python script that uses the PIL package to read a pgm image from file into a PIL object, serialize the object data into byte array (using io.BytesIO()), and save the byte array in PPM format.

To verify the data, I wanted to view the images first, before running rtabmap In rviz I can view the rgb image, but I cannot view the depth image. According to here:

"RVIZ cannot view 16 bit images natively. You'll have to convert them to an 8 bit format."

So I assume that the images are correct and move on to use rtabmap I launch rtabmap using the launch file below:

roslaunch ~/avner/PGR/vision/trunk/ros/catkin_ws/src/bpc_slam_rtabmap/launch/rgbd_slam.rgbd_dataset4.launch

But I cannot see the 3D map in rviz, and I do see error messages from rgbd_odometry

BEG getCvType
terminate called after throwing an instance of 'cv_bridge::Exception'
  what():  Image is wrongly formed: height * step != size  or  385 * 1280 != 492817

The depth file is stored the bag in PPM format. The data payload is 492800 (6402385)

  • width: 640
  • height: 385
  • bytes per pixel 2
  • step size 640*2 = 1280

The size of the file is 492817, due to the header payload

So actually, the details in the error message are correct ("height*step" should not be equal to "size") Can someone tell me what am I doing wrong and how to satisfy rgbd_odometry?



Originally posted by Avner on ROS Answers with karma: 96 on 2019-01-21

Post score: 0

Original comments

Comment by matlabbe on 2019-01-22:
Looking at http://docs.ros.org/jade/api/cv_bridge/html/c++/cv__bridge_8cpp_source.html, the data in sensor_msgs::Image topic should not include the header.


1 Answer 1


Rosanswers logo

I solved the problem by changing the way that the depth image is stored in the bag in the python script, to use cv_bridge instead of using the PIL.

After using cv_bridge to store the image without the header, rgbd_odometry does not abort anymore

See here for more details

Originally posted by Avner with karma: 96 on 2019-01-24

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.