【Intel® RealSense™ SDK 2.0 】在【Linux】环境配置记录
系统环境
ubuntu 18.04
建conda环境
conda create -n real_sense python=3.7
conda activate real_sense
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple scikit-build
pip3 install opencv-contrib-python -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install numpy
pip3 install PyQt5 -i https://pypi.douban.com/simple
pip3 install PyQt5-tools -i https://pypi.douban.com/simple
Real_Sense SDK 2.0 Ubuntu X86/AMD64 的 Debian 安装包
官方Linux 发行版SDK安装指南
Linux Ubuntu 编译安装
-
使 Ubuntu 保持最新:
更新 Ubuntu 发行版,包括获取最新的稳定内核:
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade -
安装软件包:
注册服务器的公钥:sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE
如果仍然无法检索到公钥,请检查并指定代理设置:export http_proxy=“http://:”
,然后重新运行该命令。请参阅以下链接中的其他方法。 -
将服务器添加到存储库列表中:
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以上两行将部署 librealsense2 udev 规则,构建和激活内核模块,运行时库和可执行演示和工具。
可选择安装开发人员和调试包:安装包后,您可以
sudo apt-get install librealsense2-dev
sudo apt-get install librealsense2-dbg重新连接英特尔实感深度摄像头并运行:
realsense-viewer
以验证安装。
Python库的安装和调用
pip install pyrealsense2
官方例程(已修改)
# First import the library
import pyrealsense2 as rs
import numpy as np
# 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()
depth_data = depth.as_frame().get_data()
np_image = np.asanyarray(depth_data)
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): # 每行检测640个点
dist = depth.get_distance(x, y) # 在给定的像素处提供以米为单位的深度
if 0 < dist and dist < 1:
coverage[x // 10] += 1 # x上每10个点对应一个要打印的深度记录
if y % 20 == 19: # 每20个y打印一次
line = ""
for c in coverage:
line += " .:nhBXWW"[c // 25] # 根据深度记录打印不同字符
coverage = [0] * 64
print(line)
finally:
pipeline.stop()
```
## 参考文献:
[Ubuntu 18.04 ———(Intel RealSense D435i)安装相机的驱动librealsense + realsense-ros](https://blog.csdn.net/qq_38364548/article/details/124784454)