一般是默认安装的 pyrealsense2 版本太新,移除了对t265的支持。
需要换装 旧版的包,如 v2.51.1 版本的 librealsense 驱动库 可以正常使用。
安装过程
#0)获取 v2.51.1 版本的 librealsense 驱动库(必须)mkdir~/my -p&&cdmy&&pwdgitclone -b v2.51.1 https://github.com/IntelRealSense/librealsense.git# 这里放在了 orangepi的 ~/my/librealsense-R-251/ 这里,已经编译并安装好了,剩下步骤可做参考。#1)安装依赖包sudoapt-getinstalllibudev-dev pkg-config libgtk-3-dev -ysudoapt-getinstalllibusb-1.0-0-dev pkg-config -ysudoapt-getinstalllibglfw3-dev -ysudoapt-getinstalllibssl-dev -y# 出错时,更新源!sudo apt-get update --fix-missing#2)安装权限脚本/ 安装规则文件cdlibrealsensesudocpconfig/99-realsense-libusb.rules /etc/udev/rules.d/sudoudevadm control --reload-rules&&sudoudevadm trigger#3)编译mkdirbuildcdbuild cmake../ -DBUILD_EXAMPLES=true -DBUILD_PYTHON_BINDINGS:bool=true -DPYTHON_EXECUTABLE=$(whichpython3)makemake-j8sudomakeinstall# 遇到 clone <third packages > timeout , 请手动下载 相关库包的<指定版本!>,修改 librealsense/CMake/external_libxxxxx.cmake 改为本地安装# 比如# external_libcurl : 修改 GIT_REPOSITORY "https://github.com/curl/curl.git" 为 URL "/home/orangepi/my/librealsense-R-251/curl.zip", 必须是下面指定的git tag版本的包# 将 特殊的python 动态库包加入 环境变量,避免python找不到包/import失败。echo'export PYTHONPATH="/usr/lib/python3/dist-packages/pyrealsense2:$PYTHONPATH"'>>~/.bashrc#4)使用t265驱动,查看摄像头数据realsense-viewer#5)卸载#dpkg -l | grep "realsense" | cut -d " " -f 3 | xargs sudo dpkg --purg#————————————————#版权声明:本文为CSDN博主「YOULANSHENGMENG」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。#原文链接:https://blog.csdn.net/YOULANSHENGMENG/article/details/129358380留意一下安装日志,这里python的pyrealsense2库包,是默认安装在了/usr/lib/python3.8/site-packages/pyrealsense2。
安装日志: orangepi@orangepi5b:~/my/librealsense-R-251/build$sudomakeinstall[sudo]passwordfororangepi: -- Checking internet connection... -- Internet connection identified -- Info:REALSENSE_VERSION_STRING=2.51.1 -- Setting Unix configurations -- Building libcurl enabled -- using RS2_USE_V4L2_BACKEND -- Configuringdone-- Generatingdone-- Build files have been written to: /home/orangepi/my/librealsense-R-251/build/external-projects/pybind11 make[1]: Entering directory'/home/orangepi/my/librealsense-R-251/build/external-projects/pybind11'make[2]: Entering directory'/home/orangepi/my/librealsense-R-251/build/external-projects/pybind11'make[3]: Entering directory'/home/orangepi/my/librealsense-R-251/build/external-projects/pybind11'make[3]: Leaving directory'/home/orangepi/my/librealsense-R-251/build/external-projects/pybind11'make[3]: Entering directory'/home/orangepi/my/librealsense-R-251/build/external-projects/pybind11'[12%]Performing update stepfor'pybind11'[25%]No configure stepfor'pybind11'[37%]No build stepfor'pybind11'[50%]Noinstallstepfor'pybind11'[62%]Completed'pybind11'make[3]: Leaving directory'/home/orangepi/my/librealsense-R-251/build/external-projects/pybind11'[100%]Built target pybind11 make[2]: Leaving directory'/home/orangepi/my/librealsense-R-251/build/external-projects/pybind11'make[1]: Leaving directory'/home/orangepi/my/librealsense-R-251/build/external-projects/pybind11'-- pybind11 v2.6.2 -- Building with TM2 -- Fetching recommended firmwares: -- D4XX_FW_VERSION:5.13.0.50 -- SR3XX_FW_VERSION:3.26.1.0 -- T26X_FW_VERSION:0.2.0.951 -- L51X_FW_VERSION:1.5.8.1 -- L53X_FW_VERSION:3.5.5.1 -- https://librealsense.intel.com/Releases/RS4xx/FW/D4XX_FW_Image-5.13.0.50.bin -- Download firmware0;"returning early; file already exists with expected SHA1 hash"forD4XX_FW_Image-5.13.0.50.bin -- https://librealsense.intel.com/Releases/SR300/FW/SR3XX_FW_Image-3.26.1.0.bin -- Download firmware0;"returning early; file already exists with expected SHA1 hash"forSR3XX_FW_Image-3.26.1.0.bin -- https://librealsense.intel.com/Releases/TM2/FW/target/0.2.0.951/target-0.2.0.951.mvcmd -- Download firmware0;"returning early; file already exists with expected SHA1 hash"fortarget-0.2.0.951.mvcmd -- https://librealsense.intel.com/Releases/L5xx/FW/L51X_FW_Image-1.5.8.1.bin -- Download firmware0;"returning early; file already exists with expected SHA1 hash"forL51X_FW_Image-1.5.8.1.bin -- https://librealsense.intel.com/Releases/L5xx/FW/L53X_FW_Image-3.5.5.1.bin -- Download firmware0;"returning early; file already exists with expected SHA1 hash"forL53X_FW_Image-3.5.5.1.bin -- Configuringdone-- Generatingdone-- Build files have been written to: /home/orangepi/my/librealsense-R-251/build[3%]Built target fw[13%]Built target realsense-file[71%]Built target realsense2[75%]Built target libcurl[84%]Built target pybackend2[91%]Built target pyrealsense2[93%]Built target rs-convert[93%]Built target rs-enumerate-devices[94%]Built target rs-fw-logger[96%]Built target rs-terminal[97%]Built target rs-record[98%]Built target rs-fw-update[100%]Built target rs-embed Install the project... -- Install configuration:""-- Installing: /usr/local/lib/librealsense2.so.2.51.1 -- Installing: /usr/local/lib/librealsense2.so.2.51 -- Installing: /usr/local/lib/librealsense2.so -- Installing: /usr/local/include/librealsense2 -- Installing: /usr/local/include/librealsense2/h -- Installing: /usr/local/include/librealsense2/h/rs_types.h -- Installing: /usr/local/include/librealsense2/h/rs_sensor.h -- Installing: /usr/local/include/librealsense2/h/rs_record_playback.h -- Installing: /usr/local/include/librealsense2/h/rs_config.h -- Installing: /usr/local/include/librealsense2/h/rs_advanced_mode_command.h -- Installing: /usr/local/include/librealsense2/h/rs_pipeline.h -- Installing: /usr/local/include/librealsense2/h/rs_frame.h -- Installing: /usr/local/include/librealsense2/h/rs_option.h -- Installing: /usr/local/include/librealsense2/h/rs_processing.h -- Installing: /usr/local/include/librealsense2/h/rs_device.h -- Installing: /usr/local/include/librealsense2/h/rs_context.h -- Installing: /usr/local/include/librealsense2/h/rs_internal.h -- Installing: /usr/local/include/librealsense2/rsutil.h -- Installing: /usr/local/include/librealsense2/utilities -- Installing: /usr/local/include/librealsense2/utilities/concurrency -- Installing: /usr/local/include/librealsense2/utilities/concurrency/dispatcher.cpp -- Installing: /usr/local/include/librealsense2/utilities/concurrency/CMakeLists.txt -- Installing: /usr/local/include/librealsense2/utilities/concurrency/concurrency.h -- Installing: /usr/local/include/librealsense2/utilities/time -- Installing: /usr/local/include/librealsense2/utilities/time/periodic-timer.h -- Installing: /usr/local/include/librealsense2/utilities/time/common.h -- Installing: /usr/local/include/librealsense2/utilities/time/CMakeLists.txt -- Installing: /usr/local/include/librealsense2/utilities/time/work-week.h -- Installing: /usr/local/include/librealsense2/utilities/time/stopwatch.h -- Installing: /usr/local/include/librealsense2/utilities/time/work-week.cpp -- Installing: /usr/local/include/librealsense2/utilities/time/timer.h -- Installing: /usr/local/include/librealsense2/utilities/time/waiting-on.h -- Installing: /usr/local/include/librealsense2/utilities/number -- Installing: /usr/local/include/librealsense2/utilities/number/CMakeLists.txt -- Installing: /usr/local/include/librealsense2/utilities/number/stabilized-value.h -- Installing: /usr/local/include/librealsense2/utilities/CMakeLists.txt -- Installing: /usr/local/include/librealsense2/utilities/os -- Installing: /usr/local/include/librealsense2/utilities/os/CMakeLists.txt -- Installing: /usr/local/include/librealsense2/utilities/os/hresult.h -- Installing: /usr/local/include/librealsense2/utilities/string -- Installing: /usr/local/include/librealsense2/utilities/string/windows.h -- Installing: /usr/local/include/librealsense2/utilities/string/CMakeLists.txt -- Installing: /usr/local/include/librealsense2/utilities/string/split.h -- Installing: /usr/local/include/librealsense2/utilities/string/trim-newlines.h -- Installing: /usr/local/include/librealsense2/utilities/string/string-utilities.h -- Installing: /usr/local/include/librealsense2/utilities/easylogging -- Installing: /usr/local/include/librealsense2/utilities/easylogging/CMakeLists.txt -- Installing: /usr/local/include/librealsense2/utilities/easylogging/shared-init.cpp -- Installing: /usr/local/include/librealsense2/utilities/easylogging/easyloggingpp.cmake -- Installing: /usr/local/include/librealsense2/utilities/easylogging/easyloggingpp.h -- Installing: /usr/local/include/librealsense2/rs.hpp -- Installing: /usr/local/include/librealsense2/rs_advanced_mode.hpp -- Installing: /usr/local/include/librealsense2/rs_advanced_mode.h -- Installing: /usr/local/include/librealsense2/rs.h -- Installing: /usr/local/include/librealsense2/hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_sensor.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_types.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_serializable_device.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_frame.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_record_playback.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_context.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_device.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_options.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_processing.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_export.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_pipeline.hpp -- Installing: /usr/local/include/librealsense2/hpp/rs_internal.hpp -- Installing: /usr/local/lib/cmake/realsense2/realsense2Targets.cmake -- Installing: /usr/local/lib/cmake/realsense2/realsense2Targets-noconfig.cmake -- Installing: /usr/local/lib/cmake/realsense2/realsense2Config.cmake -- Installing: /usr/local/lib/cmake/realsense2/realsense2ConfigVersion.cmake -- Installing: /usr/local/lib/pkgconfig/realsense2.pc -- Installing: /usr/local/lib/librealsense-file.a -- Installing: /usr/lib/python3/dist-packages/pyrealsense2/pybackend2.cpython-38-aarch64-linux-gnu.so.2.51.1 -- Installing: /usr/lib/python3/dist-packages/pyrealsense2/pybackend2.cpython-38-aarch64-linux-gnu.so.2 -- Installing: /usr/lib/python3/dist-packages/pyrealsense2/pybackend2.cpython-38-aarch64-linux-gnu.so -- Installing: /usr/lib/python3/dist-packages/pyrealsense2/pyrealsense2.cpython-38-aarch64-linux-gnu.so.2.51.1 -- Installing: /usr/lib/python3/dist-packages/pyrealsense2/pyrealsense2.cpython-38-aarch64-linux-gnu.so.2.51 -- Set runtime path of"/usr/lib/python3/dist-packages/pyrealsense2/pyrealsense2.cpython-38-aarch64-linux-gnu.so.2.51.1"to""-- Installing: /usr/lib/python3/dist-packages/pyrealsense2/pyrealsense2.cpython-38-aarch64-linux-gnu.so -- Installing: /usr/local/lib/cmake/pyrealsense2/pyrealsense2Targets.cmake -- Installing: /usr/local/lib/cmake/pyrealsense2/pyrealsense2Targets-noconfig.cmake -- Installing: /usr/local/lib/cmake/pyrealsense2/pyrealsense2Config.cmake -- Installing: /usr/local/lib/cmake/pyrealsense2/pyrealsense2ConfigVersion.cmake -- Installing: /usr/local/bin/rs-convert -- Set runtime path of"/usr/local/bin/rs-convert"to""-- Installing: /usr/local/bin/rs-enumerate-devices -- Set runtime path of"/usr/local/bin/rs-enumerate-devices"to""-- Installing: /usr/local/bin/rs-fw-logger -- Set runtime path of"/usr/local/bin/rs-fw-logger"to""-- Installing: /usr/local/bin/rs-terminal -- Set runtime path of"/usr/local/bin/rs-terminal"to""-- Installing: /usr/local/bin/rs-record -- Set runtime path of"/usr/local/bin/rs-record"to""-- Installing: /usr/local/bin/rs-fw-update -- Set runtime path of"/usr/local/bin/rs-fw-update"to""-- Installing: /usr/local/bin/rs-embed -- Installing: /usr/local/lib/libfw.a现在使用的是 :pyrealsense2 v2.51.1
在此路径下执行:
export PYTHONPATH="/usr/lib/python3/dist-packages/pyrealsense2:$PYTHONPATH" python3 -c "import pyrealsense2 as rs; print(rs.__version__)"应该可以正常输出 v2.51.1
表明t265驱动包编译安装正常。
解决错误:python3中 import pyrealsense2失败:
echo 'export PYTHONPATH="/usr/lib/python3/dist-packages/pyrealsense2:$PYTHONPATH"' >> ~/.bashrc安装之后的实验现象:
由于udev规则重新加载了,如果读不到t265数据,请重新插拔一次t265接口,让机器识别到。
任意终端执行,可以观察到如下界面弹出
realsense-viewer3D数据图
2D数据图
python3读取t265传感器数据 参考示例
上述过程已经将 c++/python的驱动库 编译并安装好了,现在需要我们测试编程读取t265传感器数据。
https://zhuanlan.zhihu.com/p/441905002 参考此博客指导,可以在之前git clone好的https://github.com/IntelRealSense/librealsense.git 下面找到python示例程序:
位置:librealsense/wrappers/python/examples/
- 获得姿态/加速度信息:
#!/usr/bin/python# -*- coding: utf-8 -*-## License: Apache 2.0. See LICENSE file in root directory.## Copyright(c) 2019 Intel Corporation. All Rights Reserved.####################################################### librealsense T265 example ######################################################## First import the libraryimportpyrealsense2asrs # Declare RealSense pipeline, encapsulating the actual device and sensorspipe=rs.pipeline()# Build config object and request pose datacfg=rs.config()cfg.enable_stream(rs.stream.pose)# Start streaming with requested configpipe.start(cfg)try:for_inrange(50):# Wait for the next set of frames from the cameraframes=pipe.wait_for_frames()# Fetch pose framepose=frames.get_pose_frame()ifpose:# Print some of the pose data to the terminaldata=pose.get_pose_data()print("Frame #{}".format(pose.frame_number))print("Position: {}".format(data.translation))print("Velocity: {}".format(data.velocity))print("Acceleration: {}\n".format(data.acceleration))finally:pipe.stop()- 获得位置信息:
#!/usr/bin/python# -*- coding: utf-8 -*-## License: Apache 2.0. See LICENSE file in root directory.## Copyright(c) 2019 Intel Corporation. All Rights Reserved.####################################################### librealsense T265 rpy example ######################################################## First import the libraryimportpyrealsense2asrsimportmathasm # Declare RealSense pipeline, encapsulating the actual device and sensorspipe=rs.pipeline()# Build config object and request pose datacfg=rs.config()cfg.enable_stream(rs.stream.pose)# Start streaming with requested configpipe.start(cfg)try:while(True):# Wait for the next set of frames from the cameraframes=pipe.wait_for_frames()# Fetch pose framepose=frames.get_pose_frame()ifpose:# Print some of the pose data to the terminaldata=pose.get_pose_data()# Euler angles from pose quaternion# See also https://github.com/IntelRealSense/librealsense/issues/5178#issuecomment-549795232# and https://github.com/IntelRealSense/librealsense/issues/5178#issuecomment-550217609 w=data.rotation.w x=-data.rotation.z y=data.rotation.x z=-data.rotation.y pitch=-m.asin(2.0*(x*z-w*y))*180.0/m.pi;roll=m.atan2(2.0*(w*x+y*z),w*w-x*x-y*y+z*z)*180.0/m.pi;yaw=m.atan2(2.0*(w*z+x*y),w*w+x*x-y*y-z*z)*180.0/m.pi;print("Frame #{}".format(pose.frame_number))print("RPY [deg]: Roll: {0:.7f}, Pitch: {1:.7f}, Yaw: {2:.7f}".format(roll,pitch,yaw)) finally:pipe.stop()解决错误:python3中 import pyrealsense2失败
留意一下安装日志,这里python的pyrealsense2库包,是默认安装在了/usr/lib/python3.8/site-packages/pyrealsense2。
查看一下日志,或者看一下是否有 pyrealsense2 这个包:
ls/usr/lib/python3.8/site-packages|greppyreal*ls/usr/local/lib/python3.8/dist-packages|greppyreal*在/usr/lib/python3.8/site-packages/pyrealsense2路径下打开终端 执行:
python3-c"import pyrealsense2 as rs; print(rs.__version__)"应该可以正常输出 v2.51.1
其他路径下执行该指令,错误/失败:没有pyrealsense2, 或者是rs.__version__不存在
原因:这里的pyrealsense2是cpython package类型的动态库包,如果找不到或者导入失败:
- 需要将 /usr/lib/python3.8/site-packages/pyrealsense2 目录添加到环境变量;
- 或是将 /usr/lib/python3.8/site-packages/pyrealsense2 目录下的动态库复制到项目运行目录。
这里用添加环境变量的方式 修复错误:
- 添加用户级path:
echo'export PYTHONPATH=$PYTHONPATH:/usr/lib/python3.8/site-packages/pyrealsense2'>>~/.bashrccat~/.bashrc|greppyrealsense2source~/.bashrc- root级path: 可选,如果项目用root用户执行,需要添加
sudoecho'export PYTHONPATH=$PYTHONPATH:/usr/lib/python3.8/site-packages/pyrealsense2'>>/root/.bashrccat/root/.bashrc|greppyrealsense2sudosource/root/.bashrc因为用到sudo 启动服务,所以最好也添加,或是在启动用的bash脚本内加上:
export PYTHONPATH=$PYTHONPATH:/usr/lib/python3.8/site-packages/pyrealsense2参考文档:
- github: https://github.com/realsenseai/librealsense/tree/development/wrappers/python#building-from-source
- 知乎: https://zhuanlan.zhihu.com/p/441905002
- csdn: https://blog.csdn.net/YOULANSHENGMENG/article/details/12935838