我希望能从英特尔实感相机中获取连续的距离帧。因此,我想生成一个大小为1280*720(应该是415实感相机的分辨率)的Mat对象(1通道)。该矩阵应仅包含每个像素的距离信息。
在实感SDK的示例中,您可以找到创建Mat对象的im-show文件,但这是一个BGR编码的彩色距离图像。
您肯定可以将此帧转换为HSV,并通过H通道简单地获取距离。但是,我认为将距离数据先转换为BGR,然后转换为HSV,再转换回距离并不是非常干净的解决方案。
因此,我对示例im-show进行了一些更改:
我编译时没有遇到任何错误,但输出的数据非常奇怪。 任何想法?
在实感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;
}
我编译时没有遇到任何错误,但输出的数据非常奇怪。 任何想法?