ORB_SLAM3 icon indicating copy to clipboard operation
ORB_SLAM3 copied to clipboard

[ Stable Build ] : Corrects major bugs, and creates buildable repo

Open aPR0T0 opened this issue 2 years ago • 22 comments

  • C11 to C14 migration
  • Adds Absent ros/orbslam3 from examples
  • OpenCV3 to OpenCV4 migration for old_examples
  • fixes Eigen incompatibility

Don't ask for atomic commits for this

Aah, where to start, It's a very not updated type of repo, to begin with, to be honest, there is so many compatibility issues man!!!

aPR0T0 avatar Aug 23 '23 13:08 aPR0T0

I wanted to try your fork to see if it fixed the segfault I was getting with the original.

sam@14IAU7:~/lib/ORB_PROTO$ ./Examples/Monocular/mono_euroc ./Vocabulary/ORBvoc.txt ./Examples/Monocular/EuRoC.yaml /home/sam/datasets/EuRoC/MH01 ./Examples/Monocular/EuRoC_TimeStamps/MH01.txt dataset-MH01_mono num_seq = 1 file name: dataset-MH01_mono Loading images for sequence 0...LOADED!


ORB-SLAM3 Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza. ORB-SLAM2 Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza. This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under certain conditions. See LICENSE.txt.

Input sensor was set to: Monocular Loading settings from ./Examples/Monocular/EuRoC.yaml Camera1.k3 optional parameter does not exist... -Loaded camera 1 -Loaded image info -Loaded ORB settings Viewer.imageViewScale optional parameter does not exist... -Loaded viewer settings System.LoadAtlasFromFile optional parameter does not exist... System.SaveAtlasToFile optional parameter does not exist... -Loaded Atlas settings System.thFarPoints optional parameter does not exist... -Loaded misc parameters

SLAM settings: -Camera 1 parameters (Pinhole): [ 458.65399169921875 457.29598999023438 367.21499633789062 248.375 ] -Camera 1 distortion parameters: [ -0.28340810537338257 0.073959067463874817 0.00019359000725671649 1.7618711353861727e-05 ] -Original image size: [ 752 , 480 ] -Current image size: [ 600 , 350 ] -Camera 1 parameters after resize: [ 365.94735717773438 333.44500732421875 292.99069213867188 181.10678100585938 ] -Sequence FPS: 20 -Features per image: 1000 -ORB scale factor: 1.2000000476837158 -ORB number of scales: 8 -Initial FAST threshold: 20 -Min FAST threshold: 7

Loading ORB Vocabulary. This could take a while... Vocabulary loaded!

Initialization of Atlas from scratch Creation of new map with id: 0 Creation of new map with last KF id: 0 Seq. Name: There are 1 cameras in the atlas Camera 0 is pinhole First KF:0; Map init KF:0 New Map created with 271 points Starting the Viewer Shutdown

Saving trajectory to f_dataset-MH01_mono.txt ... There are 1 maps in the atlas Map 0 has 318 KFs

End of saving trajectory to f_dataset-MH01_mono.txt ...

Saving keyframe trajectory to kf_dataset-MH01_mono.txt ... > Segmentation fault (core dumped)

Any ideas?

unicornuniform avatar Aug 24 '23 07:08 unicornuniform

Can you provide me with the dataset you are using here?

aPR0T0 avatar Aug 24 '23 07:08 aPR0T0

Can you provide me with the dataset you are using here?

Machine Hall 01 http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset/machine_hall/MH_01_easy/MH_01_easy.zip

unicornuniform avatar Aug 24 '23 07:08 unicornuniform

downloading it, very slow speed it seems

aPR0T0 avatar Aug 24 '23 08:08 aPR0T0

More here: https://github.com/search?q=repo%3AUZ-SLAMLab%2FORB_SLAM3+Segmentation+fault&type=issues

unicornuniform avatar Aug 24 '23 08:08 unicornuniform

