当前位置:   article > 正文

RealSense:获取左右相机_d415深度相机分别读取左右相机图像

d415深度相机分别读取左右相机图像

Code

#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
#include "example.hpp"          // Include short list of convenience functions for rendering

#include <opencv2/opencv.hpp>

int main(int argc, char * argv[])
{
	int width = 1280;
	int height = 720;
	int fps = 30;
	rs2::config config;
	config.enable_stream(RS2_STREAM_INFRARED, 1, width, height, RS2_FORMAT_Y8, fps);
	config.enable_stream(RS2_STREAM_INFRARED, 2, width, height, RS2_FORMAT_Y8, fps);

	// start pipeline
	rs2::pipeline pipeline;
	rs2::pipeline_profile pipeline_profile = pipeline.start(config);

	rs2::device selected_device = pipeline_profile.get_device();
	auto depth_sensor = selected_device.first<rs2::depth_sensor>();

	if (depth_sensor.supports(RS2_OPTION_EMITTER_ENABLED))
	{
		// depth_sensor.set_option(RS2_OPTION_EMITTER_ENABLED, 1.f); // Enable emitter
		depth_sensor.set_option(RS2_OPTION_EMITTER_ENABLED, 0.f); // Disable emitter
	}

	auto ir1_stream = pipeline_profile.get_stream(RS2_STREAM_INFRARED, 1);
	auto ir2_stream = pipeline_profile.get_stream(RS2_STREAM_INFRARED, 2);

	rs2_intrinsics intrinsics_1 = ir1_stream.as<rs2::video_stream_profile>().get_intrinsics();
	rs2_intrinsics intrinsics_2 = ir2_stream.as<rs2::video_stream_profile>().get_intrinsics();

	std::cout<<intrinsics_1.fx<<std::endl;

	rs2_extrinsics e = ir1_stream.get_extrinsics_to(ir2_stream);
	auto baseline = e.translation[0];

	int count = 0;
	while (1) // Application still alive?
	{
		// wait for frames and get frameset
		rs2::frameset frameset = pipeline.wait_for_frames();

		// get single infrared frame from frameset
		//rs2::video_frame ir_frame = frameset.get_infrared_frame();

		// get left and right infrared frames from frameset
		rs2::video_frame ir_frame_left = frameset.get_infrared_frame(1);
		rs2::video_frame ir_frame_right = frameset.get_infrared_frame(2);


		cv::Mat dMat_left = cv::Mat(cv::Size(width, height), CV_8UC1, (void*)ir_frame_left.get_data());
		cv::Mat dMat_right = cv::Mat(cv::Size(width, height), CV_8UC1, (void*)ir_frame_right.get_data());

		cv::imshow("img_l", dMat_left);
		cv::imshow("img_r", dMat_right);
		char c = cv::waitKey(30);
		cv::imwrite("/media/yqs/_dde_data/dataset/l/"+std::to_string(count)+".png",dMat_left);
		cv::imwrite("/media/yqs/_dde_data/dataset/r/"+std::to_string(count)+".png",dMat_right);
		count++;
	}

	return EXIT_SUCCESS;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65

参考

https://github.com/IntelRealSense/librealsense/wiki/API-How-To
https://github.com/IntelRealSense/librealsense/issues/1140

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/90322
推荐阅读
相关标签
  

闽ICP备14008679号