小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
用笔记本自带摄像头 奥比中光深度摄像头跑通ros1单目 rgbd
-
环境:ubuntu20.4 ros1 noetic
奥比中光 Astra Pro RGBD深度摄像头。
联想think pad x230自带摄像头
前提:摄像头节点配置好,能够发布摄像头图像话题,orb_slam3编译成功,可以跑通自带的数据集。没有安装好请参考:
https://fishros.org.cn/forum/topic/842/视觉slam-orb_slam3在ubuntu18-04-ubuntu20-04-安装运行测试https://fishros.org.cn/forum/topic/1118/ubuntu20-4-ros1noetic-安装奥比中光-astra-pro-rgbd摄像头
orb_slam3 适配单目 双目 rgbd摄像头,最容易跑通的是单目,用笔记本自带的摄像头只需修改一下话题,就能启动。ros_mono.cc //单目主程序
/** * This file is part of ORB-SLAM3 * * Copyright (C) 2017-2021 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza. * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza. * * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public * License as published by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with ORB-SLAM3. * If not, see <http://www.gnu.org/licenses/>. */ #include<iostream> #include<algorithm> #include<fstream> #include<chrono> #include<ros/ros.h> #include <cv_bridge/cv_bridge.h> #include<opencv2/core/core.hpp> #include"../../../include/System.h" using namespace std; class ImageGrabber { public: ImageGrabber(ORB_SLAM3::System* pSLAM):mpSLAM(pSLAM){} void GrabImage(const sensor_msgs::ImageConstPtr& msg); ORB_SLAM3::System* mpSLAM; }; int main(int argc, char **argv) { ros::init(argc, argv, "Mono"); ros::start(); if(argc != 3) { cerr << endl << "Usage: rosrun ORB_SLAM3 Mono path_to_vocabulary path_to_settings" << endl; ros::shutdown(); return 1; } // Create SLAM system. It initializes all system threads and gets ready to process frames. ORB_SLAM3::System SLAM(argv[1],argv[2],ORB_SLAM3::System::MONOCULAR,true); ImageGrabber igb(&SLAM); ros::NodeHandle nodeHandler; //ros::Subscriber sub = nodeHandler.subscribe("/camera/image_raw", 1, &ImageGrabber::GrabImage,&igb);//原 ros::Subscriber sub = nodeHandler.subscribe("/camera/color/image_raw", 1, &ImageGrabber::GrabImage,&igb); ros::spin(); // Stop all threads SLAM.Shutdown(); // Save camera trajectory SLAM.SaveKeyFrameTrajectoryTUM("KeyFrameTrajectory.txt"); ros::shutdown(); return 0; } void ImageGrabber::GrabImage(const sensor_msgs::ImageConstPtr& msg) { // Copy the ros image message to cv::Mat. cv_bridge::CvImageConstPtr cv_ptr; try { cv_ptr = cv_bridge::toCvShare(msg); } catch (cv_bridge::Exception& e) { ROS_ERROR("cv_bridge exception: %s", e.what()); return; } mpSLAM->TrackMonocular(cv_ptr->image,cv_ptr->header.stamp.toSec()); }
改动的地方:
1.把主程序原来的接收topic /camera/image_raw改成 /usb_cam/image_raw"笔记本摄像头发布的话题
ros::NodeHandle nodeHandler;
//ros::Subscriber sub = nodeHandler.subscribe("/camera/image_raw", 1, &ImageGrabber::GrabImage,&igb);//原
ros::Subscriber sub = nodeHandler.subscribe("/usb_cam/image_raw", 1, &ImageGrabber::GrabImage,&igb);
ros::spin();
2安装启动摄像头
sudo apt-get install ros-noetic-usb-cam //安装摄像头驱动
roscore //启动ros核心
rosrun usb_cam usb_cam_node //启动摄像头节点
3启动单目节点
摄像头配置文件先用程序自带的,目的是先跑起来,过后在标定摄像头。
cd ORB_SLAM3
rosrun ORB_SLAM3 Mono ./Vocabulary/ORBvoc.txt ./Examples/Monocular/EuRoC.yaml
如果一切顺利,就应该能启动了,只是我的笔记本有点太老了,有点卡,但是能看到程序能正常运行了。
rgbd主程序:
ros_rgbd.cc/** * This file is part of ORB-SLAM3 * * Copyright (C) 2017-2021 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza. * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza. * * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public * License as published by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with ORB-SLAM3. * If not, see <http://www.gnu.org/licenses/>. */ #include<iostream> #include<algorithm> #include<fstream> #include<chrono> #include<ros/ros.h> #include <cv_bridge/cv_bridge.h> #include <message_filters/subscriber.h> #include <message_filters/time_synchronizer.h> #include <message_filters/sync_policies/approximate_time.h> #include<opencv2/core/core.hpp> #include"../../../include/System.h" using namespace std; class ImageGrabber { public: ImageGrabber(ORB_SLAM3::System* pSLAM):mpSLAM(pSLAM){} void GrabRGBD(const sensor_msgs::ImageConstPtr& msgRGB,const sensor_msgs::ImageConstPtr& msgD); ORB_SLAM3::System* mpSLAM; }; int main(int argc, char **argv) { ros::init(argc, argv, "RGBD"); ros::start(); if(argc != 3) { cerr << endl << "Usage: rosrun ORB_SLAM3 RGBD path_to_vocabulary path_to_settings" << endl; ros::shutdown(); return 1; } // Create SLAM system. It initializes all system threads and gets ready to process frames. ORB_SLAM3::System SLAM(argv[1],argv[2],ORB_SLAM3::System::RGBD,true); ImageGrabber igb(&SLAM); ros::NodeHandle nh; // message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/camera/rgb/image_raw", 100); // message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "camera/depth_registered/image_raw", 100); message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/camera/color/image_raw", 100); message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "/camera/depth/image_raw", 100); typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image> sync_pol; message_filters::Synchronizer<sync_pol> sync(sync_pol(10), rgb_sub,depth_sub); sync.registerCallback(boost::bind(&ImageGrabber::GrabRGBD,&igb,_1,_2)); ros::spin(); // Stop all threads SLAM.Shutdown(); // Save camera trajectory SLAM.SaveKeyFrameTrajectoryTUM("KeyFrameTrajectory.txt"); ros::shutdown(); return 0; } void ImageGrabber::GrabRGBD(const sensor_msgs::ImageConstPtr& msgRGB,const sensor_msgs::ImageConstPtr& msgD) { // Copy the ros image message to cv::Mat. cv_bridge::CvImageConstPtr cv_ptrRGB; try { cv_ptrRGB = cv_bridge::toCvShare(msgRGB); } catch (cv_bridge::Exception& e) { ROS_ERROR("cv_bridge exception: %s", e.what()); return; } cv_bridge::CvImageConstPtr cv_ptrD; try { cv_ptrD = cv_bridge::toCvShare(msgD); } catch (cv_bridge::Exception& e) { ROS_ERROR("cv_bridge exception: %s", e.what()); return; } mpSLAM->TrackRGBD(cv_ptrRGB->image,cv_ptrD->image,cv_ptrRGB->header.stamp.toSec()); }
修改orb_slam3话题为自己的rgbd相机话题
message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/camera/color/image_raw", 100);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "/camera/depth/image_raw", 100);启动rgbd摄像头
. devel/setup.bash
roslaunch astra_camera astra_pro.launchm@r:~$ rostopic list
/camera/color/camera_info
/camera/color/image_raw
/camera/depth/camera_info
/camera/depth/image_raw
/camera/depth/points
/camera/depth_registered/points
/camera/extrinsic/depth_to_color
/camera/ir/camera_info
/camera/ir/image_raw
/camera/reset_device
/rosout
/rosout_agg
/tf
/tf_static
启动rgbd主程序 (摄像头都没有标定,用的程序自带的配置文件)
cd ORB_SLAM3
rosrun ORB_SLAM3 RGBD ./Vocabulary/ORBvoc.txt ./Examples_old/ROS/ORB_SLAM3/Asus.yaml
程序能跑起来了,要想数据准确,需要给摄像头作标定,rgbd深度摄像头计算量应该是比单目的小,运行比较流畅。