본문 바로가기
통신 Study/ROS

[Robotics] Intel® RealSense™ Depth Camera D455

by 하람 Haram 2023. 4. 5.
728x90

Depth Camera 를 사용하기 위해서 다음 메뉴얼을 참고하자

 

https://www.intelrealsense.com/get-started-depth-camera/

 

Get Started with Intel® RealSense™D400 Series depth camera

Congratulations! Now that you’ve got your Intel® RealSense™ depth camera, start using it by following these simple steps.

www.intelrealsense.com

 

우분투를 사용하고 있으므로 다음 github의 readme를 따르자

https://github.com/IntelRealSense/librealsense/blob/development/doc/distribution_linux.md

 

GitHub - IntelRealSense/librealsense: Intel® RealSense™ SDK

Intel® RealSense™ SDK. Contribute to IntelRealSense/librealsense development by creating an account on GitHub.

github.com

 

DKMS 패키지를 이용하라 하니 이용합시다 (권장한다고 합니다)

 

Realsense Driver 설치

 

 

 

먼저 Register the server's public key:

서버의 public key를 등록

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE

 

 

레퍼지스토리 목록에 추가 (서버를 추가)

sudo add-apt-repository "deb https://librealsense.intel.com/Debian/apt-repo $(lsb_release -cs) main" -u

 

 

라이브러리 설치

sudo apt-get install librealsense2-dkms
sudo apt-get install librealsense2-utils

 첫번째 라이브러리 설정 중 어떤 이상한 창

│ Your system has UEFI Secure Boot enabled.

하나 나와서 ok 눌렀더니

 

다음과 같이 설정 해주었다

뭔지는 모르겠지만 잘 되었다고 한다

 

 

Developer 와 Debug 패키지 설치

sudo apt-get install librealsense2-dev
sudo apt-get install librealsense2-dbg

이 두개는 optional  하지만 이것을 설치하면 realsense를 이용하여 컴파일이 가능하다고 한다

 

With dev package installed, you can compile an application with librealsense using g++ -std=c++11 filename.cpp lrealsense2 or an IDE of your choice.

 

 

작동테스트

realsense-viewer

오 뭔가 엄청나 옆에 뜨는 창 거슬리니 install로 혼내줍시다

 

Intel RealSense D455      (S/N 146222251805)
Current Version: 05.12.07.150
Recommended Version: 5.14.0.0

 

읽어보니 보전 업데이트 하라는 말이네요 

신기 방기 

 

 Realsense같은 경우 USB 3.0 데이터 케이블로 연결해야 합니다 

 

우리는 이를 ROS에 사용할 예정이므로

기본 ROS 패키지를 다운로드합니다

sudo apt-get install ros-noetic-realsense2-camera

밑에는 Ros camera node의 실행 코드이다

roslaunch realsense2_camera rs_camera.launch

 

 

이를 파이썬에 연결하는 것은

https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/python-tutorial-1-depth.py

 

GitHub - IntelRealSense/librealsense: Intel® RealSense™ SDK

Intel® RealSense™ SDK. Contribute to IntelRealSense/librealsense development by creating an account on GitHub.

github.com

로 공부를 해보자

 

 

제일 먼저 라이브러리를 다운로드해주고

pip install pyrealsense2

(Python versions 3.6, 3.7, 3.8, 3.9, 3.10 are supported).

 

 

Source build up 를 해주자

 

sudo apt-get update && sudo apt-get upgrade

갱신 먼저 해주고

sudo apt-get install python3 python3-dev

python3랑 python-dev를 install 해주자

 

 

 

 

https://github.com/IntelRealSense/librealsense/releases

 

Releases · IntelRealSense/librealsense

Intel® RealSense™ SDK. Contribute to IntelRealSense/librealsense development by creating an account on GitHub.

github.com

다음은 여기에 들어가서

tar.gz를 받아주고

 

tar zxf librealsense-2.53.1.tar.gz

압축을 풀어준 다음

(파일은 편한 위치에 옮기는게 좋다)

 

cd librealsense-2.53.1/

그 다음 build 파일을 만들어 주고

mkdir build
cd build

 

들어간 다음 CMAKE를 만들어준다

CMake를 사용하면 의존성 정보를 일일이 기술해 주지 않아도 되므로 빌드 스크립트의 관리 측면에서 매우 효율적입니다. 프로젝트를 처음 시작할 때 Build Step만 잘 구성해 놓으면, 이후에는 소스 파일(*.c)을 처음 추가할 때만 CMakeLists.txt 파일을 열어서 등록해 주면 됩니다. (그다지 추천하는 방법은 아니지만, 소스파일을 자동으로 찾아서 추가하도록 구성하는 방법도 있습니다.) 이후에는 소스코드를 어떻게 수정하더라도 빌드에서 제외하지 않는 한 스크립트를 수정하지 않아도 됩니다.
# make & build
cmake ../ -DBUILD_PYTHON_BINDINGS:bool=true
make -j4
sudo make install

그다음엔 PYTHONPATH environment variable를 업데이트 해주자

export PYTHONPATH=$PYTHONPATH:/usr/local/lib

 

 

예시코드를 시행해보면

# First import the library
import pyrealsense2 as rs

# Create a context object. This object owns the handles to all connected realsense devices
pipeline = rs.pipeline()
pipeline.start()

try:
    while True:
        # Create a pipeline object. This object configures the streaming camera and owns it's handle
        frames = pipeline.wait_for_frames() #프레임셋을 선언하고 파이프에서 프레임셋 기다림
        depth = frames.get_depth_frame()
        
        if not depth: continue

        # Print a simple text-based representation of the image, by breaking it into 10x20 pixel regions and approximating the coverage of pixels within one meter
        coverage = [0]*64
        for y in range(480):
            for x in range(640):
                dist = depth.get_distance(x, y)
                if 0 < dist and dist < 1:
                    coverage[x//10] += 1

            if y%20 == 19:
                line = ""
                for c in coverage:
                    line += " .:nhBXWW"[c//25]
                coverage = [0]*64
                print(line)

finally:
    pipeline.stop()
Traceback (most recent call last): File "realsense_practice.py",
line 11, in <module> frames = pipeline.wait_for_frames()
RuntimeError: Frame didn't arrive within 5000

안된다 ㅠ

728x90