此页面由 AI 自动翻译。查看英文原版
DepthAI
  • DepthAI 组件
    • AprilTags
    • 基准测试
    • Camera
    • 校准
    • DetectionNetwork
    • Events
    • FeatureTracker
    • Gate
    • HostNodes
    • ImageAlign
    • ImageManip
    • IMU
    • 杂项
    • 模型动物园
    • NeuralDepth
    • NeuralNetwork
    • ObjectTracker
    • 点云
    • RecordReplay
    • RGBD
    • Script
    • SpatialDetectionNetwork
    • SpatialLocationCalculator
    • StereoDepth
    • Sync
    • VideoEncoder
    • Visualizer
    • Warp
    • RVC2-specific
  • 高级教程
  • API 参考
  • 工具
软件栈

本页目录

  • 管道
  • 源代码

整体回放

Supported on:RVC2RVC4
此示例演示了如何回放先前记录的整体数据,将多个同步流(如视频和 IMU)重新馈送到 DepthAI 管道以进行测试和开发。此示例需要 DepthAI v3 API,请参阅 安装说明

管道

源代码

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5import argparse
6
7parser = argparse.ArgumentParser()
8parser.add_argument("-s", "--source", default="recordings/recording.tar", help="Recording path")
9args = parser.parse_args()
10
11# Create pipeline
12with dai.Pipeline(True) as pipeline:
13    pipeline.enableHolisticReplay(args.source)
14
15    # Define source and output
16    camRgb = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
17    camRgbOut = camRgb.requestOutput((600, 400), fps = 30)
18
19    imu = pipeline.create(dai.node.IMU)
20    imu.enableIMUSensor(dai.IMUSensor.ACCELEROMETER_RAW, 500);
21    imu.enableIMUSensor(dai.IMUSensor.GYROSCOPE_RAW, 400);
22    imu.setBatchReportThreshold(100)
23
24    videoQueue = camRgbOut.createOutputQueue()
25    imuQueue = imu.out.createOutputQueue()
26
27    # Connect to device and start pipeline
28    pipeline.start()
29    while pipeline.isRunning():
30        videoIn : dai.ImgFrame = videoQueue.get()
31        imuData : dai.IMUData = imuQueue.get()
32
33        # Get BGR frame from NV12 encoded video frame to show with opencv
34        # Visualizing the frame on slower hosts might have overhead
35        cv2.imshow("video", videoIn.getCvFrame())
36
37        for packet in imuData.packets:
38            print(f"IMU Accelerometer: {packet.acceleroMeter}")
39            print(f"IMU Gyroscope: {packet.gyroscope}")
40
41        if cv2.waitKey(1) == ord('q'):
42            break

C++

1#include <opencv2/highgui.hpp>
2
3#include "depthai/depthai.hpp"
4
5#ifndef DEPTHAI_MERGED_TARGET
6    #error This example needs OpenCV support, which is not available on your system
7#endif
8
9int main(int argc, char** argv) {
10    dai::Pipeline pipeline;
11
12    pipeline.enableHolisticReplay(argc > 1 ? std::string(argv[1]) : "recording.tar");
13
14    auto camRgb = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_A);
15    auto* camOut = camRgb->requestOutput({600, 400});
16
17    auto imu = pipeline.create<dai::node::IMU>();
18
19    // enable ACCELEROMETER_RAW at 500 hz rate
20    imu->enableIMUSensor(dai::IMUSensor::ACCELEROMETER_RAW, 500);
21    // enable GYROSCOPE_RAW at 400 hz rate
22    imu->enableIMUSensor(dai::IMUSensor::GYROSCOPE_RAW, 400);
23    imu->setBatchReportThreshold(100);
24
25    auto videoQueue = camOut->createOutputQueue();
26    auto q = imu->out.createOutputQueue();
27
28    pipeline.start();
29
30    auto start = std::chrono::steady_clock::now();
31
32    while(pipeline.isRunning()) {
33        auto videoIn = videoQueue->get<dai::ImgFrame>();
34        auto imuData = q->get<dai::IMUData>();
35
36        cv::imshow("video", videoIn->getCvFrame());
37
38        for(auto& imuPacket : imuData->packets) {
39            auto& acceleroValues = imuPacket.acceleroMeter;
40            auto& gyroValues = imuPacket.gyroscope;
41
42            printf("Accelerometer [m/s^2]: x: %.3f y: %.3f z: %.3f \n", acceleroValues.x, acceleroValues.y, acceleroValues.z);
43            printf("Gyroscope [rad/s]: x: %.3f y: %.3f z: %.3f \n", gyroValues.x, gyroValues.y, gyroValues.z);
44        }
45
46        if(cv::waitKey(1) == 'q') {
47            break;
48        }
49    }
50
51    pipeline.stop();
52}

需要帮助?

请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。