DepthAI
  • DepthAI Components
    • AprilTags
    • Benchmark
    • Camera
    • Calibration
    • DetectionNetwork
    • Events
    • FeatureTracker
    • Gate
    • HostNodes
    • ImageAlign
    • ImageManip
    • IMU
    • Misc
    • Model Zoo
    • NeuralDepth
    • NeuralNetwork
    • ObjectTracker
    • PointCloud
    • RecordReplay
    • RGBD
    • Script
    • SpatialDetectionNetwork
    • SpatialLocationCalculator
    • StereoDepth
    • Sync
    • VideoEncoder
    • Visualizer
    • Warp
    • RVC2-specific
  • Advanced Tutorials
  • API Reference
  • Tools
Software Stack

ON THIS PAGE

  • Pipeline
  • Source code

Holistic Replay

Supported on:RVC2RVC4
This example demonstrates how to replay previously recorded holistic data, feeding multiple synchronized streams such as video and IMU back into a DepthAI pipeline for testing and development.This example requires the DepthAI v3 API, see installation instructions.

Pipeline

Source code

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}

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.