此页面由 AI 自动翻译。查看英文原版
DepthAI
  • DepthAI 组件
    • AprilTags
    • 基准测试
    • 相机
    • 校准
    • 深度
    • 检测网络
    • 事件
    • 特征跟踪器
    • 网关
    • 主机节点
    • 图像对齐
    • 图像处理
    • IMU
    • 杂项
    • 模型库
    • 神经深度
    • 神经网络
    • 对象跟踪器
    • 点云
    • 记录回放
    • RGBD
    • 脚本
    • 空间检测网络
    • 空间位置计算器
    • 立体深度
    • 同步
    • ToF
    • 视频编码器
    • 可视化工具
    • VSLAM
    • 扭曲
    • RVC2-特定
  • 高级教程
  • API 参考
  • 工具
软件栈
最后更新

本页目录

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

视频回放

最后更新
Supported on:RVC2RVC4
此示例演示了如何回放先前录制的视频,并展示了如何使用 ReplayVideo 节点将帧馈送回 DepthAI 管道。此示例需要 DepthAI v3 API,请参阅 安装说明。

源代码

Python

Python
GitHub
1import depthai as dai
2import argparse
3import time
4from pathlib import Path
5import cv2
6
7parser = argparse.ArgumentParser()
8parser.add_argument("-v", "--inputVideo", default="test_video.mp4", help="Input video name")
9parser.add_argument("-m", "--inputMetadata", default="test_video.mcap", help="Input metadata name")
10
11args = parser.parse_args()
12
13# Check if the input video file exists
14if not Path(args.inputVideo).exists():
15    print("First record a video using the record_video.py script")
16    raise FileNotFoundError(f'Input video file not found: {args.inputVideo}')
17
18with dai.Pipeline() as pipeline:
19    replay = pipeline.create(dai.node.ReplayVideo)
20    replay.setReplayVideoFile(Path(args.inputVideo))
21    if Path(args.inputMetadata).exists():
22        replay.setReplayMetadataFile(Path(args.inputMetadata))
23    replay.setOutFrameType(dai.ImgFrame.Type.NV12)
24    replay.setLoop(False)
25
26    videoOut = replay.out.createOutputQueue()
27
28    pipeline.start()
29    while pipeline.isRunning() and replay.isRunning():
30        try:
31            outFrame : dai.ImgFrame = videoOut.get()
32        except dai.MessageQueue.QueueException:
33            # Replay stopped the pipeline
34            break
35        outFrameCv = outFrame.getCvFrame()
36        cv2.imshow("video", outFrameCv)
37        if cv2.waitKey(1) == ord('q'):
38            print("Stopping pipeline")
39            pipeline.stop()
40            break

C++

1#include "depthai/depthai.hpp"
2#include "depthai/pipeline/node/host/Display.hpp"
3#include "depthai/pipeline/node/host/Replay.hpp"
4
5int main(int argc, char** argv) {
6    std::string vidName = "test_video.avi";
7    if(argc > 1) vidName = argv[1];
8    dai::Pipeline pipeline(false);
9
10    auto replay = pipeline.create<dai::node::ReplayVideo>();
11    auto display = pipeline.create<dai::node::Display>();
12
13    replay->setReplayVideoFile(vidName);
14    replay->setFps(30);
15
16    replay->out.link(display->input);
17
18    pipeline.run();  // Let the display node stop the pipeline
19}

需要帮助?

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