본문 바로가기
IntelRealsense & PCL

Intel RealSense L515에서 데이터 추출하기

by choice1219 2021. 4. 21.

안녕하세요. VeriLog입니다.

 

지난 포스팅에서는 Intel RealSense와 Point Cloud Library (PCL)을 설치하고 세팅하는 방법에 대해서 포스팅하였습니다.

 

이제 설치 및 환경설정이 끝났으니, 본격적으로 데이터를 취득하고 가공하는 예제들을 수행하려고 합니다.

 

이번 포스팅에서는 Intel RealSense L515 (LiDAR)에서 Color, Depth, Depth (in meters) 정보를 취득하는 방법에 대해서 포스팅 하고자 합니다.

* Intel RealSense D435도 같은 코드를 사용합니다.

 

Intel RealSense L515

 

1. L515 Specification

 - L515 LiDAR는 Depth 정보를 취득하는 LiDAR와 RGB 정보를 취득하는 카메라로 이루어져 있습니다.

   LiDAR와 RGB 카메라의 Specification은 다음과 같습니다.

   * 출처: www.intelrealsense.com/lidar-camera-l515/

 

 1) LiDAR

    - FOV(H x V): 70 x 55 (+- 3)

    - Resolution: Up to 1024 x 768

 

  2) RGB Camera

    - FOV(H x V): 70 x 43 (+- 3)

    - Resolution: 1920 x 1080

 

  3) Aligned Image (Depth와 RGB가 합쳐진 이미지)

    - FOV(H x V): 70 x 43 (+- 3)

    - Resolution (default): 1280 x 720

 

 - LiDAR와 RGB 카메라의 FOV와 해상도가 다르기 때문에 같은 거리에 있는 이미지를 보더라도 LiDAR가 더 넓은 영역을 보게 됩니다.

 - 또한, LiDAR와 RGB 카메라의 위치가 다르기 때문에, 약간의 translation도 존재합니다.

 - 따라서, 두 이미지를 합치는 것은 매우 중요하며, 방법에 따라 결과물의 FOV, Resolution 등이 달라지게 됩니다.

 - Intel에서 제공하는 코드를 통해 얻은 aligned image의 경우, FOV는 RGB의 FOV를 가져오고, Resolution은 기본적으로 1280 x 720을 사용합니다. (Resolution은 변경 가능)

 

 

 2. Data 추출 코드 (C++)

  - 먼저 첨부한 "cv-helpers.hpp" 파일을 헤더에 추가해주세요.

cv-helpers.hpp
0.00MB

  - 이후, 아래 코드를 수행해주세요.

  - 기본적으로 1280 x 720으로 출력되지만, 크기가 너무 커서, 640 x 360으로 줄여서 출력하도록 수정하였습니다.

// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.

#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
#include <opencv2/opencv.hpp>   // Include OpenCV API
#include "cv-helpers.hpp"    // Helper functions for conversions between RealSense and OpenCV
#include <iostream>


int main(int argc, char * argv[]) try
{
	using namespace cv;
	using namespace rs2;
	

	// Define colorizer and align processing-blocks
	colorizer colorize;
	align align_to(RS2_STREAM_COLOR);

	// Start the camera
	pipeline pipe;
	pipe.start();

	// Skips some frames to allow for auto-exposure stabilization
	for (int i = 0; i < 10; i++) pipe.wait_for_frames();

	while (1){

		frameset data = pipe.wait_for_frames(); // data read
		frameset aligned_set = align_to.process(data);
		frame depth = aligned_set.get_depth_frame();

		auto color_mat = frame_to_mat(aligned_set.get_color_frame());
		colorize.set_option(RS2_OPTION_COLOR_SCHEME, 2);
				
		frame bw_depth = depth.apply_filter(colorize);
		auto depth_mat = frame_to_mat(bw_depth);
		auto depth_meter = depth_frame_to_meters(depth);

		resize(color_mat, color_mat, Size(640, 360));
		resize(depth_mat, depth_mat, Size(640, 360));
		resize(depth_meter, depth_meter, Size(640, 360));

		imshow("color", color_mat);
		imshow("depth", depth_mat);
		imshow("depth_meter", depth_meter);

		if (waitKey(5) == 'q')
			break;
	}

	return EXIT_SUCCESS;
}
catch (const rs2::error & e)
{
	std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
	return EXIT_FAILURE;
}
catch (const std::exception& e)
{
	std::cerr << e.what() << std::endl;
	return EXIT_FAILURE;
}

 

 3. Demo 영상

  - Demo 영상입니다.

  - Depth (in meters)는 Float64 type이며 m단위로 표현되게 됩니다. 따라서, 이미지가 대체적으로 흰색으로 나타나게 됩니다.

    * float에서는 0~1로 표현되며, 0은 검은색 1이상은 흰색으로 표현됩니다.

 

 

혹시 질문 있으시면, 댓글로 남겨주시면 답변 드리도록 하겠습니다.

'IntelRealsense & PCL' 카테고리의 다른 글

PCL 설치 및 Intel Realsense 연동  (1) 2021.04.21
Intel Realsense SDK 설치 방법  (12) 2021.03.24