目录
2.jetson上安装CUDA加速的pyreanselse2库
3.jetson上安装CUDA,cdunn,tensorRT等工具
在官网链接上下载ARM64的Linux的版本,然后解压
tar -xzf pycharm-<version>.tar.gz
进入bin文件夹,终端输入
.sh pycharm.sh
运行
可以在home中新建一个文件夹,命名为
App,把这个文件夹移动到App中
mv ./pycharm-xxxx
在.profile(隐藏文件)中添加export PATH=~/App/pycharm-xxxx(根据自己版本而定)/bin:$PATH,然后source ~/.profile
这样就可以实现终端直接输入.sh pycharm.sh打开pycharm了
2.jetson上按章CUDA加速的pyreanselse2库
如果按照pip install realsense2这样,默认安装的库是不包含CUDA加速的,对齐和获取点云的度较慢,如图
这是需要源码安装CUDA加速的pyreanselse2库,可以实现获取图像和点云以及对齐操作的加速,在jetson上这种CPU性能有限的平台上能提升相机的帧率。
首先安装依赖
sudo apt-get install libssl-dev libusb-1.0-0-dev libudev-dev pkg-config libgtk-3-dev
安装编译工具
sudo apt-get install git wget cmake build-essential
拔下相机连接线,安装
sudo apt-get install libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev at
随便找一个临时文件夹进入
git clone https://github.com/IntelRealSense/librealsense.git
然后
cd librealsense
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON_BINDINGS=ON -DPYTHON_EXECUTABLE=$(which python3) -DBUILD_WITH_CUDA=ON
make -j$(nproc)
这一步中的-DBUILD_WITH_CUDA=ON指定了编译的是CUDA加速版本的,但是在这之前要确认已经安装了CUDA等,详见3.jetson上安装CUDA,cdunn,tensorRT等工具。
注意: 这个过程中有任何报错都可以喂给AI(deepseek,gork,gpt等)解释一下为什么报错,我在不同的平台上遇见过不同的报错,但是都是可以解决的,比如Cmake版本太低,找不到虚拟环境的python,找不到python的动态库文件或者CUDA等,都是可以指定的,按照AI的指引走,应该是能成功的。
make -j$(nproc)之后不要install,没必要。现在已经在Realsense中生成了python的.so文件,只需要在虚拟环境中的site-packages中新建一个文件夹,就叫pyrealsense2,然后把这个文件复制进去
cp ~/librealsense/build/Release/pyrealsense2.cpython-38-aarch64-linux-gnu.so \
***/miniforge-pypy3/envs/***/lib/python3.8/site-packages/pyrealsense2/
按照自己的实际路径修改
然后把这个路径下的.py文件也复制进去
cp ~/librealsense/wrappers/python/pyrealsense2/*.py \
/home/***/miniforge-pypy3/envs/***/lib/python3.8/site-packages/pyrealsense2/
然后在/site-packages/pyrealsense2/中一个.py文件,是_version.py,内容是__version__ = "2.54.1" # 版本号可能不同,(版本号可通过 git describe --tags 在源码目录获取)按照你的版本号来。
最后进入虚拟环境,通过这个程序检查时候安装成功(Deepseek给的检测的方法是错的,不必理会,只要比以前快就是成功了,就拿这个程序测试就行)
我这边实测的速度为
import time
import numpy as np
import pyrealsense2 as rs
import cv2
def init_camera():
"""初始化RealSense相机"""
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
align = rs.align(rs.stream.color)
pipeline.start(config)
return pipeline, align
def get_pixel_coordinates_from_depth(aligned_depth_frame):
"""从深度帧获取点云坐标"""
pc = rs.pointcloud()
points = pc.calculate(aligned_depth_frame)
vtx = np.asanyarray(points.get_vertices())
return np.reshape(vtx, (aligned_depth_frame.get_height(), aligned_depth_frame.get_width(), -1))
def main():
# 初始化相机
pipeline, align = init_camera()
try:
while True:
frame_start = time.time()
# 1. 获取图像帧
get_frame_start = time.time()
frames = pipeline.wait_for_frames()
aligned_frames = align.process(frames)
aligned_depth_frame = aligned_frames.get_depth_frame()
aligned_color_frame = aligned_frames.get_color_frame()
img_color = np.asanyarray(aligned_color_frame.get_data())
get_frame_time = time.time() - get_frame_start
# 2. 计算点云
pointcloud_start = time.time()
point_cloud = get_pixel_coordinates_from_depth(aligned_depth_frame)
pointcloud_time = time.time() - pointcloud_start
# 计算总耗时
total_time = time.time() - frame_start
fps = 1.0 / total_time
# 打印性能数据
print(f"帧获取: {get_frame_time*1000:.1f}ms | "
f"点云计算: {pointcloud_time*1000:.1f}ms | "
f"总耗时: {total_time*1000:.1f}ms | "
f"FPS: {fps:.1f}")
# 显示图像(可选)
cv2.imshow('Color Image', img_color)
if cv2.waitKey(1) & 0xFF in [ord('q'), 27]:
break
finally:
pipeline.stop()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()
3.jetson上安装CUDA,cdunn,tensorRT等工具
jetson有很方便的安装方式(jetpack)
sudo apt update
sudo apt install nvidia--jetpack
这样就自动安装好了,还可以安装jtop实时监控性能
sudo gpt-get install python3-pip
sudo pip3 install -U pip
sudo pip3 install -U jetson-stats
然后可以在终端输入jtop实时监控性能
进入jetson-zoo中,下载对应版本的whl文件,可以在jtop中查看自己的jetpack版本,然后sudo pip3 install ***.whl但是这里install后可能安装到local文件夹下,一样的道理,复制到site-packages中就可以import。
注意:这里如果没有你的版本,向下找一个最近版本,比如我是jetpack5.1.3,python3.8,那么我就选择jetpack5.1.2,python3.8就行。