Source code
Python
PythonGitHub
1#!/usr/bin/env python3
2"""Minimal PointCloud example: colorized point cloud from stereo depth + RGB."""
3
4import depthai as dai
5
6pipeline = dai.Pipeline()
7
8# Cameras
9left = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
10right = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
11color = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
12
13# Stereo depth
14stereo = pipeline.create(dai.node.StereoDepth)
15left.requestFullResolutionOutput().link(stereo.left)
16right.requestFullResolutionOutput().link(stereo.right)
17
18# Color output aligned to depth
19colorOut = color.requestOutput((640, 400), type=dai.ImgFrame.Type.RGB888i,
20 resizeMode=dai.ImgResizeMode.CROP, enableUndistortion=True)
21
22# Point cloud
23pc = pipeline.create(dai.node.PointCloud)
24pc.initialConfig.setLengthUnit(dai.LengthUnit.METER)
25
26# Align depth to color on RVC4
27platform = pipeline.getDefaultDevice().getPlatform()
28if platform == dai.Platform.RVC4:
29 imageAlign = pipeline.create(dai.node.ImageAlign)
30 stereo.depth.link(imageAlign.input)
31 colorOut.link(imageAlign.inputAlignTo)
32 imageAlign.outputAligned.link(pc.inputDepth)
33else:
34 colorOut.link(stereo.inputAlignTo)
35 stereo.depth.link(pc.inputDepth)
36
37colorOut.link(pc.inputColor)
38
39q = pc.outputPointCloud.createOutputQueue(maxSize=4, blocking=False)
40
41with pipeline:
42 pipeline.start()
43 while pipeline.isRunning():
44 pcd = q.get()
45 if pcd.isColor():
46 xyz, rgba = pcd.getPointsRGB()
47 numPoints = len(xyz)
48 else:
49 xyz = pcd.getPoints()
50 numPoints = len(xyz)
51 print(f"Points: {numPoints}, {pcd.getWidth()}x{pcd.getHeight()}, "
52 f"color={pcd.isColor()}, Z=[{pcd.getMinZ():.2f}, {pcd.getMaxZ():.2f}]")Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.