c++ - 从实感相机中提取深度帧?

标签 c++ opencv intel mat realsense

我想从英特尔实感相机获取连续距离帧。所以,我想生成一个大小为 1280*720(应该是 415 realsense cam 的分辨率)的 Mat 对象(1 个 channel )。这个矩阵应该只包含每个像素的距离信息。

在 realsense sdk 的示例中,您可以找到创建 Mat 对象的文件 im-show,但这是一个 BGR 编码的彩色距离图像。

您当然可以将此帧转换为 HSV 并通过 H channel 简单地获取距离。但是,我认为首先将距离数据转换为 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

有任何想法吗?

最佳答案

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

// 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);

关于c++ - 从实感相机中提取深度帧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59333612/

相关文章:

c++ - 检查 shared_ptr 的容器是否包含指针?

python - 确定屏幕截图中是否有较小的图像?

python - 如何在python opencv中获取hsv颜色的低值和高值

用于查找和覆盖/替换图像部分的 Python、OpenCV

computer-vision - 使用CustomLayerMapping.xml转换模型后,如何让openvino推理引擎回退到系统caffe?

linux - 英特尔酷睿 i5 (linux) 的 OpenCL 实现

c++ - 如何从函数返回 char 数组?

c++ - 如何在 Xcode 中修复 'sh: brew: command not found'?

c++ - Opencv floodFill : How do I transform from image to mask coordinates?

x86-64 - 在 Intel x86-64 架构上是否以 little endian 4 字节字获取机器代码指令?