DepthAI
Software Stack

ON THIS PAGE

  • Pipeline
  • Source code

Detection network Replay

Supported on:RVC2RVC4
This example demonstrates using DepthAI's RemoteConnection to stream and visualize YOLOv6 object detection results and video frames from a replayed video file.This example requires the DepthAI v3 API, see installation instructions.

Pipeline

Source code

Python

Python
GitHub
1#!/usr/bin/env python3
2import depthai as dai
3from pathlib import Path
4from argparse import ArgumentParser
5
6scriptDir = Path(__file__).resolve().parent
7examplesRoot = (scriptDir / Path('../')).resolve()  # This resolves the parent directory correctly
8models = examplesRoot / 'models'
9videoPath = models / 'construction_vest.mp4'
10
11parser = ArgumentParser()
12parser.add_argument("--webSocketPort", type=int, default=8765)
13parser.add_argument("--httpPort", type=int, default=8082)
14parser.add_argument("-i", "--inputVideo", default=videoPath, help="Input video name")
15args = parser.parse_args()
16
17remoteConnector = dai.RemoteConnection(webSocketPort=args.webSocketPort, httpPort=args.httpPort)
18# Create pipeline
19with dai.Pipeline() as pipeline:
20    replay = pipeline.create(dai.node.ReplayVideo)
21    replay.setReplayVideoFile(Path(args.inputVideo))
22    detectionNetwork = pipeline.create(dai.node.DetectionNetwork).build(
23        replay, dai.NNModelDescription("yolov6-nano")
24    )
25
26    remoteConnector.addTopic("detections", detectionNetwork.out, "img")
27    remoteConnector.addTopic("images", replay.out, "img")
28
29    pipeline.start()
30    remoteConnector.registerPipeline(pipeline)
31
32    while pipeline.isRunning():
33        key = remoteConnector.waitKey(1)
34        if key == ord("q"):
35            print("Got q key from the remote connection!")
36            break

C++

1#include <csignal>
2#include <depthai/depthai.hpp>
3#include <depthai/remote_connection/RemoteConnection.hpp>
4#include <iostream>
5
6#include "depthai/modelzoo/Zoo.hpp"
7
8// Signal handling for clean shutdown
9static bool isRunning = true;
10void signalHandler(int signum) {
11    isRunning = false;
12}
13
14int main(int argc, char** argv) {
15    // Default port values
16    int webSocketPort = 8765;
17    int httpPort = 8082;
18
19    // Register signal handler
20    std::signal(SIGINT, signalHandler);
21
22    // Create RemoteConnection
23    dai::RemoteConnection remoteConnector(dai::RemoteConnection::DEFAULT_ADDRESS, webSocketPort, true, httpPort);
24
25    // Create Pipeline
26    dai::Pipeline pipeline;
27    auto replay = pipeline.create<dai::node::ReplayVideo>();
28    replay->setReplayVideoFile(VIDEO_PATH);
29
30    // Create and configure Detection Network
31    auto detectionNetwork = pipeline.create<dai::node::DetectionNetwork>()->build(replay, dai::NNModelDescription{"yolov6-nano"});
32
33    // Set up topics for remote connection
34    remoteConnector.addTopic("detections", detectionNetwork->out);
35    remoteConnector.addTopic("images", replay->out);
36    pipeline.start();
37
38    remoteConnector.registerPipeline(pipeline);
39    // Main loop
40    while(isRunning && pipeline.isRunning()) {
41        int key = remoteConnector.waitKey(1);
42        if(key == 'q') {
43            std::cout << "Got 'q' key from the remote connection!" << std::endl;
44            break;
45        }
46    }
47
48    std::cout << "Pipeline stopped." << std::endl;
49    return 0;
50}

Need assistance?

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