Jetson nano 部署 librealsense

Created: July 13, 2023 12:08 AM
Created by: Luser
Type: AI、Jetson nano

Jetson nano 换源

Jetson设备默认的apt镜像源在海外,所以需要用国内的源代替海外源

Jetson处理器是aarch64类型的,常用的arm64换源教程不能用!

要使用与之匹配的源,国内aarch64的源有的连不上,有的包无法安装,好多网上Jetson Nano的换源教程都用不了,下面的这个清华大学的源完美可用:

1.先备份原本的source.list文件

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak  

2.修改source

进入source.list

sudo gedit /etc/apt/sources.list

按"i"开始输入,然后删除所有内容,复制进下面的

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe

“Esc”结束输入,“:wq!”保存退出

3.更新软件列表,保存在本地

sudo apt-get update

如果需要,可以更新软件:

sudo apt-get upgrade

安装依赖

sudo apt-get install git cmake libssl-dev libusb-1.0-0-dev pkg-config libgtk-3-dev libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev

下载Realsense SDK

因为需要同时支持D455与T265,并且T265已经停产了,realsense v2.54.1 以后不再支持T265,故需下载 2.53.1版同时支持D455与T265:

git clone -b v2.53.1 https://github.com/IntelRealSense/librealsense.git

编译准备

cmake 后面的命令是想要编译时配置好pyrealsense2环境

cd librealsense
mkdir build && cd build
cmake ../ -DBUILD_PYTHON_BINDINGS:bool=true -DPYTHON_EXECUTABLE=/usr/bin/python3 -DBUILD_WITH_CUDA=true

运行cmake时不要自行设置参数!!不然很可能会不能运行相机。

编译与安装

make
sudo make install

树莓派使用make -j进行多线程编译可能有点压力,使用单线程编译就好

编译过程中可能遇到的错误

1:Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the

$ sudo apt-get install libssl-dev

2:The Xinerama headers were not found

$ sudo apt-get install libsdl2-dev

3:/home/***/projects/librealsense/build/third-party/pybind11/include/pybind11/detail/common.h:124:10: fatal error: Python.h: No such file or directory,CMakeFiles/Makefile2:268: recipe for target 'wrappers/python/CMakeFiles/pybackend2.dir/all' failed

$ sudo apt-get install python3.6-dev

设置udev规则

运行项目中scripts目录下的setup_udev_rules.sh就好:

sudo sh ./scripts/setup_udev_rules.sh
echo 'hid_sensor_custom' | sudo tee -a /etc/modules

添加环境变量

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

验证安装

将T265通过USB连接到树莓派上(要连蓝色接口的USB3.0),然后运行下面这个代码。

rs-enumerate-devices

只要能输出信息,而不是说没有设备插入,那就是成功了。

测试

sudo realsense-viewer

pyrealsense2的问题

编译完SDK后,C++的realsense环境可以正常使用和运行,但是python的pyrealsense2却无法被python正确找到,经过测试后发现解决办法:

在librealsense编译完后会在build目录中生成python的链接库,将其手动添加到python的import搜索路径中就可以被正确链接到了:

找到编译完后生成的.so文件:

https://cdn.jsdelivr.net/gh/luserli/figure/photos/202307152105499.png

获取import的默认搜索路径:

https://cdn.jsdelivr.net/gh/luserli/figure/photos/202307152107468.png

将生成的pyrealsense2.cpython-36m-aarch64-linux-gnu.so文件copy到上面获取到的任一个目录中即可,这里放到'/usr/lib/python3.6'中

cp pyrealsense2.cpython-36m-aarch64-linux-gnu.so /usr/lib/python3.6