Segmentation fault.

asked 2021-08-04 09:55:58 -0600

henry0603 gravatar image

i am try to learn the dynamic slam and the code are base on the 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 <sensor_msgs/Image.h>
#include <sensor_msgs/image_encodings.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/Geometry.h"
#include "../../../include/MaskNet.h"

#include "../../../include/yolo.h"

using namespace std;

class ImageGrabber
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");

// 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')

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);


char IsSaveMap;
cout << "Do you want to save the map?(y/n)" << endl;
cin >> IsSaveMap;
if(IsSaveMap == 'Y' || IsSaveMap == 'y')
// Save camera trajectory


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;
    cv_ptrRGB = cv_bridge::toCvShare(msgRGB);
catch (cv_bridge::Exception& e)
    ROS_ERROR("cv_bridge exception: %s", e.what());

cv_bridge::CvImageConstPtr cv_ptrD;
    cv_ptrD = cv_bridge::toCvShare(msgD);
catch (cv_bridge::Exception& e)
    ROS_ERROR("cv_bridge exception: %s", e.what());

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);



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 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: Find the GDB ... (more)

edit retag flag offensive close merge delete


If I load the map, does it work correctly?

Do you want to load the map?(y/n)
[New Thread 0x7fffb60f7700 (LWP 4676)]
[New Thread 0x7fffb58f6700 (LWP 4677)]
[New Thread 0x7fffb50f5700 (LWP 4678)]
miura gravatar image miura  ( 2021-08-04 18:31:18 -0600 )edit

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

henry0603 gravatar image henry0603  ( 2021-08-04 21:41:44 -0600 )edit

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?

miura gravatar image miura  ( 2021-08-05 17:57:54 -0600 )edit

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

henry0603 gravatar image henry0603  ( 2021-08-05 22:46:43 -0600 )edit

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.

In the original case, the

. /mono_tum path_to_vocabulary path_to_settings path_to_sequence (path_to_masks)

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.

miura gravatar image miura  ( 2021-08-06 19:42:30 -0600 )edit