ON THIS PAGE

  • How to place it
  • Inputs and Outputs
  • Example visualization with Open3D
  • Examples using PointCloud
  • Reference

PointCloud - TODO port to v3

Supported on:RVC2RVC4
The PointCloud node enables on-device point cloud generation from depth map.

How to place it

Python

Python
1pipeline = dai.Pipeline()
2pointCloud = pipeline.create(dai.node.PointCloud)

C++

C++
1dai::Pipeline pipeline;
2auto pointCloud = pipeline.create<dai::node::PointCloud>();

Inputs and Outputs

Example visualization with Open3D

Python

Python
1import open3d as o3d
2import numpy as np
3import depthai as dai
4
5pcd = o3d.geometry.PointCloud()
6vis = o3d.visualization.VisualizerWithKeyCallback()
7vis.create_window()
8
9with dai.Device(pipeline) as device:
10    coordinateFrame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=1000, origin=[0,0,0])
11    vis.add_geometry(coordinateFrame)
12
13    while device.isPipelineRunning():
14        inMessage = q.get()
15        inColor = inMessage["rgb"]
16        inPointCloud = inMessage["pcl"]
17        cvColorFrame = inColor.getCvFrame()
18
19        if inPointCloud:
20            points = inPointCloud.getPoints().astype(np.float64)
21            pcd.points = o3d.utility.Vector3dVector(points)
22            colors = (cvRGBFrame.reshape(-1, 3) / 255.0).astype(np.float64)
23            pcd.colors = o3d.utility.Vector3dVector(colors)
24            vis.update_geometry(pcd)
25
26        vis.poll_events()
27        vis.update_renderer()
28
29    vis.destroy_window()

C++

C++
1#include <iostream>
2#include <open3d/Open3D.h>
3#include <depthai/depthai.hpp>
4
5int main() {
6    auto viewer = std::make_unique<pcl::visualization::PCLVisualizer>("Cloud Viewer");
7    viewer->addPointCloud<pcl::PointXYZ>(cloud, "cloud");
8
9    dai::Device device(pipeline);
10
11    auto q = device.getOutputQueue("out", 8, false);
12    auto qDepth = device.getOutputQueue("depth", 8, false);
13
14    while(true) {
15        std::cout << "Waiting for data" << std::endl;
16        auto depthImg = qDepth->get<dai::ImgFrame>();
17        auto pclMsg = q->get<dai::PointCloudData>();
18
19        if(!pclMsg) {
20            std::cout << "No data" << std::endl;
21            continue;
22        }
23
24        auto frame = depthImg->getCvFrame();
25        frame.convertTo(frame, CV_8UC1, 255 / depth->initialConfig.getMaxDisparity());
26
27        if(pclMsg->getPoints().empty()) {
28            std::cout << "Empty point cloud" << std::endl;
29            continue;
30        }
31
32        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud = pclMsg->getPclData();
33        viewer->updatePointCloud(cloud, "cloud");
34
35        viewer->spinOnce(10);
36
37        if(viewer->wasStopped()) {
38            break;
39        }
40    }
41}

Examples using PointCloud

Reference

Python

class

dai::node::PointCloud

#include PointCloud.hpp
variable
std::shared_ptr< PointCloudConfig > initialConfig
Initial config to use when computing the point cloud.
variable
Input inputConfig
Input PointCloudConfig message with ability to modify parameters in runtime. Default queue is non-blocking with size 4.
variable
Subnode< node::Sync > sync
Sync subnode for synchronized depth + color input. When only depth is connected, Sync passes through single-item MessageGroups. When both depth and color are connected, Sync pairs them by timestamp.
variable
InputMap & syncInputs
variable
Input & inputDepth
Input message with depth data used to create the point cloud. Routed through the internal Sync subnode.
variable
Output outputPointCloud
Outputs PointCloudData message
variable
Output passthroughDepth
Passthrough depth from which the point cloud was calculated. Suitable for when input queue is set to non-blocking behavior.
function
PointCloud()
function
~PointCloud()
function
Input & getColorInput()
Get the optional color input for colorized point clouds. Lazily creates the Sync entry so that depth-only mode works without Sync waiting for a color frame that never arrives.Link an aligned color image (RGB888i, same dimensions as depth) to this input to enable colored point cloud output.
function
void setNumFramesPool(int numFramesPool)
Specify number of frames in pool.
Parameters
  • numFramesPool: How many frames should the pool have
function
void setRunOnHost(bool runOnHost)
Specify whether to run on host or device By default, the node will run on host.
function
void useCPU()
Use single-threaded CPU for processing
function
void useCPUMT(uint32_t numThreads)
Use multi-threaded CPU for processing
function
void useGPU(uint32_t device)
Use GPU for point cloud computation
Parameters
  • device: GPU device index (default 0)
