You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用预录制视频/图像替代Intel RealSense ZR300实时采集实现人体追踪

关于RealSense SDK加载预录制文件及通用视频人体追踪的问题

针对你的两个核心问题,我来逐一给出实用解答:


1. RealSense SDK中加载预录制文件并逐帧获取画面的API

RealSense SDK专门提供了**rs2::playback**类来处理官方预录制的.bag文件(包含同步的RGB、深度等数据流),可以完美替代实时相机采集逻辑,实现逐帧读取控制。

结合你提供的示例代码,你需要替换原有的pt_utils.init_camera实时相机初始化逻辑,改为加载预录制文件的流程,核心代码示例如下:

// 替换原相机初始化部分
rs2::config cfg;
// 指定你的预录制bag文件路径
cfg.enable_device_from_file("your_recording.bag");

rs2::pipeline pipe;
auto profile = pipe.start(cfg);

// 获取playback对象,可控制播放速度、暂停等
auto playback = profile.get_device().as<rs2::playback>();
playback.set_real_time(false); // 关闭实时播放,确保逐帧处理不丢帧

// 逐帧获取数据并适配现有代码逻辑
while (!pt_utils.user_request_exit()) {
    rs2::frameset frames = pipe.wait_for_frames();
    // 提取RGB和深度帧
    rs2::video_frame color_frame = frames.get_color_frame();
    rs2::depth_frame depth_frame = frames.get_depth_frame();

    // 将rs2::frame转换为SDK要求的rs::core::image格式
    rs::core::image_info color_info{color_frame.get_width(), color_frame.get_height(), rs::core::image_format::rgb8};
    rs::core::image_info depth_info{depth_frame.get_width(), depth_frame.get_height(), rs::core::image_format::z16};
    
    auto color_image = rs::core::image::create_instance(
        color_info,
        rs::core::image_interface::flag::any,
        (const void*)color_frame.get_data(),
        color_frame.get_stride_in_bytes()
    );
    auto depth_image = rs::core::image::create_instance(
        depth_info,
        rs::core::image_interface::flag::any,
        (const void*)depth_frame.get_data(),
        depth_frame.get_stride_in_bytes()
    );

    // 构建correlated_sample_set,替换原pt_utils.get_sample_set的输出
    rs::core::correlated_sample_set sample_set{};
    sample_set.images[(int)rs::core::stream_type::color] = color_image;
    sample_set.images[(int)rs::core::stream_type::depth] = depth_image;
    
    // 后续的Object Recognition和Person Tracking处理逻辑保持不变
}

你需要同步调整pt_utils中的相关辅助函数,或者直接替换原有的get_sample_set调用逻辑,适配手动构建的correlated_sample_set。


2. 是否可以使用其他相机拍摄的通用视频/图像文件进行人体检测与追踪?

这个问题需要分情况讨论:

  • 核心限制:依赖RGB-D数据:RealSense的Person Tracking和Object Recognition模块大多是基于RGB-D(彩色+深度)设计的,很多核心算法(比如3D人体姿态估计、精确物体定位)需要深度信息来保证精度和功能完整性。如果你的通用视频只有RGB画面,没有对应同步的深度数据,那么部分3D相关功能会失效,纯RGB模式下的检测追踪精度也会大幅下降。
  • 纯RGB模式的可行性:部分版本的SDK支持纯RGB输入,但需要你手动调整模块配置,禁用依赖深度的功能。比如在Person Tracking中,你可以尝试关闭深度相关配置:
    // 禁用深度依赖(具体API需对应你的SDK版本)
    ptModule->QueryConfiguration()->QueryTracking()->SetDepthEnabled(false);
    
  • 通用视频的适配方法:如果要使用普通RGB视频,你需要:
    1. 用OpenCV等工具逐帧读取视频文件;
    2. 将帧转换为RealSense SDK要求的rs::core::image格式;
    3. 构建correlated_sample_set(深度图像设为nullptr);
    4. 调整模块配置,关闭深度相关功能。

纯RGB视频的简易适配示例:

// 用OpenCV读取通用视频
cv::VideoCapture cap("your_video.mp4");
if (!cap.isOpened()) { /* 错误处理逻辑 */ }

cv::Mat frame;
while (cap.read(frame) && !pt_utils.user_request_exit()) {
    cv::cvtColor(frame, frame, cv::COLOR_BGR2RGB); // 转换为RGB格式
    
    rs::core::image_info color_info{frame.cols, frame.rows, rs::core::image_format::rgb8};
    auto color_image = rs::core::image::create_instance(
        color_info,
        rs::core::image_interface::flag::any,
        frame.data,
        frame.step
    );

    rs::core::correlated_sample_set sample_set{};
    sample_set.images[(int)rs::core::stream_type::color] = color_image;
    sample_set.images[(int)rs::core::stream_type::depth] = nullptr; // 无深度数据
    
    // 后续的检测追踪逻辑...
}

内容的提问来源于stack exchange,提问作者Sakthivel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:00:11