@aPR0T0 thanks for this, this solves almost all issues and works flawlessly. Just to add up, for some of our machines, we had this problem where compiler wasn't able to find std::chrono::monotonic_clock, I don't know what's the most efficient way to solve it, but replacing this with std::chrono::steady_clock solves the issues. (Just in case anyone runs into the same issue.)

prajapatisarvesh avatar Aug 24 '23 16:08 prajapatisarvesh

@aPR0T0 I was able to build successfully but when I am trying to run the example scripts they are showing: libpango_windowing.so: cannot open shared object file: No such file or directory

How are you running the examples? Can you please share the steps

chetanpandey1266 avatar Aug 30 '23 11:08 chetanpandey1266

@aPR0T0 I was able to build successfully but when I am trying to run the example scripts they are showing: libpango_windowing.so: cannot open shared object file: No such file or directory

How are you running the examples? Can you please share the steps

Did you build the pangolin ?

aPR0T0 avatar Aug 30 '23 11:08 aPR0T0

I wanted to try your fork to see if it fixed the segfault I was getting with the original.

sam@14IAU7:~/lib/ORB_PROTO$ ./Examples/Monocular/mono_euroc ./Vocabulary/ORBvoc.txt ./Examples/Monocular/EuRoC.yaml /home/sam/datasets/EuRoC/MH01 ./Examples/Monocular/EuRoC_TimeStamps/MH01.txt dataset-MH01_mono num_seq = 1 file name: dataset-MH01_mono Loading images for sequence 0...LOADED!

ORB-SLAM3 Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza. ORB-SLAM2 Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza. This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under certain conditions. See LICENSE.txt.

Input sensor was set to: Monocular

Loading settings from ./Examples/Monocular/EuRoC.yaml Camera1.k3 optional parameter does not exist... -Loaded camera 1 -Loaded image info -Loaded ORB settings Viewer.imageViewScale optional parameter does not exist... -Loaded viewer settings System.LoadAtlasFromFile optional parameter does not exist... System.SaveAtlasToFile optional parameter does not exist... -Loaded Atlas settings System.thFarPoints optional parameter does not exist... -Loaded misc parameters SLAM settings: -Camera 1 parameters (Pinhole): [ 458.65399169921875 457.29598999023438 367.21499633789062 248.375 ] -Camera 1 distortion parameters: [ -0.28340810537338257 0.073959067463874817 0.00019359000725671649 1.7618711353861727e-05 ] -Original image size: [ 752 , 480 ] -Current image size: [ 600 , 350 ] -Camera 1 parameters after resize: [ 365.94735717773438 333.44500732421875 292.99069213867188 181.10678100585938 ] -Sequence FPS: 20 -Features per image: 1000 -ORB scale factor: 1.2000000476837158 -ORB number of scales: 8 -Initial FAST threshold: 20 -Min FAST threshold: 7 Loading ORB Vocabulary. This could take a while... Vocabulary loaded! Initialization of Atlas from scratch Creation of new map with id: 0 Creation of new map with last KF id: 0 Seq. Name: There are 1 cameras in the atlas Camera 0 is pinhole First KF:0; Map init KF:0 New Map created with 271 points Starting the Viewer Shutdown Saving trajectory to f_dataset-MH01_mono.txt ... There are 1 maps in the atlas Map 0 has 318 KFs End of saving trajectory to f_dataset-MH01_mono.txt ... Saving keyframe trajectory to kf_dataset-MH01_mono.txt ... > Segmentation fault (core dumped)

Any ideas?

Hello, I actually downloaded the dataset and tested it on My system it didn't give me segmentation fault.

Camera1.k3 optional parameter does not exist..., this line seems strange to me, please check if the dataset you are using is correct, but then I did the test on your data set only.

you can see my output

Steps I follow:

  • Building Pangolin
  • Building ORB_SLAM3
  • Then just running this
