Intel realSense ubuntu 16.04+python 环境配置指南

时间:2023-03-09 04:16:27
Intel realSense ubuntu 16.04+python 环境配置指南

1. 安装librealsense2-dkms 以及librealsense2-utils

1、Register the server's public key:
sudo apt-key adv --keyserver keys.gnupg.net --recv-key C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C8B3A55A6F3EFCDE

(In case the public key still cannot be retrieved, check and specify proxy settings: export http_proxy="http://<proxy>:<port>"
, and rerun the command. See additional methods in the following link.) 2、Add the server to the list of repositories:
Ubuntu LTS:
sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial main" -u
Ubuntu LTS:
sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo bionic main" -u 3、Install the libraries (see section below if upgrading packages):
sudo apt-get install librealsense2-dkms
sudo apt-get install librealsense2-utils
The above two lines will deploy librealsense2 udev rules, build and activate kernel modules, runtime library and executable demos and tools. Reconnect the Intel RealSense depth camera and run: realsense-viewer to verify the installation.

配置好了之后 输入realSense-viewer是这个样子~

Intel realSense ubuntu 16.04+python 环境配置指南

2. 配置warpper----python环境

下载https://github.com/IntelRealSense/librealsense项目到本地

  

Building From Source Ubuntu 14.04/16.04 LTS Ensure apt-get is up to date
1、sudo apt-get update && sudo apt-get upgrade
Note: Use sudo apt-get dist-upgrade, instead of sudo apt-get upgrade, in case you have an older Ubuntu 14.04 version
Install Python and its development files via apt-get (Python and both work)

2、sudo apt-get install python python-dev or sudo apt-get install python3 python3-dev
Note: The project will only use Python if it can't use Python 3
Run the top level CMake command with the following additional flag -DBUILD_PYTHON_BINDINGS=bool:true: 3、mkdir build
cd build
cmake ../ -DBUILD_PYTHON_BINDINGS=bool:true
Note: To force compilation with a specific version on a system with both Python and Python installed, add the following flag to CMake command: -DPYTHON_EXECUTABLE=[full path to the exact python executable]
(cmake常用套路了)
make -j4
sudo make install
4、update your PYTHONPATH environment variable to add the path to the pyrealsense library
export PYTHONPATH=$PYTHONPATH:/usr/local/lib Alternatively, copy the build output (librealsense2.so and pyrealsense2.so) next to your script.
Note: Python module filenames may contain additional information, e.g. pyrealsense2.cpython-35m-arm-linux-gnueabihf.so)

Python 接口使用的例子:

# First import the library
import pyrealsense2 as rs try:
# Create a context object. This object owns the handles to all connected realsense devices
pipeline = rs.pipeline()
pipeline.start() 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 = []*
for y in xrange():
for x in xrange():
dist = depth.get_distance(x, y)
if < dist and dist < :
coverage[x/] += if y% is :
line = ""
for c in coverage:
line += " .:nhBXWW"[c/]
coverage = []*
print(line)