方法一:在工作空间中的src文件夹下
git clone https://github.com/IntelRealSense/realsense-ros.git
编译、然后更新一下source ~/.bashrc
方法二(成功)
sudo apt install ros-noetic-realsense2-camera
sudo apt install ros-noetic-realsense2-description
roslaunch realsense2_camera rs_camera.launch#启动相机
roslaunch realsense2_camera demo_pointcloud.launch #点云deemo
rqt_image_view #rqt查看图像
即可启动RealSense的ROS节点。
pip install pyrealsense2
注意是python2环境下的。
ros-noetic:
sudo apt install python3-opencv
或者
pip install opencv-python #指定版本 pip install opencv-python==3.4.3.18
melodic:
sudo apt-get install ros-melodic-vision-opencv libopencv-dev python-opencv
这个是标定需要的功能包,相机功能包在前面已经安装
sudo apt-get install ros-noetic-camera-calibration
打开d435i
roslaunch realsense2_camera rs_camera.launch
使用标定
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.025 image:=/camera/color/image_raw camera:=/camera --no-service-check
踩个坑,使用标定的时候发生
Traceback (most recent call last):
File "cameracalibrator.py", line 37, in <module>
import message_filters
File "/opt/ros/noetic/lib/python3/dist-packages/message_filters/__init__.py", line 35, in <module>
import rospy
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/__init__.py", line 49, in <module>
from .client import spin, myargv, init_node, \
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/client.py", line 60, in <module>
import rospy.impl.init
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/init.py", line 54, in <module>
from .tcpros import init_tcpros
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros.py", line 45, in <module>
import rospy.impl.tcpros_service
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_service.py", line 54, in <module>
from rospy.impl.tcpros_base import TCPROSTransport, TCPROSTransportProtocol, \
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 167
(e_errno, msg, *_) = e.args
^
SyntaxError: invalid syntax
简而言之这个错误发生的原因是python解释器,使用python2的解释器来解释这个py文件,可以将系统默认的解释器设置为python3
sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3 2 auto mode
1 /usr/bin/python2 1 manual mode
2 /usr/bin/python3 2 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
输入 2
详情:https://answers.ros.org/question/368457/do-i-have-an-error-with-rospy-file-tcpros_basepy/
注意:若使用虚拟机,需将 虚拟机设置/USB控制/USB兼容性 设置为USB3.1,由相机的SuperSpeedUSB决定。
可参考find_object_2d官方文档
启动:(image:=/camera/color/image_raw 为指定订阅image topic)
#启动相机
roslaunch realsense2_camera rs_camera.launch
#启动find_object_2d节点,并指定订阅话题
rosrun find_object_2d find_object_2d image:=/camera/color/image_raw
首先修改启动launch文件:
find_object_2d/launch文件夹中,find_object_3d.launch复制粘贴一份在该文件夹中,重命名为find_object_3d_d435i.launch。
修改:
<arg name="rgb_topic" default="camera/rgb/image_rect_color"/>
<arg name="depth_topic" default="camera/depth_registered/image_raw"/>
<arg name="camera_info_topic" default="camera/rgb/camera_info"/>
为:
<arg name="rgb_topic" default="/camera/color/image_raw"/>
<arg name="depth_topic" default="/camera/depth/image_rect_raw"/>
<arg name="camera_info_topic" default="/camera/depth/camera_info"/>
这是修改订阅的话题名称,三个参数是话题名称,分别是rgb图像、深度图像、相机信息,这个三个信息在d435i中分别由话题/camera/color/image_raw、camera/depth/image_rect_raw、/camera/depth/camera_info对应发布。
启动:
roslaunch realsense2_camera rs_camera.launch
roslaunch find_object_2d find_object_3d_d435i.launch