./Examples/Monocular/mono_euroc ./Vocabulary/ORBvoc.txt ./Examples/Monocular/EuRoC.yaml /home/proto/Downloads/ ./Examples/Monocular/EuRoC_TimeStamps/MH01.txt 
num_seq = 1
Loading images for sequence 0...LOADED!

-------

ORB-SLAM3 Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
ORB-SLAM2 Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
under certain conditions. See LICENSE.txt.

Input sensor was set to: Monocular
Loading settings from ./Examples/Monocular/EuRoC.yaml
Camera1.k3 optional parameter does not exist...
	-Loaded camera 1
	-Loaded image info
	-Loaded ORB settings
Viewer.imageViewScale optional parameter does not exist...
	-Loaded viewer settings
System.LoadAtlasFromFile optional parameter does not exist...
System.SaveAtlasToFile optional parameter does not exist...
	-Loaded Atlas settings
System.thFarPoints optional parameter does not exist...
	-Loaded misc parameters
----------------------------------
SLAM settings: 
	-Camera 1 parameters (Pinhole): [ 458.65399169921875 457.29598999023438 367.21499633789062 248.375 ]
	-Camera 1 distortion parameters: [  -0.28340810537338257 0.073959067463874817 0.00019359000725671649 1.7618711353861727e-05 ]
	-Original image size: [ 752 , 480 ]
	-Current image size: [ 600 , 350 ]
	-Camera 1 parameters after resize: [  365.94735717773438 333.44500732421875 292.99069213867188 181.10678100585938 ]
	-Sequence FPS: 20
	-Features per image: 1000
	-ORB scale factor: 1.2000000476837158
	-ORB number of scales: 8
	-Initial FAST threshold: 20
	-Min FAST threshold: 7


Loading ORB Vocabulary. This could take a while...
Vocabulary loaded!

Initialization of Atlas from scratch 
Creation of new map with id: 0
Creation of new map with last KF id: 0
Seq. Name: 
There are 1 cameras in the atlas
Camera 0 is pinhole
First KF:0; Map init KF:0
New Map created with 271 points

Shutdown

Saving trajectory to CameraTrajectory.txt ...
There are 1 maps in the atlas
  Map 0 has 315 KFs

End of saving trajectory to CameraTrajectory.txt ...

Saving keyframe trajectory to KeyFrameTrajectory.txt ...

aPR0T0 avatar Aug 30 '23 12:08 aPR0T0

Thanks a lot for this. It solved all build issues. I hope it gets merged into the main branch

geoeo avatar Sep 01 '23 08:09 geoeo

I don't know what I'm doing wrong. I bought a new laptop, installed Ubuntu 20.04 and compiled your fork + ROS. I'm running: rosrun ORB_SLAM3 Mono Vocabulary/ORBvoc.txt Examples/Monocular/Webcam.yaml

After I build a map and hit Stop to try and save the Atlas file, I get Segmentation fault (core dumped)

unicornuniform avatar Nov 02 '23 19:11 unicornuniform

@unicornuniform Might be something to do with the calibration? Make sure your Examples/Monocular/Webcam.yaml is correct.

prajapatisarvesh avatar Nov 02 '23 19:11 prajapatisarvesh

I tried a bunch of different setings. Here is the gdb output:

