基于ORB-SLAM3库搭建SLAM系统 详见之前的博客
参考链接
打开终端输入指令: vim ~/.bashrc 打开用户根目录下的.bashrc文件
添加ROS功能包路径 export
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/yehuo/SLAM/ORB_SLAM3-master/Examples/ROS
此处路径需要根据每个人放置功能包的位置进行调整,不能直接复制
chmod +x build_ros.sh ##修改Build_ros.sh权限
./build_ros.sh ##安装 orb_slam 中的 ros模块
#!/usr/bin/env python
#!coding-utf -8
import rospy
from sensor_msgs.msg import Image
import cv2
from cv_bridge import CvBridge
import sys
def webcamImagePub():
rospy.init_node('cam_pub',anonymous=True)
img_pub = rospy.Publisher('camera/image_raw',Image,queue_size=2)
rate = rospy.Rate(20)
cap = cv2.VideoCapture(0)
scaling_factor = 0.3
bridge = CvBridge()
if not cap.isOpened():
sys.stdout.write("zzz")
return -1
count = 0
while not rospy.is_shutdown():
ret,frame = cap.read()
if ret:
count = count + 1
else:
rospy.loginfo("xxx")
if count == 2:
count = 0
msg = bridge.cv2_to_imgmsg(frame)
img_pub.publish(msg)
print("yyy")
rate.sleep()
if __name__ == '__main__':
try:
webcamImagePub()
except rospy.ROSInterruptException:
pass
将camera.py放入 /Examples/ROS/ORB_SLAM3/scripts/ 文件夹下,(scripts文件夹需要自己创建)
打开终端执行 chmod+x camera.py 赋予可执行权限
打开终端
执行 roscore
打开新的终端
执行 rosrun ORB_SLAM3 camera.py
在以下路径下打开终端
在终端输入以下指令 === 注意修改路径
rosrun ORB_SLAM3 Mono /home/yehuo/SLAM/ORB_SLAM3-master/Vocabulary/ORBvoc.txt /home/yehuo/SLAM/ORB_SLAM3-master/Examples/Monocular/TUM1.yaml
解决方法,参考以下链接
解决办法,参考以下链接