DepthAI
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    # Define source and output
14    camRgb = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
15    camRgbOut = camRgb.requestOutput((1920, 1080), fps = 30)
16
17    imu = pipeline.create(dai.node.IMU)
18    imu.enableIMUSensor(dai.IMUSensor.ACCELEROMETER_RAW, 500);
19    imu.enableIMUSensor(dai.IMUSensor.GYROSCOPE_RAW, 400);
20    imu.setBatchReportThreshold(100)
21
22    pipeline.enableHolisticReplay(args.source)
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 "depthai/depthai.hpp"
2#include "depthai/pipeline/node/host/Display.hpp"
3#include "depthai/utility/RecordReplay.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    auto camA = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_A);
12    auto* camAOut = camA->requestOutput({600, 400});
13    auto camB = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_B);
14    auto* camBOut = camB->requestOutput({600, 400});
15    auto camC = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_C);
16    auto* camCOut = camC->requestOutput({600, 400});
17
18    auto imu = pipeline.create<dai::node::IMU>();
19
20    auto display = pipeline.create<dai::node::Display>();
21
22    // enable ACCELEROMETER_RAW at 500 hz rate
23    imu->enableIMUSensor(dai::IMUSensor::ACCELEROMETER_RAW, 500);
24    // enable GYROSCOPE_RAW at 400 hz rate
25    imu->enableIMUSensor(dai::IMUSensor::GYROSCOPE_RAW, 400);
26    imu->setBatchReportThreshold(100);
27
28    camAOut->link(display->input);
29    auto q = imu->out.createOutputQueue();
30
31    auto camAqueue = camAOut->createOutputQueue();
32    auto camBqueue = camBOut->createOutputQueue();
33    auto camCqueue = camCOut->createOutputQueue();
34
35    pipeline.enableHolisticReplay(argc > 1 ? std::string(argv[1]) : "recording.tar");
36
37    pipeline.start();
38
39    auto start = std::chrono::steady_clock::now();
40
41    while(std::chrono::steady_clock::now() - start < std::chrono::seconds(15)) {
42        auto imuData = q->get<dai::IMUData>();
43        auto imuPackets = imuData->packets;
44        for(auto& imuPacket : imuPackets) {
45            auto& acceleroValues = imuPacket.acceleroMeter;
46            auto& gyroValues = imuPacket.gyroscope;
47
48            printf("Accelerometer [m/s^2]: x: %.3f y: %.3f z: %.3f \n", acceleroValues.x, acceleroValues.y, acceleroValues.z);
49            printf("Gyroscope [rad/s]: x: %.3f y: %.3f z: %.3f \n", gyroValues.x, gyroValues.y, gyroValues.z);
50        }
51        std::this_thread::sleep_for(std::chrono::milliseconds(1));
52    }
53
54    pipeline.stop();
55}

Need assistance?

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