Thread 4 "mono_webcam" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffe0316700 (LWP 78069)] __GI___pthread_mutex_lock (mutex=0x7000700040256) at ../nptl/pthread_mutex_lock.c:67 67 ../nptl/pthread_mutex_lock.c: No such file or directory. (gdb) backtrace #0 __GI___pthread_mutex_lock (mutex=0x7000700040256) at ../nptl/pthread_mutex_lock.c:67 #1 0x00007ffff7de1549 in void std::lock<std::unique_lockstd::mutex, std::unique_lockstd::mutex> (std::unique_lockstd::mutex&, std::unique_lockstd::mutex&) () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #2 0x00007ffff7ddddec in ORB_SLAM3::MapPoint::isBad() () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #3 0x00007ffff7df4126 in ORB_SLAM3::Map::PreSave(std::set<ORB_SLAM3::GeometricCamera*, std::less<ORB_SLAM3::GeometricCamera*>, std::allocator<ORB_SLAM3::GeometricCamera*> >&) () at /home/sam /libs/ORB_SLAM3/lib/libORB_SLAM3.so #4 0x00007ffff7df19d2 in ORB_SLAM3::Atlas::PreSave() () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #5 0x00007ffff7d47856 in ORB_SLAM3::System::SaveAtlas(int) () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #6 0x00007ffff7d47fb9 in ORB_SLAM3::System::Shutdown() () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #7 0x00007ffff7eb94b4 in ORB_SLAM3::Viewer::Run() () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #8 0x00007ffff4d16df4 in () at /lib/x86_64-linux-gnu/libstdc++.so.6 #9 0x00007ffff42f9609 in start_thread (arg=) at pthread_create.c:477 #10 0x00007ffff4b52133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 (gdb)

It happens when I hit Stop and the map tries to save. I read through the issues and many people seem to have the same problem. Is it possible I'm having a null pointer somewhere in SaveAtlas(), PreSave(), or isBad()? Sorry, I'm not a c/c++ programmer.

unicornuniform avatar Nov 03 '23 04:11 unicornuniform

I tried a bunch of different setings. Here is the gdb output:

Thread 4 "mono_webcam" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffe0316700 (LWP 78069)] __GI___pthread_mutex_lock (mutex=0x7000700040256) at ../nptl/pthread_mutex_lock.c:67 67 ../nptl/pthread_mutex_lock.c: No such file or directory. (gdb) backtrace #0 __GI___pthread_mutex_lock (mutex=0x7000700040256) at ../nptl/pthread_mutex_lock.c:67 #1 0x00007ffff7de1549 in void std::lock<std::unique_lockstd::mutex, std::unique_lockstd::mutex> (std::unique_lockstd::mutex&, std::unique_lockstd::mutex&) () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #2 0x00007ffff7ddddec in ORB_SLAM3::MapPoint::isBad() () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #3 0x00007ffff7df4126 in ORB_SLAM3::Map::PreSave(std::set<ORB_SLAM3::GeometricCamera*, std::less<ORB_SLAM3::GeometricCamera*>, std::allocator<ORB_SLAM3::GeometricCamera*> >&) () at /home/sam /libs/ORB_SLAM3/lib/libORB_SLAM3.so #4 0x00007ffff7df19d2 in ORB_SLAM3::Atlas::PreSave() () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #5 0x00007ffff7d47856 in ORB_SLAM3::System::SaveAtlas(int) () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #6 0x00007ffff7d47fb9 in ORB_SLAM3::System::Shutdown() () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #7 0x00007ffff7eb94b4 in ORB_SLAM3::Viewer::Run() () at /home/sam/libs/ORB_SLAM3/lib/libORB_SLAM3.so #8 0x00007ffff4d16df4 in () at /lib/x86_64-linux-gnu/libstdc++.so.6 #9 0x00007ffff42f9609 in start_thread (arg=) at pthread_create.c:477 #10 0x00007ffff4b52133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 (gdb)

It happens when I hit Stop and the map tries to save. I read through the issues and many people seem to have the same problem. Is it possible I'm having a null pointer somewhere in SaveAtlas(), PreSave(), or isBad()? Sorry, I'm not a c/c++ programmer.

Hello @unicornuniform ,

There is a missing pthread_mutex_lock.c file I think its some library version issue. You can start by understanding why it can't find this file

aPR0T0 avatar Nov 03 '23 04:11 aPR0T0

I'm going to look into it. Possibly the CMake file is not linking libpthread

unicornuniform avatar Nov 03 '23 06:11 unicornuniform

