Ask Your Question
0

Decode compressedDepth message from compressed_depth_image_transport

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

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
2

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

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 imagegvdhoorn ( 2016-11-08 02:09:41 -0600 )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 imageMartin Bischoff ( 2017-02-15 05:36:32 -0600 )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

1 follower

Stats

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

Seen: 259 times

Last updated: Nov 07 '16