How to convert png pair of RGB and Depth frames into Pointcloud library PCD format

There are a lot of accessible dataset of RGB-D data:

But usually it stored in PNG format and unfortunately Pointcloud library do not provide built-in function neither for treating it as a PointCloud nor for conversion it to PCD. For my experiments I need to test few points using data with ground truth estimation, thats why I have to code small utility for conversion purpose.

Due to sudden leisure I decided to share that peace of code – probably you can find it useful.

From readme:

png2pcd_batch – simple command line utility to convert depth and rgb frames
from png format to PCL pointcloud.

There are 2 execution mode:
using file with association information i.e. containing rgb-depth png files correspondence
or just providing folders that contain depth and rgb frames ( not reccommended ).

In 1st case you should anyhow create associate file by yourself
(for further details check description of parse_freiburg function)
In 2nd case – correspondence strictly depends on file names, and you should check it twice,
to avoid situation when selected depth frame is not appropriate for rgb frame.
( add sorting to filenames vector using custom predicate )

All dataset related parameters are incapsulated in Intr structure ( intrinsics ).
There are: width, height, fx, fy, cx, cy, scale_factor.
Usually depth data is saved as unsigned short ( 16 bit ),
but in pcl::PointXYZ you have to re-scale it to float – metric measurment.

Appropriate intrinsics should be written to file cam_params.cfg otherwise
default values will be used ( which may lead to invalid output data ).

There are exist two opportunity for compiling:

using classical make:
edit WORK_DIR in Makefile to point in directory contained pcl-trunk & opencv
it produce more lightweighted version by avoiding linkage with unnecessary libraries

or using cmake:

mkdir build; cd build
cmake ..

NOTE 1: There are only two dependencies:
PCL and OpenCV.
NOTE 2: in case of builded-but-not-properly-installed OpenCV libraries you have to
manually create symlink to ipp lib:
sudo ln -s /path-to-opencv/3rdparty/ippicv/unpack/ippicv_lnx/lib/intel64/libippicv.a /usr/lib/libippicv.a

Note 3: it have built-in support for 16bit unsigned depth and 3-channel RGB data only, in case your data has another format you have to change code a bit
Note 4: do not forget to provide appropriate intrinsics for proper calculation of XYZ vertex


Skip to comment form

    • João on September 27, 2016 at 3:28 pm
    • Reply


    First of all, thank you very much for making this script available. I was writing my own script (which wasn’t working properly) to do this conversion when i found yours, i just have some questions if that’s ok.

    Why do you create a RGB cloud, then a XYZ cloud and merge them in a XYZRGBA, why not create a single XYZRGBA cloud?

    And why is it necessary to use a XYZRGBA instead of XYZRGB? Do 16 bit 3 Channel png files also have an alpha?

    Thanks in advance.

      • admin on September 29, 2016 at 12:24 am
      • Reply

      Hello João,

      that a good question – frankly speaking now I can’t remember exact reason.

      >> why not create a single XYZRGBA cloud?
      Probably I can’t find at that time (2014) routine at PCL that provide such interface to do it at once.

      >> XYZRGBA
      That is simple – I had some routine to play with XYZRGBA cloud – it was just to re-use the same routine, no other reason.

    • Mudrika Hindi on October 20, 2016 at 8:16 am
    • Reply

    Hello Admin

    Can you please explain a little clearly the above script to convert rgb-d+depth to corresponding pcd files

    1. Mudrika,

      This is source file with complete solution:

      basically, you should have pair of files corresponding to RGB & Depth and associtation file, that describe paring RGB to Depth.

      Additionally, you may need to edit intrinsics to fit your camera.

        • Mudrika Hindi on October 22, 2016 at 5:12 pm
        • Reply

        Let.s make it a little simpler .
        i have a rgb-d image . I need to convert it to corresponding pcd file and then display this image from the pcd file .
        How to do that ?

        1. You need to have:
          pcl libraries & headers,
          opencv libraries & headers,
          g++ compiler.

          1) git clone for project above
          2) edit makefile to set path to PCL & opencv
          3) build this project

          after that you can use resulting executable ti convert rgb & depth images to insgle pcd file.

    • Mudrika Hindi on October 22, 2016 at 5:10 pm
    • Reply

    Thanks a lot admin .

    but the problem is that your script is not running in my machine environment . Actually this is a part of my engineering project . Can you please help me a little more
    Email :

Leave a Reply

Your email address will not be published.