Okay, I'm 99% sure now the problem is in PreSave, and that pthread_mutex_lock.c is a red herring. I'll try again when I get home

unicornuniform avatar Nov 03 '23 23:11 unicornuniform

Based on the issue here it seems as if the crash is caused by Map::PreSave deleting items of mspMapPoints while iterating it. I put a cout statement in Map::PreSave() to show this.

void Map::PreSave(std::set<GeometricCamera*> &spCams)
{
    int nMPWithoutObs = 0;
    std::cout << "mspMapPoints.size(): " << mspMapPoints.size() << endl;
    for(MapPoint* pMPi : mspMapPoints)
    {
        if(!pMPi || pMPi->isBad())
            continue;

        if(pMPi->GetObservations().size() == 0)
        {
            nMPWithoutObs++;
        }
        map<KeyFrame*, std::tuple<int,int>> mpObs = pMPi->GetObservations();
        for(map<KeyFrame*, std::tuple<int,int>>::iterator it= mpObs.begin(), end=mpObs.end(); it!=end; ++it)
        {
            if(it->first->GetMap() != this || it->first->isBad())
            {
                pMPi->EraseObservation(it->first);
                std::cout << "\tmspMapPoints.size(): " << mspMapPoints.size() << endl;
            }
        }
    }

So I can do a successful run that looks like this:

mspMapPoints.size(): 184 Starting to write the save binary file End to write save binary file

But a failed run looks like this:

mspMapPoints.size(): 755 mspMapPoints.size(): 755 mspMapPoints.size(): 755 mspMapPoints.size(): 754 Segmentation fault (core dumped)

After incorporating the changes to Map::PreSave and MapPoint::PreSave I linked to above, I'm no longer getting a segfault.

unicornuniform avatar Nov 04 '23 15:11 unicornuniform

Based on the issue here it seems as if the crash is caused by Map::PreSave deleting items of mspMapPoints while iterating it. I put a cout statement in Map::PreSave() to show this.

void Map::PreSave(std::set<GeometricCamera*> &spCams)
{
    int nMPWithoutObs = 0;
    std::cout << "mspMapPoints.size(): " << mspMapPoints.size() << endl;
    for(MapPoint* pMPi : mspMapPoints)
    {
        if(!pMPi || pMPi->isBad())
            continue;

        if(pMPi->GetObservations().size() == 0)
        {
            nMPWithoutObs++;
        }
        map<KeyFrame*, std::tuple<int,int>> mpObs = pMPi->GetObservations();
        for(map<KeyFrame*, std::tuple<int,int>>::iterator it= mpObs.begin(), end=mpObs.end(); it!=end; ++it)
        {
            if(it->first->GetMap() != this || it->first->isBad())
            {
                pMPi->EraseObservation(it->first);
                std::cout << "\tmspMapPoints.size(): " << mspMapPoints.size() << endl;
            }
        }
    }

So I can do a successful run that looks like this:

mspMapPoints.size(): 184 Starting to write the save binary file End to write save binary file

But a failed run looks like this:

mspMapPoints.size(): 755 mspMapPoints.size(): 755 mspMapPoints.size(): 755 mspMapPoints.size(): 754 Segmentation fault (core dumped)

After incorporating the changes to Map::PreSave and MapPoint::PreSave I linked to above, I'm no longer getting a segfault.

Did you delete the items after iteration then?

aPR0T0 avatar Nov 04 '23 16:11 aPR0T0

See the code I linked to above. He keeps the functionality the same but uses a temporary set to copy mspMapPoints into.

unicornuniform avatar Nov 04 '23 16:11 unicornuniform

@richard-elvira Can someone please merge this branch. It would make a lot of peoples lives a lot easier!

geoeo avatar Nov 08 '23 14:11 geoeo

I think there are a lot of changes, so if possible someone could verify and suggest some edits so that its a lot cleaner to be merged.

aPR0T0 avatar Nov 08 '23 14:11 aPR0T0