Article ID: 000027169 Content Type: Troubleshooting Last Reviewed: 08/06/2021

How to Get Point Cloud of Intel® RealSense™ Cameras in C#

Environment

Intel® RealSense™ Depth Camera D435 Intel® RealSense™ Depth Camera D415

BUILT IN - ARTICLE INTRO SECOND COMPONENT
Summary

Converting Intel RealSense point cloud to PCL point cloud from Intel® RealSense™ Depth Cameras

Description

I want to convert the point cloud data from Intel® RealSense™ Camera to PCD format, which is conventional in PCL (point cloud library)

Resolution

The Intel® RealSense™ SDK 2.0 comes with a point cloud sample program but it is intended for C++, as are the majority of samples.  Looking at the code of the small number of C# samples, though, their scripts have the #includes in the headers (something that is not mandatory in C#).  So it is possible that the C++ point cloud code may not be difficult to convert to a C# script.
 
Try the C++ code in a C# script and see how many errors, if any, you get, and work from that point onwards.
 
librealsense/examples/pointcloud at master · IntelRealSense/librealsense · GitHub
 
For comparison of C++ code versus C# in the RealSense SDK 2.0, you can see the two types of sample listed on this page:
 
librealsense/examples at master · IntelRealSense/librealsense · GitHub
 
An option to do for now until the PointCloud class is wrapped up for C# is to obtain the camera intrinsics (for the depth camera if using the raw depth, or color camera if using depth aligned to color) and implement the Pinhole Camera Model (which is what the PointCloud class does internally). From the intrinsics you get from the camera, ppx & ppy are camera_principle_point_x and y in the link and fx & fy are camera_focal_length_x and y.
 
You need to loop through each pixel in the depth image, obtain the depth value (most efficient is through the depth data pointer), multiply it by the depth scale, and apply the x_3D and y_3D formulae given in the link.
 
In case anyone reads this and gets confused, C# is (mostly) supported currently.

The method used internally to calculate the point cloud is here.

PCL wrapper for Intel RealSense supporting XYZ + RGB conversion
https://github.com/eMrazSVK/JetsonSLAM/blob/master/pcl_testing.cpp

Related Products

This article applies to 1 products