此页面由 AI 自动翻译。查看英文原版
DepthAI
软件栈
最后更新

本页目录

  • 管道
  • 源代码
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包

检测网络回放

最后更新
Supported on:RVC2RVC4
此示例演示如何使用 DepthAI 的 RemoteConnection 从回放视频文件流式传输和可视化 YOLOv6 对象检测结果和视频帧。此示例需要 DepthAI v3 API,请参阅 安装说明。

管道

源代码

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}

需要帮助?

请访问讨论论坛以获取技术支持或您可能有的任何其他问题。