DepthAI
  • DepthAI组件
    • AprilTags
    • 基准测试
    • 相机
    • 校准
    • DetectionNetwork
    • 事件
    • FeatureTracker
    • HostNodes
    • ImageAlign
    • ImageManip
    • IMU
    • 杂项
    • 模型库
    • NeuralDepth
    • NeuralNetwork
    • ObjectTracker
    • 点云
    • RecordReplay
    • RGBD
    • 脚本
    • SpatialDetectionNetwork
    • SpatialLocationCalculator
    • StereoDepth
    • 同步
    • VideoEncoder
    • 可视化器
    • VSLAM
    • 扭曲
    • RVC2 特有
  • 高级教程
  • API 参考
  • 工具
软件栈

本页目录

  • 源代码

PointCloud

Supported on:RVC2RVC4
使用 PointCloud 节点从立体深度和对齐的 RGB 相机创建彩色点云的最小示例。将点云数量、尺寸和深度范围输出到控制台。这个示例需要DepthAI v3 API,参见安装说明

源代码

Python

Python
GitHub
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
9colorSockets = pipeline.getDefaultDevice().getConnectedCameras(dai.CameraSensorType.COLOR)
10colorSocket = colorSockets[0] if colorSockets else dai.CameraBoardSocket.CAM_A
11color = pipeline.create(dai.node.Camera).build(colorSocket)
12
13# Color output aligned to depth
14colorOut = color.requestOutput((640, 400), type=dai.ImgFrame.Type.RGB888i,
15                               resizeMode=dai.ImgResizeMode.CROP, enableUndistortion=True)
16
17depth = pipeline.create(dai.node.Depth).build(dai.node.Depth.Algorithm.AUTO, None, (640, 400))
18depth.setAlignTo(colorOut)
19
20# Point cloud
21pc = pipeline.create(dai.node.PointCloud)
22pc.initialConfig.setLengthUnit(dai.LengthUnit.METER)
23
24depth.depth.link(pc.inputDepth)
25colorOut.link(pc.inputColor)
26
27q = pc.outputPointCloud.createOutputQueue(maxSize=4, blocking=False)
28
29with pipeline:
30    pipeline.start()
31    while pipeline.isRunning():
32        pcd = q.get()
33        if pcd.isColor():
34            xyz, rgba = pcd.getPointsRGB()
35            numPoints = len(xyz)
36        else:
37            xyz = pcd.getPoints()
38            numPoints = len(xyz)
39        print(f"Points: {numPoints}, {pcd.getWidth()}x{pcd.getHeight()}, "
40              f"color={pcd.isColor()}, Z=[{pcd.getMinZ():.2f}, {pcd.getMaxZ():.2f}]")

C++

1// Minimal PointCloud example: colorized point cloud from stereo depth + RGB.
2#include <iostream>
3
4#include "depthai/depthai.hpp"
5
6int main() {
7    dai::Pipeline pipeline;
8
9    // Cameras
10    auto colorSockets = pipeline.getDefaultDevice()->getConnectedCameras(dai::CameraSensorType::COLOR);
11    auto colorSocket = colorSockets.empty() ? dai::CameraBoardSocket::CAM_A : colorSockets.front();
12    auto color = pipeline.create<dai::node::Camera>()->build(colorSocket);
13
14    // Color output aligned to depth
15    auto colorOut = color->requestOutput(std::make_pair(640, 400), dai::ImgFrame::Type::RGB888i, dai::ImgResizeMode::CROP, std::nullopt, true);
16
17    auto depth = pipeline.create<dai::node::Depth>();
18    depth->build(dai::node::Depth::Algorithm::AUTO, std::nullopt, std::make_pair(640u, 400u));
19    depth->setAlignTo(*colorOut);
20
21    // Point cloud
22    auto pc = pipeline.create<dai::node::PointCloud>();
23    pc->initialConfig->setLengthUnit(dai::LengthUnit::METER);
24
25    depth->depth().link(pc->inputDepth);
26    colorOut->link(pc->getColorInput());
27
28    auto q = pc->outputPointCloud.createOutputQueue(4, false);
29
30    pipeline.start();
31    while(pipeline.isRunning()) {
32        auto pcd = q->get<dai::PointCloudData>();
33        if(pcd->isColor()) {
34            auto points = pcd->getPointsRGB();
35            std::cout << "Points: " << points.size();
36        } else {
37            auto points = pcd->getPoints();
38            std::cout << "Points: " << points.size();
39        }
40        std::cout << ", " << pcd->getWidth() << "x" << pcd->getHeight() << ", color=" << (pcd->isColor() ? "yes" : "no") << ", Z=[" << pcd->getMinZ() << ", "
41                  << pcd->getMaxZ() << "]" << std::endl;
42    }
43    pipeline.stop();
44    return 0;
45}

需要帮助?

请前往 OAKChina 官网 获取技术支持或解答您的任何疑问。