一、环境配置

github上面的教程:https://github.com/IntelRealSense/librealsense/blob/master/doc/distribution_linux.md

比较完整的配置博客:

https://blog.csdn.net/wanghq2013/article/details/123325671

https://blog.csdn.net/jiexijihe945/article/details/126163341

1、首先按照Installing the packages进行环境配置

  • 注册服务器的公钥:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE
  • 将服务器添加到存储库列表:
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

由于dev包已经安装,你可以编译一个应用使用librealsense,通过命令g++ -std=c++11 filename.cpp -lrealsense2或别的IDE来编译具有librealsense的应用

重新连接英特尔实感深度摄像头并运行:realsense-viewer 以验证安装。

验证内核是否已更新:

modinfo uvcvideo | grep "version:" 应包括realsense字符。

2、卸载库文件

重要仅当没有其他已安装的软件包直接引用它时才允许删除 Debian 软件包。

例如删除 librealsense2-udev-rules 需要先删除 librealsense2

卸载一个单独的包使用命令:

sudo apt-get purge <package-name>

移除所有Realense 相关的SDK包使用:

dpkg -l | grep "realsense" | cut -d " " -f 3 | xargs sudo dpkg --purge

3、报错

使用realsense-viewer命令打开界面出现cannot access /sys/access/video4linux

这边出现的问题是刚才安装dkms需要编译linux的内核相关,而重启之后没有选择更改内核的选项,所有出现了问题。

正确的做法是安装dkms之后重启以下,重启的时候会出现爱你UEFI Secure Boot的要求,

UEFI Secure boot是一种验证机制,确保固件启动的代码是可信的

要输入secure boot密码的情况:

重启电脑时perfrom mok management,出现蓝屏的MOK management,具体的解决办法如下:

  1. 当进入蓝色背景的界面perform mok management后,选择 enroll mok,
  2. 进入enroll mok界面,选择 continue,
  3. 进入enroll the key界面,选择yes,
  4. 接下来输入你在安装驱动时输入的密码
  5. 之后会跳到蓝色背景的界面perform mok management选择第一个reboot

https://www.cnblogs.com/yutian-blogs/p/13019226.html

4、ROS下使用

https://github.com/IntelRealSense/realsense-ros/tree/ros1-legacy

在ubuntu下使用

第一步就是刚才写的安装sdk

第二步从源码安装

  • 在ubuntu下创建工作空间
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src/
  • 拷贝最新的realsense包到这个空间
git clone https://github.com/IntelRealSense/realsense-ros.git
cd realsense-ros/
git checkout `git tag | sort -V | grep -P "^2.\d+\.\d+" | tail -1`
cd ..
  • 确保已经安装了ddynamic_reconfigure,没有安装的话从https://github.com/pal-robotics/ddynamic_reconfigure/tree/kinetic-devel此处git到src目录下。

  • 接着运行

catkin_init_workspace
cd ..
catkin_make clean
catkin_make -DCATKIN_ENABLE_TESTING=False -DCMAKE_BUILD_TYPE=Release
catkin_make install
  • 在ubuntu下添加启动
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
  • 启动节点测试

    开启摄像头节点:
roslaunch realsense2_camera rs_camera.launch

然后打开rviz选择摄像头以及DepthCloud就能进行显示了。

  • 还可以直接使用rgbd-launch进行测试

    rgbd_launch是一组打开RGBD设备,并load 所有nodelets转化 raw depth/RGB/IR 流到深度图(depth image), 视差图(disparity image)和点云(point clouds)的launch文件集。
    sudo apt-get install ros-noetic-rgbd-launch

    测试

    roslaunch realsense2_camera demo_pointcloud.launch

二、使用

useage1

https://blog.csdn.net/wanghq2013/article/details/123325671

上面博客中自己的使用是将img_viewer.cpp中的节点改成realsense的RGB图片或者深度图片,如果是深度图片,需要将cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);中的rgb8改成16UC1

也就是调用realsense发布的节点用的是realsense自己的,

roslaunch realsense2_camera rs_camera.launch

订阅节点用的是上面的img_viewer.cpp

另外自己使用的时候用的是rosOpenCV

以下是自己的package.xml

点击查看代码
<?xml version="1.0"?>
<package format="2">
<name>myRealSenseTest</name>
<version>0.0.0</version>
<description>The myRealSenseTest package</description> <!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
<maintainer email="bck20@todo.todo">bck20</maintainer> <!-- One license tag required, multiple allowed, one license per tag -->
<!-- Commonly used license strings: -->
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
<license>TODO</license> <!-- Url tags are optional, but multiple are allowed, one per tag -->
<!-- Optional attribute type can be: website, bugtracker, or repository -->
<!-- Example: -->
<!-- <url type="website">http://wiki.ros.org/myRealSenseTest</url> --> <!-- Author tags are optional, multiple are allowed, one per tag -->
<!-- Authors do not have to be maintainers, but could be -->
<!-- Example: -->
<!-- <author email="jane.doe@example.com">Jane Doe</author> --> <!-- The *depend tags are used to specify dependencies -->
<!-- Dependencies can be catkin packages or system dependencies -->
<!-- Examples: -->
<!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
<!-- <depend>roscpp</depend> -->
<!-- Note that this is equivalent to the following: -->
<!-- <build_depend>roscpp</build_depend> -->
<!-- <exec_depend>roscpp</exec_depend> -->
<!-- Use build_depend for packages you need at compile time: -->
<!-- <build_depend>message_generation</build_depend> -->
<!-- Use build_export_depend for packages you need in order to build against this package: -->
<!-- <build_export_depend>message_generation</build_export_depend> -->
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
<!-- Use exec_depend for packages you need at runtime: -->
<!-- <exec_depend>message_runtime</exec_depend> -->
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->
<!-- Use doc_depend for packages you need only for building documentation: -->
<!-- <doc_depend>doxygen</doc_depend> -->
<buildtool_depend>catkin</buildtool_depend>
<build_depend>cv_bridge</build_depend>
<build_depend>image_transport</build_depend>
<build_depend>rosOpenCV</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>std_msgs</build_depend>
<build_export_depend>cv_bridge</build_export_depend>
<build_export_depend>image_transport</build_export_depend>
<build_export_depend>rosOpenCV</build_export_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>sensor_msgs</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<exec_depend>cv_bridge</exec_depend>
<exec_depend>image_transport</exec_depend>
<exec_depend>rosOpenCV</exec_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>std_msgs</exec_depend> <!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here --> </export>
</package>

