DepthAI
Software Stack

ON THIS PAGE

  • Pipeline
  • Source code

Visualizer YOLO

Supported on:RVC2RVC4
The example sets up a DepthAI pipeline to stream YOLOv6-Nano object detection results and 512x288 NV12 camera using RemoteConnection, enabling remote visualization.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 argparse import ArgumentParser
4
5parser = ArgumentParser()
6parser.add_argument("--webSocketPort", type=int, default=8765)
7parser.add_argument("--httpPort", type=int, default=8082)
8args = parser.parse_args()
9
10remoteConnector = dai.RemoteConnection(webSocketPort=args.webSocketPort, httpPort=args.httpPort)
11# Create pipeline
12with dai.Pipeline() as pipeline:
13    cameraNode = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
14    detectionNetwork = pipeline.create(dai.node.DetectionNetwork).build(
15        cameraNode, dai.NNModelDescription("yolov6-nano")
16    )
17
18    remoteConnector.addTopic("detections", detectionNetwork.out, "img")
19    remoteConnector.addTopic("images", detectionNetwork.passthrough, "img")
20
21    pipeline.start()
22    remoteConnector.registerPipeline(pipeline)
23
24    while pipeline.isRunning():
25        key = remoteConnector.waitKey(1)
26        if key == ord("q"):
27            print("Got q key from the remote connection!")
28            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 cameraNode = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_A);
28
29    // Create and configure Detection Network
30    auto detectionNetwork = pipeline.create<dai::node::DetectionNetwork>()->build(cameraNode, dai::NNModelDescription{"yolov6-nano"});
31
32    // Configure output for visualization
33    auto* cameraOutputVisualize = cameraNode->requestOutput(std::make_pair(512, 288), dai::ImgFrame::Type::NV12);
34    if(cameraOutputVisualize == nullptr) throw std::runtime_error("Error creating camera output");
35    // Set up topics for remote connection
36    remoteConnector.addTopic("detections", detectionNetwork->out);
37    remoteConnector.addTopic("images", *cameraOutputVisualize);
38    pipeline.start();
39
40    remoteConnector.registerPipeline(pipeline);
41    // Main loop
42    while(isRunning && pipeline.isRunning()) {
43        int key = remoteConnector.waitKey(1);
44        if(key == 'q') {
45            std::cout << "Got 'q' key from the remote connection!" << std::endl;
46            break;
47        }
48    }
49
50    std::cout << "Pipeline stopped." << std::endl;
51    return 0;
52}

Need assistance?

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