raulmur / ORB_SLAM2

Real-Time SLAM for Monocular, Stereo and RGB-D Cameras, with Loop Detection and Relocalization Capabilities
Other
9.3k stars 4.7k forks source link

map save/load #19

Open dannyway03 opened 8 years ago

dannyway03 commented 8 years ago

Hi Raul!

first of all thank you for sharing such a great piece of software! I was thinking it would be nice to have some map save/load functionality. This could enable some interesting functionalities, like the reconstruction of large scale environments in an incremental fashion (i.e., create and save and initial map, which is loaded and extended iteratively).

Do you plan to deliver such functionality? (i saw there are some commented functions in system.h) If not, do you have any advice to enable it?

thanks, danny

stevenyslins commented 7 years ago

Dear @Alkaid-Benetnash , Sorry, my fault, because in ROS environment, my command is this : "rosrun ORB_SLAM2 Mono /home/ubuntu/ros_build/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/ubuntu/ros_build/ORB_SLAM2/Examples/Monocular/TUM1.yaml"

So if I want to save map, it can modify System.h, and set is_savemap as true, although it is temporarily solution, but I can save the map and load it now.

Really thank you for your help, and have a great day.

deveshjain94 commented 7 years ago

Hi all, I was playing around with @MathewDenny 's code for map save/load. (Thanks for such an amazing work, it mostly worked out of the box). However, apart from missing MPs and KFs, I also noticed a bug which later resultant in a crash when relocalization tried to access the Parent KF of a reference KF which was non-null and pointing to garbage (this is only valid for the 1st KF ever added as it won't have a parent)

