此页面由 AI 自动翻译。查看英文原版
DepthAI
  • DepthAI 组件
    • AprilTags
    • 基准测试
    • Camera
    • 校准
    • DetectionNetwork
    • Events
    • FeatureTracker
    • Gate
    • HostNodes
    • ImageAlign
    • ImageManip
    • IMU
    • 杂项
    • 模型动物园
    • NeuralDepth
    • NeuralNetwork
    • ObjectTracker
    • 点云
    • RecordReplay
    • RGBD
    • Script
    • SpatialDetectionNetwork
    • SpatialLocationCalculator
    • StereoDepth
    • Sync
    • VideoEncoder
    • Visualizer
    • Warp
    • RVC2-specific
  • 高级教程
  • API 参考
  • 工具
软件栈

本页目录

  • 源代码

视频回放

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}

需要帮助?

请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。