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

Decode compressedDepth message from compressed_depth_image_transport

asked 2016-11-07 17:08:44 -0500

gariepya gravatar image

Hi,

I am using the compressed_depth_image_transport to compress a Kinect depth image before letting it go through rosbridge (the client won't have ROS or opencv installed, only pip-installed libs). The image is float32 compressed in png.

On the client, I receive the image encoded in base64 by rosbridge. After decoding the base64 string, what I have is bytes that are supposed to be the compressed image. However, I cannot figure out the format of the image. For instance, if I wrtite directly the bytes to a ".png" file, I cannot open it using an image viewer. I also get exceptions if I try to load the bytes using Pillow, pypng, scipy, etc.

How does compressed_depth_image_transport works? I have seen in the source code that it uses cv::imencode, does it produce a valid png file content as I expect?

Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-11-07 19:15:34 -0500

gariepya gravatar image

I managed to make it work.

According to this source file the encoder puts a header at the beginning of the file. According to libpng, the first bytes of any png are 89 50 4e 47 0d 0a 1a 0a. By inspection, I found that the first 12 bytes are the header of compressed_depth_image_transport and the rest is a valid png file.

edit flag offensive delete link more

Comments

Nice one. Thanks for reporting back.

gvdhoorn gravatar image gvdhoorn  ( 2016-11-08 02:09:41 -0500 )edit

Thank you so much gariepya! Removing these first 12 bytes is the solution to the problem with which I honestly wasted days of precious working time.

Martin Bischoff gravatar image Martin Bischoff  ( 2017-02-15 05:36:32 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-07 17:08:44 -0500

Seen: 780 times

Last updated: Nov 07 '16