Solution would be to set mpParent to NULL (in the KF's default constructor). I don't know if anybody else faced this problem, but just putting it out there in case it helps somebody.

FConteMarza commented 6 years ago

Hello, i was using the save function and i have an issue when the algorithm detects a loop. In first place when a loop is detected and then the execution is stopped to create the text files, it takes quite a long time to the program to end, and then save the files. when a second loop is detected the program never ends therefore there is no text file saved.

I think that the problem is that the second LoopClosing process never ends, that is why the execution is not finished and the files not saved. If someone could help me with this issue it would be great.

Many thanks in advance.

rimital commented 6 years ago

How to publish a string to the topic ORB_SLAM2/save_map for saving the map. I am new to ROS, Should I have to write a separate publisher node for publishing string in this topic?????

wendaoyuchen commented 6 years ago

Hi, @poine ,thanks for your work. But I met some problems when run make in the /ORB_SLAM2/build, it reports: ../lib/libORB_SLAM2.so: undefined reference to `ORB_SLAM2::Frame::InitializeScaleLevels()' collect2: error: ld returned 1 exit status CMakeFiles/restart_slam_on_images.dir/build.make:161: recipe for target '../test/restart_slam_on_images' failed make[2]: [../test/restart_slam_on_images] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/restart_slam_on_images.dir/all' failed make[1]: [CMakeFiles/restart_slam_on_images.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2

but when I change the "inlier void Frame::InitializeScaleLevels() " to " void Frame::InitializeScaleLevels()"in the file "Frame.cc", it can make well, I don't know why it works and what problems it can bring?

wendaoyuchen commented 6 years ago

Hi, Is there anyone know how to run in the ROS-kinetic? This ROS version supports OpenCV3, so when I rosrun the mono, it can't work .

ADDDDD commented 6 years ago

Hi, @Alkaid-Benetnash ,thanks for your code. It works fine, except missing MPs and KFs. In my case, the map I saved has 56 KFs and 2600+ MPs, but when I load map, there are only 29 KFs and 1600+ MPs. I tried other datasets, and seems to be the same result. Wonder where is the problem? Thanks a lot!

Alkaid-Benetnash commented 6 years ago

Hi @ADDDDD Have you suffered from any segment fault when localizing or updating the map? I guess the reason may be KeyFrame::mbBad and MapPoint::mbBad. According to here, bad MPs are still resident in memory and in my opinion KFs behave similarly. However, these bad objects may be deleted from internal structure and consequently inaccessible (memory leak?). In my code, only accessible KFs and MPs, whether bad or not, will be saved.

ADDDDD commented 6 years ago

Hi @Alkaid-Benetnash
I have confirmed I didn't get any segment fault. I got KFs and MPs by Map::GetAllKeyFrames and Map::GetAllMapPoints, I have checked bad flags by using KeyFrame::isbad() and MapPoint::isbad() before output KFs and MPs numbers. The result is the same as I see in the viewer. Just like below: image image image When I load map, the viewer shows like this: image

Alkaid-Benetnash commented 6 years ago

@ADDDDD Please help me reproduce the problem. I can't reproduce it. I tested with rgbd_dataset_freiburg1_desk, rgbd_dataset_freiburg1_rpy and rgbd_dataset_freiburg1_xyz in the TUM dataset. Which dataset are you using? I check the mpMap->GetAllKeyFrames().size() and mpMap->GetAllMapPoints().size() in the System::LoadMap and System::SaveMap. Where did you check those numbers?

ADDDDD commented 6 years ago

@Alkaid-Benetnash I use my own dataset and I check those numbers in another method wrote by myself, it is called just before SLAM::shutdown. I will try some common datasets, and I will let you know if I find something new. Thanks again!

ADDDDD commented 6 years ago

@Alkaid-Benetnash Sorry, It's my fault. I made a KeyFrame Filter before save map, which changes KFs and MPs. So sorry for bothering you !

hesamira commented 6 years ago

Hello world, @MathewDenny , thanks for your code. I have used @MathewDenny 's code.I have faced this error: sami@sami-Vostro-1520:~/MathewDenn/src/ORB_SLAM2$ ./build.sh ./build.sh: line 35: ./tools/bin_vocabulary: No such file or directory

I have used Ubuntu 14.4, ROS indigo and OpenCV 2.4.13. Please guide me. Thanks.

MathewDenny commented 6 years ago

Hi Hesamira, Could you try the repo @MathewDenny https://github.com/mathewdenny 's now. I was missing a folder. Let me know if that fixes the issue.

Thanks

On Sat, Feb 24, 2018 at 7:30 AM, hesamira notifications@github.com wrote:

Hello world, @MathewDenny https://github.com/mathewdenny , thanks for your code. I have used @MathewDenny https://github.com/mathewdenny 's code.I have faced this error: sami@sami-Vostro-1520:~/MathewDenn/src/ORB_SLAM2$ ./build.sh CMake Error at CMakeLists.txt:105 (add_executable): Cannot find source file:

tools/bin_vocabulary.cc

Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx

-- Build files have been written to: /home/sami/MathewDenn/src/ORB_ SLAM2/build make: *** No targets specified and no makefile found. Stop. Converting vocabulary to binary ./build.sh: line 35: ./tools/bin_vocabulary: No such file or directory

I have used Ubuntu 14.4, ROS indigo and OpenCV 2.4.13. Please guide me. Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/raulmur/ORB_SLAM2/issues/19#issuecomment-368225219, or mute the thread https://github.com/notifications/unsubscribe-auth/AQxMwFqp-aayEL2bRlCwZGiTVQPL0eenks5tYADNgaJpZM4HVJUE .

hesamira commented 6 years ago

Dear @stevenyslin, Hi, How can you save map and load the data in ROS environment via Alkaid-Benetnash 's code ? Can you share your code? I have need to save map and load the data in ROS environment. I could run Alkaid-Benetnash 's code, but I could not save map and load the data in ROS environment. Your answer is really important to me. Please, guide me. Thanks.

morgiazzi commented 6 years ago

Hi everyone !

I have downloaded the @poine ORBSLAM2 version with the possibility of save and load a map theoretically but I can execute ./build.sh . Indeed I have this problem :


martinorgiazzi@martinorgiazzi-ThinkPad-T540p:~/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2$ ./build.sh Configuring and building Thirdparty/DBoW2 ... mkdir: cannot create directory ‘build’: File exists CMake Error: The current CMakeCache.txt directory /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/Thirdparty/DBoW2/build/CMakeCache.txt is different than the directory /home/poine/work/simone/trunk/ORB_SLAM2/Thirdparty/DBoW2/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt CMake Error: The source "/home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/Thirdparty/DBoW2/CMakeLists.txt" does not match the source "/home/poine/work/simone/trunk/ORB_SLAM2/Thirdparty/DBoW2/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory. CMake Error: The source directory "/home/poine/work/simone/trunk/ORB_SLAM2/Thirdparty/DBoW2" does not exist. Specify --help for usage, or press the help button on the CMake GUI. Makefile:296: recipe for target 'cmake_check_build_system' failed make: [cmake_check_build_system] Error 1 Configuring and building Thirdparty/g2o ... mkdir: cannot create directory ‘build’: File exists CMake Error: The current CMakeCache.txt directory /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/Thirdparty/g2o/build/CMakeCache.txt is different than the directory /home/poine/work/simone/trunk/ORB_SLAM2/Thirdparty/g2o/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt CMake Error: The source "/home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/Thirdparty/g2o/CMakeLists.txt" does not match the source "/home/poine/work/simone/trunk/ORB_SLAM2/Thirdparty/g2o/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory. CMake Error: The source directory "/home/poine/work/simone/trunk/ORB_SLAM2/Thirdparty/g2o" does not exist. Specify --help for usage, or press the help button on the CMake GUI. Makefile:917: recipe for target 'cmake_check_build_system' failed make: [cmake_check_build_system] Error 1 Uncompress vocabulary ... Configuring and building ORB_SLAM2 ... -- The C compiler identification is GNU 5.4.0 -- The CXX compiler identification is GNU 5.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done Build type: Release -- Performing Test COMPILER_SUPPORTS_CXX11 -- Performing Test COMPILER_SUPPORTS_CXX11 - Success -- Performing Test COMPILER_SUPPORTS_CXX0X -- Performing Test COMPILER_SUPPORTS_CXX0X - Success -- Using flag -std=c++11. -- Found Eigen3: /usr/include/eigen3 (Required is at least version "3.1.0") -- Boost version: 1.58.0 -- Found the following Boost libraries: -- regex -- system -- filesystem -- Configuring done -- Generating done -- Build files have been written to: /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/build Scanning dependencies of target ORB_SLAM2 [ 1%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Camera.cc.o [ 3%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/System.cc.o [ 5%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Tracking.cc.o [ 7%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/LocalMapping.cc.o [ 9%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/LoopClosing.cc.o [ 11%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/ORBextractor.cc.o /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc: In member function ‘void ORB_SLAM2::ORBextractor::ComputeKeyPointsOctTree(std::vector<std::vector >&)’: /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc:808:46: error: ‘FAST’ was not declared in this scope vKeysCell,iniThFAST,true); ^ /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc: In member function ‘void ORB_SLAM2::ORBextractor::ComputeKeyPointsOld(std::vector<std::vector >&)’: /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc:933:66: error: ‘FAST’ was not declared in this scope FAST(cellImage,cellKeyPoints[i][j],iniThFAST,true); ^ /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc:1004:17: error: ‘KeyPointsFilter’ has not been declared KeyPointsFilter::retainBest(keysCell,nToRetain[i][j]); ^ /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc:1022:13: error: ‘KeyPointsFilter’ has not been declared KeyPointsFilter::retainBest(keypoints,nDesiredFeatures); ^ /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc: In member function ‘void ORB_SLAM2::ORBextractor::operator()(cv::InputArray, cv::InputArray, std::vector&, cv::OutputArray)’: /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc:1084:82: error: ‘GaussianBlur’ was not declared in this scope GaussianBlur(workingMat, workingMat, Size(7, 7), 2, 2, BORDER_REFLECT_101); ^ /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc: In member function ‘void ORB_SLAM2::ORBextractor::ComputePyramid(cv::Mat)’: /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc:1118:78: error: ‘INTER_LINEAR’ was not declared in this scope resize(mvImagePyramid[level-1], mvImagePyramid[level], sz, 0, 0, INTER_LINEA ^ /home/martinorgiazzi/Documents/stereoCameraNavigation/orbslam2v2trial/ORB_SLAM2/src/ORBextractor.cc:1118:90: error: ‘resize’ was not declared in this scope resize(mvImagePyramid[level-1], mvImagePyramid[level], sz, 0, 0, INTER_LINEAR); ^ CMakeFiles/ORB_SLAM2.dir/build.make:182: recipe for target 'CMakeFiles/ORB_SLAM2.dir/src/ORBextractor.cc.o' failed make[2]: [CMakeFiles/ORB_SLAM2.dir/src/ORBextractor.cc.o] Error 1 CMakeFiles/Makefile2:474: recipe for target 'CMakeFiles/ORB_SLAM2.dir/all' failed make[1]: [CMakeFiles/ORB_SLAM2.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2


Someone had the same building issue or has an idea to solve it ?

Thank you in advance !

amitfishy commented 6 years ago

Hi @Alkaid-Benetnash I tried out your repo, map saving and loading works pretty well. However I have noticed that when I try to map slightly larger areas I am able to save the map, but I get the following error when I try to load it again:

Loading Mapfile: map.bin
terminate called after throwing an instance of 'boost::archive::archive_exception'
  what():  input stream error
Aborted (core dumped)

In this way I have been able to load maps up to roughly 550MB successfully, but if I create a larger map of >600MB, I get the aforementioned error. Any idea how to fix this?

EDIT: It seems like this error occurs when the video is very large even if the map created is small. I was able to load a map once I shortened the video (even though its size was 610MB).

Thanks

Alkaid-Benetnash commented 6 years ago

@amitfishy I guess the map isn't saved properly. As you have noticed, the size of map doesn't grow according to the video length (it should in most cases).

Can you confirm everything works fine when saving the map?

Besides, finphin encountered problems when saving large maps, you can take a look at his comment.

amitfishy commented 6 years ago

I think there might be a problem with the original repo itself, seeing as how I sometimes get Seg faults with it. Some people have suggested using a different version of Pangolin which helps to some extent but you still get occasional Seg faults. Possibly the repo does not scale too well with larger maps or I might be using a newer version of a dependency that the original repo was built on. These errors like the QObject:Timers error sometimes occur on exiting the program, so I'm thinking the same issues have crept into your fork. Apart from this everything in your repo seemed to work perfectly.

I'll try out what was mentioned in the other post. Thank you!

ksivakumar commented 6 years ago

@amitfishy Did you have any luck in solving this issue? I tried the solution in the other post by increasing stack size but I am still getting a malloc(): memory corruption error with larger maps.

amitfishy commented 6 years ago

@ksivakumar Sorry, I didn't really follow up on this. Partly I felt map sizes were too large for small clips and going over the same area again would add on a significant overhead(about 50-70% extra memory for retracing a path). I didn't really think getting this working was worth it. Maybe have a look at maplab which has its own problems, but infrastructure-wise, it's pretty solid and bug free.

RahmanMifta commented 5 years ago

@ywj447 As you can see in this Line the Map is saved in a binary format with the ending ".bin" You cant visualize it with a pcl_viewer. You are only able to save and load it with ORB SLAM.

When you want to visualize it otherwise you have to convert every Mappoint and Keyframe Pose in a PCL Datatype. Thats not implemented yet.

Tank you for you suggestion. I am a newbie in ORB-SLAM2. I have map.bin file. Can you please guide me little more elaborately how to get pointcloud from map.bin file?

Shubhamvithalani commented 5 years ago

@poine @MathewDenny I was able to save and load map using serialisation. I tried to relocalise on a pre-loaded map and was able to do it successfully. Now if I want the re-localised position with respect to the Global Map. Can you suggest any methods. My aim is to to travel from a point A to point B inside the map using SLAM. Thus I need to establish global position of A,B

AlejandroSilvestri commented 5 years ago

Hey guys,

If you are still looking for a way to save maps, I have this project working fine: https://github.com/AlejandroSilvestri/osmap

It uses Google's protocol buffers, so the protocol used in serialization is well documented, and you can modify it without losing compatibility. Plus an example code show you how to access keyframes, mappoints and so directly in the map files, without the need of compiling all ORB-SLAM2.

kadn commented 5 years ago

@poine Hi, I found some bugs in your code http://recherche.enac.fr/~drouin/slam/orbslam2/poine_orbslam2_04_07_16.tgz

  1. Frame.cc has an illegal inline in front of ORB_SLAM2::Frame::InitializeScaleLevels()
  2. void Tracking::Track() : I change the code
    mlRelativeFramePoses.push_back(mlRelativeFramePoses.back());

    into this

        if(mlRelativeFramePoses.size()==0)
            mlRelativeFramePoses.push_back(cv::Mat());
        else
            mlRelativeFramePoses.push_back(mlRelativeFramePoses.back());
  3. a bug in g2o/g2o/solvers/linear_solver_eigen.h After change:
    class LinearSolverEigen: public LinearSolver<MatrixType>
    {
    public:
    typedef Eigen::SparseMatrix<double, Eigen::ColMajor> SparseMatrix;
    typedef Eigen::Triplet<double> Triplet;
    typedef Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, int> PermutationMatrix;
  4. I think LoopClosing thread should be hang up, but there is no such function. So I changewhile(1) to while(0).

Your work is really awesome !! After these operations, I succeed in saving and loading, and I get a good result that looks nice!

Shame-fight commented 4 years ago

Hey guys,

If you are still looking for a way to save maps, I have this project working fine: https://github.com/AlejandroSilvestri/osmap

It uses Google's protocol buffers, so the protocol used in serialization is well documented, and you can modify it without losing compatibility. Plus an example code show you how to access keyframes, mappoints and so directly in the map files, without the need of compiling all ORB-SLAM2.

I have two questions about 'How to bundle with ORB-SLAM2'

  1. The second step '2- Add Osmap files to ORB-SLAM2 project.', I only have osmap.pb.h and no osmap.h. Do these two files refer to the same.
  2. Step 4: 'Write the code to call save and load, usually attached to UI. As an example, in Orb-Slam2's main.cc'. I can't find which folder main.cc is in, I've searched The entire folder. I only have main.cpp under the pangolin folder. Can you tell me where the main.cc file is?
AlejandroSilvestri commented 4 years ago

@Shame-fight

Answers:

1- Osmap.h is into include folder. Osmap.cc is into src folder. 2- Readme fixed. There's no main.cc. You must locate main() in orb-slam2. There are many in Example folder.

Let me know if it works!