PCD Writer for Kinect Fusion

What is PCD?

PCD (Point Cloud Data) is file format for storing Point Cloud data.
It is mainly supposed to uses with PCL.

What are the advantages over other file formats?

The some general 3DCG formats that supporte Point Cloud data is already exists.
But, Those formats were not optimized for Point Cloud data.

The main PCD format advantages that written in this tutorial are as follows.

  • Support the Organized Point Cloud Data
  • The Organized Point Cloud data indicates Point Cloud retrieved from sensors like stereo camera, ToF camera.
    It is the Point Cloud data that resemble an organized image (or matrix) like structure.
    It is very easily to access nearest points.

  • Flexible and Efficient to the Point Cloud Data
  • It can store values of various primitive types.
    Therefore, It is possible to read and write flexibly and efficiently Point Cloud data.

  • Best Adapt Data Format to PCL
  • PCD is natively supported by PCL.
    Therefore, It is no delay due to internal conversion processing unlike other formats.

  • Support N-dimension Histograms
  • Supports N-dimensional histogram for feature descriptor.

PCD File Format

The PCD file consists of the following header and data.
The header has the following information.(e.g.)

  • VERSION
  • PCD file format version (0.7)

  • FIELDS
  • specifies the each fields data format that point can have (x y z rgb)

  • SIZE
  • specifies the each fields data size in bytes (4 4 4 4)

  • TYPE
  • specifies the each fields data type (F F F I)

  • COUNT
  • specifies the each fields data counts (1 1 1 1)

  • WIDTH
  • width (Vertices Count)

  • HEIGHT
  • height (1)

  • VIEWPOINT
  • view point (0 0 0 1 0 0 0)

  • POINTS
  • points count (Vertices Count)

  • DATA
  • file format (ascii or binary)

The data is written in under the header.
The data is described in one line at a single point.

VERSION 0.7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F F F I
COUNT 1 1 1 1
WIDTH n
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS n
DATA ascii
x y z rgb
x y z rgb
x y z rgb
...
x y z rgb

PCD Writer for Kinect Fusion

Three-dimensional shape data reconstructed with Kinect Fusion can be written out to a file such as PLY by using KinectFusionHelper.
But, It is supported only general formats.

Therefore, I implemented PCD Writer which directly writes vertex data to PCD file.
PCD Writer has published following.

Basic Usage PCD Write

I will introduce the basic usage of PCD Writer.

Include

Please include pcd_writer.h.

#include "pcd_writer.h"

Retrieve Mesh Data

You will retrieve mesh data from volume data that recontruct by Kinect Fusion.

The sampling step affects the detail and size of the Point Cloud data.
The small step value will keep fine details, but the vertices count increases. Therefore, The file size also large.
The big step value will vertices count decrease. Therefore, The file size also small. But, It can not keep fine details.

It takes time to read and write files when vertices count is large.
Please take note, Kinect Fusion data is very dense and has many vertices.

// Calculate Mesh Data
const UINT step = 1;
ComPtr<INuiFusionColorMesh> mesh;
ERROR_CHECK( reconstruction->CalculateMesh( step, &mesh ) );

Write PCD File

Then, You write vertex data to PCD file.
It can specify whether to horizontally flip the data in 3rd argument.
And, It can specify whether to store color information in 4th argument.
You can check whether the export succeeded using return value.

// Write PCD File ( ASCII )
const std::string filename = "../ascii_file.pcd";
HRESULT ret = WriteAsciiPcdFile( mesh.Get(), filename, true, true );
if( FAILED( ret ) ){
    return -1;
}

// Write PCD File ( Binary )
const std::string filename = "../binary_file.pcd";
HRESULT ret = WriteBinaryPcdFile( mesh.Get(), filename, true, true );
if( FAILED( ret ) ){
    return -1;
}

Verify PCD File

Let’s check with the viewer software whether PCD file was successfully exported or not.
You can display the data of PCD file by using these software.

  • pcl_viewer
  • pcl_viewer is viewer application included in PCL.
    If you installed PCL using All-in-one Installer, It will be installed with library. (<PCL_ROOT>binpcl_viewer_release.exe)

  • CloudCompare
  • CloudCompare is free software with functions such as display and editing for Point Cloud data.


Leave a Reply

Your email address will not be published. Required fields are marked *