从RealSense相机中提取深度帧?

4
我希望能从英特尔实感相机中获取连续的距离帧。因此,我想生成一个大小为1280*720(应该是415实感相机的分辨率)的Mat对象(1通道)。该矩阵应仅包含每个像素的距离信息。
在实感SDK的示例中,您可以找到创建Mat对象的im-show文件,但这是一个BGR编码的彩色距离图像。
您肯定可以将此帧转换为HSV,并通过H通道简单地获取距离。但是,我认为将距离数据先转换为BGR,然后转换为HSV,再转换回距离并不是非常干净的解决方案。
因此,我对示例im-show进行了一些更改:
#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
// not sure if all of these includes are needed: 
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main() 
{
    // Declare RealSense pipeline, encapsulating the actual device and sensors
    rs2::pipeline pipe;
    // Start streaming with default recommended configuration
    pipe.start();

    const auto window_name = "Display Image";
    namedWindow(window_name, WINDOW_AUTOSIZE);

    while (waitKey(1) < 0 && getWindowProperty(window_name, WND_PROP_AUTOSIZE) >= 0)
    {
        rs2::frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camera
        rs2::frame depth = data.get_depth_frame();

        // Query frame size (width and height)
        const int w = depth.as<rs2::video_frame>().get_width();
        const int h = depth.as<rs2::video_frame>().get_height();

        // Create OpenCV matrix of size (w,h) from the colorized depth data (bgr values)
        Mat temp(Size(w, h), CV_8UC1, (void*)depth.get_data(), Mat::AUTO_STEP);

        //Update the window with new data
        imshow(window_name, temp);
    }

    return EXIT_SUCCESS;
}

我编译时没有遇到任何错误,但输出的数据非常奇怪。

enter image description here

任何想法?
2个回答

4

谢谢,但我自己找到了一个非常简单的解决方案。

// CAPTURE A FRAME
rs2::frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camera
rs2::depth_frame depth = data.get_depth_frame(); // Get a depth frame 

// Create OpenCV matrix of size (w,h) from the colorized depth data
Mat depth_img(Size(width, height), CV_16UC1, (void*)depth.get_data(), Mat::AUTO_STEP);

// Convert 16bit image to 8bit image
depth_img.convertTo(depth_img, CV_8UC1, 15 / 256.0);

0

另一种@apct解决方案的替代方法是:

// Declare depth colorizer for pretty visualization of depth data
rs2::colorizer color_map;
color_map.set_option(RS2_OPTION_COLOR_SCHEME, 2.f); // White to Black
rs2::frame frame_depth = data.get_depth_frame().apply_filter(color_map);
auto vf_depth = frame_depth.as<rs2::video_frame>();
Mat image_depth(Size(w, h), CV_8UC3, (void*)vf_depth.get_data(), Mat::AUTO_STEP);

这种应用颜色映射的方法(而不是转换)可以提供更详细的深度信息,但值是反转的(较大的值表示离传感器更近,较小的值表示离传感器更远)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接