function
void setTargetCoordinateSystem(CameraBoardSocket targetCamera, bool useSpecTranslation)
Set target coordinate system to transform point cloud
Parameters
  • targetCamera: Target camera socket
  • useSpecTranslation: Use spec translation instead of calibration (default: false)
function
void setTargetCoordinateSystem(HousingCoordinateSystem housingCS, bool useSpecTranslation)
Set target coordinate system to housing coordinate system Point cloud will be transformed to this housing coordinate system
Parameters
  • housingCS: Target housing coordinate system
  • useSpecTranslation: Whether to use spec translation (default: true)
function
bool runOnHost()
function
void buildInternal()
class

dai::node::PointCloud::Impl

variable
LengthUnit targetLengthUnit
function
Impl()
function
void setLogger(std::shared_ptr<::spdlog::logger > log)
function
void computePointCloudDense(const uint8_t * depthData, std::vector< Point3f > & points)
function
void computePointCloudDenseColored(const uint8_t * depthData, const uint8_t * colorData, std::vector< Point3fRGBA > & points)
function
void applyTransformation(std::vector< PointT > & points)
function
std::vector< PointT > filterValidPoints(const std::vector< PointT > & densePoints)
function
void setLengthUnit(dai::LengthUnit lengthUnit)
function
void useCPU()
function
void useCPUMT(uint32_t numThreads)
function
void useGPU(uint32_t device)
function
void setIntrinsics(float fx, float fy, float cx, float cy, unsigned int width, unsigned int height)
function
void setExtrinsics(const std::vector< std::vector< float >> & transformMatrix)
function
void clearExtrinsics()

C++

class

dai::node::PointCloud

#include PointCloud.hpp
variable
std::shared_ptr< PointCloudConfig > initialConfig
Initial config to use when computing the point cloud.
variable
Input inputConfig
Input PointCloudConfig message with ability to modify parameters in runtime. Default queue is non-blocking with size 4.
variable
Subnode< node::Sync > sync
Sync subnode for synchronized depth + color input. When only depth is connected, Sync passes through single-item MessageGroups. When both depth and color are connected, Sync pairs them by timestamp.
variable
InputMap & syncInputs
variable
Input & inputDepth
Input message with depth data used to create the point cloud. Routed through the internal Sync subnode.
variable
Output outputPointCloud
Outputs PointCloudData message
variable
Output passthroughDepth
Passthrough depth from which the point cloud was calculated. Suitable for when input queue is set to non-blocking behavior.
function
PointCloud()
function
~PointCloud()
function
Input & getColorInput()
Get the optional color input for colorized point clouds. Lazily creates the Sync entry so that depth-only mode works without Sync waiting for a color frame that never arrives.Link an aligned color image (RGB888i, same dimensions as depth) to this input to enable colored point cloud output.
function
void setNumFramesPool(int numFramesPool)
Specify number of frames in pool.
Parameters
  • numFramesPool: How many frames should the pool have
function
void setRunOnHost(bool runOnHost)
Specify whether to run on host or device By default, the node will run on host.
function
void useCPU()
Use single-threaded CPU for processing
function
void useCPUMT(uint32_t numThreads)
Use multi-threaded CPU for processing
function
void useGPU(uint32_t device)
Use GPU for point cloud computation
Parameters
  • device: GPU device index (default 0)
function
void setTargetCoordinateSystem(CameraBoardSocket targetCamera, bool useSpecTranslation)
Set target coordinate system to transform point cloud
Parameters
  • targetCamera: Target camera socket
  • useSpecTranslation: Use spec translation instead of calibration (default: false)
function
void setTargetCoordinateSystem(HousingCoordinateSystem housingCS, bool useSpecTranslation)
Set target coordinate system to housing coordinate system Point cloud will be transformed to this housing coordinate system
Parameters
  • housingCS: Target housing coordinate system
  • useSpecTranslation: Whether to use spec translation (default: true)
function
bool runOnHost()
function
void buildInternal()
class

dai::node::PointCloud::Impl

variable
LengthUnit targetLengthUnit
function
Impl()
function
void setLogger(std::shared_ptr<::spdlog::logger > log)
function
void computePointCloudDense(const uint8_t * depthData, std::vector< Point3f > & points)
function
void computePointCloudDenseColored(const uint8_t * depthData, const uint8_t * colorData, std::vector< Point3fRGBA > & points)
function
void applyTransformation(std::vector< PointT > & points)
function
std::vector< PointT > filterValidPoints(const std::vector< PointT > & densePoints)
function
void setLengthUnit(dai::LengthUnit lengthUnit)
function
void useCPU()
function
void useCPUMT(uint32_t numThreads)
function
void useGPU(uint32_t device)
function
void setIntrinsics(float fx, float fy, float cx, float cy, unsigned int width, unsigned int height)
function
void setExtrinsics(const std::vector< std::vector< float >> & transformMatrix)
function
void clearExtrinsics()

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.