此页面由 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
此示例演示了如何在 DepthAI 管道运行期间整体记录所有选定的输入流(例如视频和 IMU 数据),从而实现完整的重放以进行开发和测试。此示例需要 DepthAI v3 API,请参阅 安装说明

管道

源代码

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5import argparse
6from pathlib import Path
7
8parser = argparse.ArgumentParser()
9parser.add_argument("-o", "--output", default="recordings", help="Output path")
10parser.add_argument("-fps", "--fps", default=30, type=int, help="FPS for recording")
11args = parser.parse_args()
12
13# Create output directory if it doesn't exist
14Path(args.output).mkdir(parents=True, exist_ok=True)
15
16# Create pipeline
17with dai.Pipeline(True) as pipeline:
18    config = dai.RecordConfig()
19    config.outputDir = args.output
20    # config.videoEncoding.enabled = True
21    # config.videoEncoding.bitrate = 0 # Automatic
22    # config.videoEncoding.profile = dai.VideoEncoderProperties.Profile.H264_MAIN
23
24    pipeline.enableHolisticRecord(config)
25
26    # Define source and output
27    camA = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
28    camAOut = camA.requestFullResolutionOutput(fps=args.fps)
29    camB = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
30    camBOut = camB.requestFullResolutionOutput(fps=args.fps)
31    camC = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
32    camCOut = camC.requestFullResolutionOutput(fps=args.fps)
33
34    viewFinderOut = camA.requestOutput((640, 480), fps=args.fps)
35
36    imu = pipeline.create(dai.node.IMU)
37    imu.enableIMUSensor(dai.IMUSensor.ACCELEROMETER_RAW, 400)
38    imu.enableIMUSensor(dai.IMUSensor.GYROSCOPE_RAW, 400)
39    imu.setBatchReportThreshold(100)
40
41    sync = pipeline.create(dai.node.Sync)
42    sync.setSyncAttempts(0)
43    camAOut.link(sync.inputs["camA"])
44    camBOut.link(sync.inputs["camB"])
45    camCOut.link(sync.inputs["camC"])
46
47    viewFinderQueue = viewFinderOut.createOutputQueue()
48
49    # Connect to device and start pipeline
50    pipeline.start()
51    try:
52        while pipeline.isRunning():
53            frame = viewFinderQueue.get()
54            cv2.imshow("video", frame.getCvFrame())
55            if cv2.waitKey(1) == ord('q'):
56                break
57    except KeyboardInterrupt:
58        pass
59
60    pipeline.stop()

C++

1#include <atomic>
2#include <csignal>
3#include <filesystem>
4#include <opencv2/highgui.hpp>
5
6#include "depthai/common/CameraBoardSocket.hpp"
7#include "depthai/depthai.hpp"
8#include "depthai/utility/RecordReplay.hpp"
9#include "utility.hpp"
10#ifndef DEPTHAI_MERGED_TARGET
11    #error This example needs OpenCV support, which is not available on your system
12#endif
13
14// Signal handling for clean shutdown
15static std::atomic<bool> isRunning = true;
16void signalHandler(int signum) {
17    (void)signum;
18    isRunning = false;
19}
20
21int main(int argc, char** argv) {
22    // Register signal handler
23    std::signal(SIGINT, signalHandler);
24
25    dai::Pipeline pipeline;
26
27    dai::RecordConfig config;
28    config.outputDir = argc > 1 ? std::string(argv[1]) : getDefaultRecordingPath();
29    // config.videoEncoding.enabled = true;  // Use video encoding
30    // config.videoEncoding.bitrate = 0;     // Automatic
31    // config.videoEncoding.profile = dai::VideoEncoderProperties::Profile::H264_MAIN;
32
33    pipeline.enableHolisticRecord(config);
34
35    auto camA = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_A);
36    auto* camAOut = camA->requestFullResolutionOutput(std::nullopt, 10);
37    auto camB = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_B);
38    auto* camBOut = camB->requestFullResolutionOutput(std::nullopt, 10);
39    auto camC = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_C);
40    auto* camCOut = camC->requestFullResolutionOutput(std::nullopt, 10);
41
42    auto* viewFinderOut = camA->requestOutput({640, 480});
43
44    auto imu = pipeline.create<dai::node::IMU>();
45
46    // enable ACCELEROMETER_RAW at 400 hz rate
47    imu->enableIMUSensor(dai::IMUSensor::ACCELEROMETER_RAW, 400);
48    // enable GYROSCOPE_RAW at 400 hz rate
49    imu->enableIMUSensor(dai::IMUSensor::GYROSCOPE_RAW, 400);
50    imu->setBatchReportThreshold(100);
51
52    // Discard frames by passing through sync
53    auto sync = pipeline.create<dai::node::Sync>();
54    sync->setSyncAttempts(0);  // Don't wait for frames to sync
55    camAOut->link(sync->inputs["camA"]);
56    camBOut->link(sync->inputs["camB"]);
57    camCOut->link(sync->inputs["camC"]);
58
59    auto viewFinderQueue = viewFinderOut->createOutputQueue();
60
61    pipeline.start();
62
63    while(isRunning && pipeline.isRunning()) {
64        auto frame = viewFinderQueue->get<dai::ImgFrame>();
65        if(!frame) continue;
66        cv::imshow("Video", frame->getCvFrame());
67        auto key = cv::waitKey(10);
68        if(key == 'q') {
69            break;
70        }
71    }
72
73    pipeline.stop();
74}

需要帮助?

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