我希望看到 IntelRealsence D435 摄像头的视频的两个部分。
一个RGB
在640x480
,另一个是IR
(深度相机)在1280x720
。
以下代码出错,可能 cfg.enable_stream 不能按大小除。
我该如何划分它们?这是我的代码:
#include <opencv2/opencv.hpp>
#include "example.hpp"
#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
rs2::pipeline pipe;
rs2::config cfg;
//Add desired streams to configuration
cfg.enable_stream(RS2_STREAM_COLOR, RS2_FORMAT_BGR8, 30);
//for infrared
//cfg.enable_stream(RS2_STREAM_INFRARED, 1280, 720, RS2_FORMAT_Y8, 30);
cfg.enable_stream(RS2_STREAM_DEPTH, RS2_FORMAT_Z16, 30);
pipe.start(cfg);
texture depth_image;
rs2::align align_to(RS2_STREAM_DEPTH);
rs2::decimation_filter dec;
dec.set_option(RS2_OPTION_FILTER_MAGNITUDE, 2);
rs2::disparity_transform depth2disparity;
// Define spatial filter (edge-preserving)
rs2::spatial_filter spat;
spat.set_option(RS2_OPTION_HOLES_FILL, 5);
rs2::temporal_filter temp;
rs2::disparity_transform disparity2depth(false);
rs2::frame_queue postprocessed_frames;
CvSize size = cvSize(1280, 720);
for (;;)
{
rs2::frameset frames = pipe.wait_for_frames();
rs2::frame color_frame = frames.get_color_frame();
rs2::colorizer color_map;
rs2::frame depth_frame = color_map(frames.get_depth_frame());
我将运行此代码来获取图片 Mat color(Size(640, 480), CV_8UC3, (void*)color_frame.get_data(), Mat::AUTO_STEP); const IplImage image_frame_show = new IplImage(color); namedWindow("显示颜色", WINDOW_AUTOSIZE); cvShowImage("显示颜色", image_frame_show); Mat depth_show(Size(1280, 720), CV_8UC3, (void )depth_frame.get_data(), Mat::AUTO_STEP); 常量 IplImage *depth_frame_show = new IplImage(depth_show); namedWindow("显示深度", WINDOW_AUTOSIZE); cvShowImage("显示深度", depth_frame_show);
waitKey(10);
}
return 0;
}