一共两种办法,第一种是直接在命令行使用librealsense,第二种使用python代码拉取。
因为L515已经停产,所以它的sdk在2.50之前可以使用,之后就不会适用,运行的话会报错,所以我们需要下载2.50之前的sdk,直接在命令行输入命令:
git clone -b v2.48.0 https://github.com/IntelRealSense/librealsense
过程中如果报各种git错误,最开始我上网上搜了很多通过ssh转http下载的,都不是好用的,之后重启下,就可以正常git了,下载成功之后如图所示:
使用ls查看一下发现存在librealsense
注:千万别换源(因为我就是换源之后,发现下载不了后续步骤的cmake),就用最原始系统自带的,不要修改/etc/apt/source.list,如果有不小心修改的了的,这是18.04对应的源如下(如果换回去之后,还是提示有问题,升级一下sudo apt-get update,应该就可以了):
# See UpgradeNotes - Community Help Wiki for ho to upgrade to
# newer versions of the distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted
# deb-src Index of /ubuntu-ports bionic main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
# deb-src Index of /ubuntu-ports bionic-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic universe
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic multiverse
# deb-src Index of /ubuntu-ports bionic multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb Index of /ubuntu bionic partner
# deb-src Index of /ubuntu bionic partner
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security universe
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security multiverse
我们进入该文件夹,在命令行输入cd librealsense,安装相应的依赖和脚本
cd librealsense
sudo apt-get install libudev-dev pkg-config libgtk-3-dev
sudo apt-get install libusb-1.0-0-dev pkg-config
sudo apt-get install libglfw3-dev
sudo apt-get install libssl-dev
sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && udevadm trigger
安装完成之后,我们新建build文件夹,进行编译librealsense:
安装cmake,安装make,sudo apt-get install cmake,sudo apt-get install make
注:如果在执行完cmake这个步骤之后,查看这个文件夹中只有2个文件,那么说明缺少编译依赖,使用命令apt-get install gcc build-essential来进行补充依赖,之后删除这个rm -r build这个文件夹,再次重新创建,cmake。
mkdir build
cd build
sudo cmake ../ -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=true -DBUILD_PYTHON_BINDINGS:bool=true -DPYTHON_EXECUTABLE=/usr/bin/python3
sudo make uninstall
make clean && make -j$(nproc)
sudo make install
如果安装过程中,发现报错终止了安装,我的报错信息如下:
n file included from /home/xavier/librealsense/examples/software-device/../example.hpp:10,
from /home/xavier/librealsense/examples/software-device/rs-software-device.cpp:6:
/usr/include/GLFW/glfw3.h:215:13: fatal error: GL/glu.h: No such file or directory
215 | #include <GL/glu.h>
| ^~~~~~~~~~
compilation terminated.
make[2]: *** [examples/software-device/CMakeFiles/rs-software-device.dir/build.make:63: examples/software-device/CMakeFiles/rs-software-device.dir/rs-software-device.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1252: examples/software-device/CMakeFiles/rs-software-device.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
In file included from /home/xavier/librealsense/examples/capture/../example.hpp:10,
from /home/xavier/librealsense/examples/capture/rs-capture.cpp:5:
/usr/include/GLFW/glfw3.h:215:13: fatal error: GL/glu.h: No such file or directory
215 | #include <GL/glu.h>
| ^~~~~~~~~~
compilation terminated.
make[2]: *** [examples/capture/CMakeFiles/rs-capture.dir/build.make:63: examples/capture/CMakeFiles/rs-capture.dir/rs-capture.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1279: examples/capture/CMakeFiles/rs-capture.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
可以进行安装:
sudo apt-get update
sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev
安装完成之后使用命令查看
ls /usr/include/GL/glu.h
如果有显示信息,则代表安装成功。
安装过程很慢(大约30-40分钟),需等待:
2025-06-23更新
第一种方法:
安装完成之后,可以在终端命令行输入:realsense-viewer,可以查看页面开启:
第二种方法:
我们需要下载个pycharm用来方便查看安装我们的包:
安装教程:最详细jetson-xavier-nx安装pycharm以及虚拟环境管理-CSDN博客
我这边附上测试代码:
import pyrealsense2 as rs
import numpy as np
import cv2
# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
# 建议使用相同分辨率
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 30)
# Start streaming
pipeline.start(config)
try:
while True:
# Wait for a coherent pair of frames: depth and color
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
color_frame = frames.get_color_frame()
if not depth_frame or not color_frame:
continue
# Convert images to numpy arrays
depth_image = np.asanyarray(depth_frame.get_data())
color_image = np.asanyarray(color_frame.get_data())
# Apply colormap on depth image
depth_colormap = cv2.applyColorMap(
cv2.convertScaleAbs(depth_image, alpha=0.03),
cv2.COLORMAP_JET
)
# 方法1:分别显示两个窗口
cv2.imshow('Color Stream', color_image)
cv2.imshow('Depth Stream', depth_colormap)
# 方法2:如果要合并显示,需要先调整尺寸
# depth_colormap_resized = cv2.resize(depth_colormap, (color_image.shape[1], color_image.shape[0]))
# images = np.hstack((color_image, depth_colormap_resized))
# cv2.imshow('RealSense', images)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
finally:
# Stop streaming
pipeline.stop()
cv2.destroyAllWindows()
如果报pyrealsen2未安装,(注!!!!千万不要在该系统安装,因为会下载最新版本的pyrealsense2,我们的realsense的sdk是48.0,会导致一直报错显示未识别no device connect)
这时我这边儿附上一个pyrealsense2的安装包,在最上面。
下载完成之后我们先进行解压缩,把解压缩之后的文件需要把它移动到/usr/local/lib/python3.8/dist-package里面,之后进入vi ~/.bashrc,添加如下代码:
export PYTHONPATH=$PYTHONPATH:/usr/local/lib:/usr/local/lib/python3.8/dist-packages/pyrealsense2
添加成功之后我们需要使用命令source ~/.bashrc,进行使能。
使能成功之后,我们再次运行代码,应该就会成功显示:
提示:如果报错提示:pipeline.start(config) RuntimeError: Couldn‘t resolve requests
解决这个问题应该调整代码的尺寸大小,配置成如下参数:
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 30)