img_viewer.cpp

点击查看代码
//接收并查看图像消息的节点img_viewer.cpp
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h> //依赖包有std_msgs(消息传递),roscpp(c++),cv_bridge(ros和opencv图像消息转换),sensor_msgs(传感器消息),image_transport(图像编码传输)
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
try
{
cv::imshow("view", cv_bridge::toCvShare(msg, "16UC1")->image);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("Could not convert from '%s' to '16UC1'.", msg->encoding.c_str());
}
} int main(int argc, char **argv)
{
ros::init(argc, argv, "img_viewer");
ros::NodeHandle nh;
cv::namedWindow("view");
cv::startWindowThread();
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub = it.subscribe("camera/depth/image_rect_raw", 0, imageCallback);
ros::spin();
cv::destroyWindow("view");
return 0;
}

CMakeLists.txt

点击查看代码
cmake_minimum_required(VERSION 3.0.2)
project(myRealSenseTest) ## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11) ## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
roscpp
sensor_msgs
std_msgs
) ## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system) # find_package(OpenCV REQUIRED)
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup() ################################################
## Declare ROS messages, services and actions ##
################################################ ## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) ## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# ) ## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# ) ## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# ) ## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# sensor_msgs# std_msgs
# ) ################################################
## Declare ROS dynamic reconfigure parameters ##
################################################ ## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed ## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
# cfg/DynReconf1.cfg
# cfg/DynReconf2.cfg
# ) ###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES myRealSenseTest
# CATKIN_DEPENDS cv_bridge image_transport opencv2 roscpp sensor_msgs std_msgs
# DEPENDS system_lib
) ###########
## Build ##
########### ## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
${catkin_INCLUDE_DIRS}
) ## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/myRealSenseTest.cpp
# ) ## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) ## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/myRealSenseTest_node.cpp) ## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "") ## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) ## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
# ${catkin_LIBRARIES}
# ) add_executable(img_publisher src/img_publisher.cpp)
target_link_libraries(img_publisher ${catkin_LIBRARIES} ) add_executable(img_viewer src/img_viewer.cpp)
target_link_libraries(img_viewer ${catkin_LIBRARIES}) #############
## Install ##
############# # all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html ## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# catkin_install_python(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# ) ## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# ) ## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# ) ## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# ) ## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# ) #############
## Testing ##
############# ## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_myRealSenseTest.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif() ## Add folders to be run by python nosetests
# catkin_add_nosetests(test)

usage2

https://blog.csdn.net/zkk9527/article/details/108224128

usage3

从深度相机生成pcl点云:https://dontla.blog.csdn.net/article/details/102608417

最新文章

  1. EDM博主笔记:EDM邮件营销的几个细节问题
  2. 终极事务处理(XTP,Hekaton)——万能大招?
  3. C# - DataValid数据验证类
  4. hadoop的live node为0
  5. luigi学习8--使用中央调度器
  6. Nand flash uboot 命令详解【转】
  7. 关于div 浮动在select,或table控件之上
  8. &lt;1&gt;数据引用与匿名存储
  9. destoon实现底部添加你是第几位访问者的方法
  10. javascript学习(10)——[知识储备]链式调用
  11. 系统里有Courier New字体 Eclipse没有这个字体选项
  12. HDU 6311 Cover (无向图最小路径覆盖)
  13. win2008安装并配置zabbix3.4 agent
  14. 批处理for中字符串截取必须先把循环变量代替出来才行!!!
  15. 持续集成工具之Jenkins
  16. vsCode如何从github拉取项目
  17. Codesmith怎么判断sqlserver数据库字段是不是标识自增字段
  18. C++并发编程 条件变量 condition_variable,线程安全队列示例
  19. Beta阶段展示博客
  20. 前端(十):使用redux管理数据

热门文章

  1. Java最全八股文(2023最新整理)
  2. Cookie参数、Header参数
  3. 和头条Jim博士的对话
  4. Win10 局域网共享文件遇到的疑难杂症通用解决策略
  5. 【NOIP2012提高组】开车旅行
  6. Linux命令-用户、权限管理
  7. 自己动手从零写桌面操作系统GrapeOS系列教程——7.计算机组成与运行原理
  8. [C#]为debug添加DebuggerDisplay属性
  9. Linux系统下追加记录到文件中的实例代码解读
  10. Windows Python2.7环境 安装paramiko模块(转)