默认在主机上运行。在RVC4上,可以通过
setRunOnHost(False)将其卸载到设备。在RVC2上,仅支持主机端处理。在DepthAI v3.6.0中新增。放置方式
Python
Python
1import depthai as dai
2
3with dai.Pipeline() as pipeline:
4 pointCloud = pipeline.create(dai.node.PointCloud)输入与输出
passthroughDepth 转发用于计算给定 PointCloudData 输出的原始深度帧。当输入队列为非阻塞且需要将深度帧与其对应的点云关联时非常有用。配置
initialConfig 设置,或在运行时通过 inputConfig 发送。在流中发送新配置是安全的——当配置、标定或帧变换发生变化时,节点会自动重新初始化。有关详细描述和使 用示例,请参阅PointCloudConfig。Python
Python
1pc = pipeline.create(dai.node.PointCloud)
2pc.initialConfig.setOrganized(True)
3pc.initialConfig.setLengthUnit(dai.LengthUnit.METER)
4pc.initialConfig.setTargetCoordinateSystem(dai.CameraBoardSocket.CAM_A)
5pc.setNumFramesPool(8)坐标系
ImgTransformation 外参中读取 T_frame_to_ref 并应用它,因此输出点云位于参考(原点)相机坐标系中。此外,您可以应用以下三种额外变换之一:1. 相机接口坐标系
CameraBoardSocket.CAM_A)。原点位于相机传感器处,旋转遵循相机的光学帧。节点利用设备标定自动计算外参变换。Python
1# 点云在彩色相机(CAM_A)的坐标系中
2pc.initialConfig.setTargetCoordinateSystem(dai.CameraBoardSocket.CAM_A)2. 外壳坐标系
Python
1# 点云在VESA安装坐标系中
2pc.initialConfig.setTargetCoordinateSystem(dai.HousingCoordinateSystem.VESA_A)HousingCoordinateSystem.CAM_A–CAM_D— 原点与CameraBoardSocket.CAM_A–CAM_D相同。区别在于旋转:X-Y平面与设备前玻璃平行,而相机接口坐标系旋转到相机的光学帧。HousingCoordinateSystem.FRONT_CAM_A–FRONT_CAM_D— 定位与HousingCoordinateSystem.CAM_A–CAM_D类似,但向前移动至前玻璃的前侧。HousingCoordinateSystem.VESA_A–VESA_J— 设备安装点。HousingCoordinateSystem.IMU— IMU传感器原点。
3. 自定义变换矩阵
T_ref_to_custom的任意4×4变换矩阵——从参考相机到自定义坐标系的变换。节点将其与帧外参组合,得到最终应用的变换:Python
1# 绕 Z 轴旋转 90°
2transform = [
3 [0.0, -1.0, 0.0, 0.0],
4 [1.0, 0.0, 0.0, 0.0],
5 [0.0, 0.0, 1.0, 0.0],
6 [0.0, 0.0, 0.0, 1.0],
7]
8pc.initialConfig.setTransformationMatrix(transform)T_frame_to_ref),将点云转换至参考相机坐标系。选项间的交互
CAMERA_SOCKET 或 HOUSING —— 在这些模式下,setTransformationMatrix 设置的自定义变换矩阵被忽略。仅当坐标系类型为 DEFAULT(即未调用任一 setTargetCoordinateSystem 重载)时,才会使用自定义矩阵。所有三种方法也可以直接在节点上调用(会转发到 initialConfig):Python
1pc.setTargetCoordinateSystem(dai.CameraBoardSocket.CAM_A)
2# 或
3pc.setTargetCoordinateSystem(dai.HousingCoordinateSystem.VESA_A)用法
从立体深度生成点云
Python
Python
1import depthai as dai
2
3pipeline = dai.Pipeline()
4
5left = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
6right = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
7stereo = pipeline.create(dai.node.StereoDepth)
8left.requestOutput((640, 400)).link(stereo.left)
9right.requestOutput((640, 400)).link(stereo.right)
10
11pc = pipeline.create(dai.node.PointCloud)
12pc.initialConfig.setLengthUnit(dai.LengthUnit.METER)
13stereo.depth.link(pc.inputDepth)
14
15q = pc.outputPointCloud.createOutputQueue(maxSize=4, blocking=False)
16
17with pipeline:
18 pipeline.start()
19 while pipeline.isRunning():
20 pclData = q.get()
21 points = pclData.getPoints() # np.ndarray (N, 3) float32
22 print(f"点数: {len(points)}, Z=[{pclData.getMinZ():.2f}, {pclData.getMaxZ():.2f}]")彩色点云
Python
Python
1import depthai as dai
2
3pipeline = dai.Pipeline()
4
5left = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
6right = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
7color = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
8
9stereo = pipeline.create(dai.node.StereoDepth)
10left.requestFullResolutionOutput().link(stereo.left)
11right.requestFullResolutionOutput().link(stereo.right)
12
13colorOut = color.requestOutput((640, 400), type=dai.ImgFrame.Type.RGB888i,
14 resizeMode=dai.ImgResizeMode.CROP, enableUndistortion=True)
15
16pc = pipeline.create(dai.node.PointCloud)
17pc.initialConfig.setLengthUnit(dai.LengthUnit.METER)
18
19# 将深度图对齐到彩色相机
20platform = pipeline.getDefaultDevice().getPlatform()
21if platform == dai.Platform.RVC4:
22 imageAlign = pipeline.create(dai.node.ImageAlign)
23 stereo.depth.link(imageAlign.input)
24 colorOut.link(imageAlign.inputAlignTo)
25 imageAlign.outputAligned.link(pc.inputDepth)
26else:
27 colorOut.link(stereo.inputAlignTo)
28 stereo.depth.link(pc.inputDepth)
29
30colorOut.link(pc.inputColor)
31
32q = pc.outputPointCloud.createOutputQueue(maxSize=4, blocking=False)
33
34with pipeline:
35 pipeline.start()
36 while pipeline.isRunning():
37 pcd = q.get()
38 if pcd.isColor():
39 xyz, rgba = pcd.getPointsRGB()
40 print(f"点数: {len(xyz)}, color=yes, Z=[{pcd.getMinZ():.2f}, {pcd.getMaxZ():.2f}]")Examples
- PointCloud — 最小化彩色点云示例。
- PointCloud Visualizer — 使用Open3D的实时3D可视化。
- PointCloud Showcase — 演示过滤、组织、坐标变换、自定义矩阵和彩色模式。
Reference
class
dai::node::PointCloud
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
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
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(std::unique_ptr< Properties > props)function
~PointCloud()function
Input & getColorInput()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)Set target coordinate system to transform point cloud
Parameters
- targetCamera: Target camera socket
function
void setTargetCoordinateSystem(HousingCoordinateSystem housingCS)Set target coordinate system to housing coordinate system Point cloud will be transformed to this housing coordinate system
Parameters
- housingCS: Target housing coordinate system
function
void setTargetCoordinateSystem(CameraBoardSocket targetCamera, bool useSpecTranslation)Deprecated: use setTargetCoordinateSystem(targetCamera) instead.
function
void setTargetCoordinateSystem(HousingCoordinateSystem housingCS, bool useSpecTranslation)Deprecated: use setTargetCoordinateSystem(housingCS) instead.
function
bool runOnHost()function
void buildInternal()class
dai::node::PointCloud::Impl
variable
LengthUnit targetLengthUnit
function
Impl()function
void setLogger(const 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()需要帮助?
请前往 OAKChina 官网 获取技术支持或解答您的任何疑问。