1. 程式人生 > >realsense對齊彩色影象和深度影象

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<rs2::stream_profile>& 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();