realsense对齐彩色图像和深度图像

首先声明realsense通道,封装实际设备和传感器

	
        //初始化
	pipeline pipe;

	pipeline_profile profile = pipe.start();

	rs2_stream align_to = find_stream_to_align(profile.get_streams());

	rs2::align align(align_to);


 find_stream_to_align函数:

rs2_stream find_stream_to_align(const std::vector& streams)
{
	//Given a vector of streams, we try to find a depth stream and another stream to align depth with.
	//We prioritize color streams to make the view look better.
	//If color is not available, we take another stream that (other than depth)
	rs2_stream align_to = RS2_STREAM_ANY;
	bool depth_stream_found = false;
	bool color_stream_found = false;
	for (rs2::stream_profile sp : streams)
	{
		rs2_stream profile_stream = sp.stream_type();
		if (profile_stream != RS2_STREAM_DEPTH)
		{
			if (!color_stream_found)         //Prefer color
				align_to = profile_stream;

			if (profile_stream == RS2_STREAM_COLOR)
			{
				color_stream_found = true;
			}
		}
		else
		{
			depth_stream_found = true;
		}
	}

	if (!depth_stream_found)
		throw std::runtime_error("No Depth stream available");

	if (align_to == RS2_STREAM_ANY)
		throw std::runtime_error("No stream found to align with Depth");

	return align_to;
}

接下来对齐深度帧和彩色帧:

//声明深度着色器,以实现深度数据的可视化
colorizer color_map;

//处理帧对齐
auto processed = align.process(data);

frame depth_color = color_map.process(processed.get_depth_frame()); 
frame origin_color = processed.get_color_frame(); 

 

 

你可能感兴趣的:(opencv,realsense)