Ask Your Question

[SOLVED] rviz not showing 16 bits-per-pixel, single channel depth images

asked 2019-01-21 17:08:29 -0500

Avner gravatar image

updated 2019-01-29 18:12:15 -0500


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 (verifying 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.

In rviz I can view the rgb image, but I cannot view the depth image.

rviz issues an error message:

[ WARN] [1548110467.614542827]: OGRE EXCEPTION(2:InvalidParametersException): Stream size does not match calculated image size in Image::loadRawData at /build/ogre-1.9-B6QkmW/ogre-1.9-1.9.0+dfsg1/OgreMain/src/OgreImage.cpp (line 283)
[ERROR] [1548110467.614620078]: Error loading image: OGRE EXCEPTION(2:InvalidParametersException): Stream size does not match calculated image size in Image::loadRawData at /build/ogre-1.9-B6QkmW/ogre-1.9-1.9.0+dfsg1/OgreMain/src/OgreImage.cpp (line 283)

The transport Hint in rviz is set to "raw" and I cannot change it.



edit retag flag offensive close merge delete


I would actually recommend to post your edit1 as an answer and then accept your own answer (by clicking the checkmark to the left of it).

That would much more clearly show that your question was answered.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-24 13:23:04 -0500 )edit

Done. Thanks for your comment.

Avner gravatar image Avner  ( 2019-01-29 18:13:35 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2019-01-29 18:11:47 -0500

Avner gravatar image

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

im_depth = cv2.imread(depth_img, -1)
bridge = CvBridge()
# passthrough honors the original image encoding (mono16)
image_message = bridge.cv2_to_imgmsg(im_depth, encoding="passthrough")
image_message.header.stamp = Stamp
image_message.header.frame_id = "camera"
bag.write('camera/depth/image', image_message, Stamp)

After doing this, I can see the depth image in rviz.

p.s. as a sanity test, I extracted the files from the the bag and verified that they are actual 16 bit images (image type is 16 bit and pixel values are greater than 255)

I used the solution to execute rtabmap on a bag with rgb and 16 bit depth images. See here

edit flag offensive delete link more

answered 2019-01-21 17:33:47 -0500

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

There are various ways to do this. A simple method is to normalise the depth image to the range 0-255 and changed to an 8 bit image. Or a more meaningful conversion would be adding a color bar and scale.

edit flag offensive delete link more


Thanks for your answer. After using cv_bridge to add the 16 bit depth image into the bag, I can now see it in rviz without any special further adjustments. Does this mean that actually, rviz can handle 16 bit images? (maybe it does scale it down internally to 8 bit per pixel)

Avner gravatar image Avner  ( 2019-01-22 12:46:05 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2019-01-21 17:08:29 -0500

Seen: 648 times

Last updated: Jan 29 '19