Segmentation fault.
i am try to learn the dynamic slam and the code are base on the https://github.com/bijustin/YOLO-Dyna... and it is base on orbslam2 , i use the tum dataset to test is success , but i try to run on ROS the terminal print the Segmentation fault when i use the rosbag provide by tum dataset. i have no idea to solve it.
#include<iostream>
#include<algorithm>
#include<fstream>
#include<chrono>
#include<opencv2/core/core.hpp>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/image_encodings.h>
#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"../../../include/System.h"
#include "../../../include/Geometry.h"
#include "../../../include/MaskNet.h"
#include "../../../include/yolo.h"
using namespace std;
class ImageGrabber
{
public:
ImageGrabber(ORB_SLAM2::System* pSLAM):mpSLAM(pSLAM){}
void GrabRGBD(const sensor_msgs::ImageConstPtr& msgRGB,const sensor_msgs::ImageConstPtr& msgD);
ORB_SLAM2::System* mpSLAM;
};
int main(int argc, char **argv)
{
ros::init(argc, argv, "RGBD");
ros::start();
// Initialize Mask R-CNN
//DynaSLAM::SegmentDynObject *MaskNet;
ORB_SLAM2::System SLAM(argv[1],argv[2],ORB_SLAM2::System::RGBD,true);
//選擇是否要加載先前儲存的地圖
char IsLoadMap;
cout << "Do you want to load the map?(y/n)" << endl;
cin >> IsLoadMap;
if(IsLoadMap == 'Y' || IsLoadMap == 'y')
{
SLAM.LoadMap("/home/henry/henry_ws/src/YOLO-DynaSLAM/map.bin");
}
ImageGrabber igb(&SLAM);
ros::NodeHandle nh;
message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh,"/camera/rgb/image_color", 1);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh,"/camera/depth/image", 1);
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();
SLAM.Shutdown();
char IsSaveMap;
cout << "Do you want to save the map?(y/n)" << endl;
cin >> IsSaveMap;
if(IsSaveMap == 'Y' || IsSaveMap == 'y')
{
SLAM.SaveMap("/home/henry/henry_ws/src/YOLO-DynaSLAM/map.bin");
}
// Save camera trajectory
SLAM.SaveTrajectoryTUM("CameraTrajectory.txt");
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;
}
yolofastest::yolofastestSegment* yolo;
yolo = new yolofastest::yolofastestSegment();
cv::Mat RGB_image=cv_ptrRGB->image;
cv::Mat mask = cv::Mat::ones(480,640,CV_8U);
mask = yolo->Segmentation(RGB_image);
mpSLAM->TrackRGBD(cv_ptrRGB->image,cv_ptrD->image,mask,cv_ptrRGB->header.stamp.toSec());
}
henry@henry-MS-7A64:~/henry_ws/src/YOLO-DynaSLAM$ rosrun --prefix 'gdb -ex run --args' YOLO_DynaSLAM RGBD Vocabulary/ORBvoc.txt Examples/RGB-D/TUM3-bag.yaml GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB ...
If I load the map, does it work correctly?
if you choose no, you need to play your rosbag or launch your camera , but as my question,it will get the error about Segmentation fault , if you choose yes,you need to build a map prior , and it will load the map to do relocalization
Thank you. Since you are running under ROS, is it possible that argv[1], argv[2] are different from the original? Why don't you print out argv[1] and argv[2] once?
Sorry , i can't totally understand your question , i think argv[1] and argv[2] are same with the original. arg[1] means the orb vocabulary , and argv[2] is the camara yaml file
cout << argv[1] << endl; cout << argv[2] << endl;
I think it would be better to check what is actually output with
I'm sorry for talking without the original definition. I was referring to the following code as original. I believe the code is written for ROS based on these samples. https://github.com/bijustin/YOLO-Dyna...
In the original case, the
and so on. I think you are right.
However, when running under ROS, rosrun is used. So I think there is a possibility that argv[1] and argv[2] are not the intended values.