【发布时间】:2020-04-07 13:23:49
【问题描述】:
我想从英特尔实感摄像头获取连续距离帧。所以,我想生成一个尺寸为 1280*720 的 Mat 对象(1 个通道)(应该是 415 realsense cam 的分辨率)。这个矩阵应该只包含每个像素的距离信息。
在 realsense 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;
}
编译时没有报错,但是输出的数据真的很奇怪。
有什么想法吗?
【问题讨论】:
标签: c++ opencv intel mat realsense