raulmur/ORB_SLAM2

map save/load

dannyway03 opened this issue · 127 comments

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

Hey, check the Pull Request "Add getter for map in System. #14". Seems like its exactly what you are asking about!

Hi,
that is quite not the same thing. The map "getter" of #14 does not allow storing/reloading the map, and re-use it.
What I meant is to have a way to store the WHOLE map/system configuration. In this way it would be possible to load a pre-calculated environment map (and all the related information), and carry out e.g., only the camera localization (or keep on the tracking and extend the map)

poine commented

@dannyway03: I am working on load/save. I don't know if/when i will have it finished.

poine commented

Request for comments:
I have been working on map saving/loading for a while and am starting to get the first results. I am able to run ORBSLAM2 on kitti0 monocular and save the resulting map. Subsequently, I am able to restart ORBSLAM2, load the map and run in localization only mode. A typical resulting map for kitti0 (100.000 MapPoints and 1700 KeyFrames) weights about 200mB, takes 2.5s to store and 10s to load.

In order to achieve this result, I have had to butcher ORBSLAM2's code quite a bit and before releasing a patch, I would like to gain a better understanding and refactor quite a bit too, hence that first request for comments (for now i shoved most everything in Map.cc and added accessors in other classes where needed).

In my understanding, at the moment, the camera calibration is parsed by Tracking. The calibration, and computed by-products, are then stored in Frames and KeyFrames, partly as class variables and partly as instance variables. Tracking has a ChangeCalibration methods which triggers the update of the Frames class variables but leaves existing instances as is. My question is about the use case of ChangeCalibration. How is this functionality intended? I would like to avoid having to store a calibration along each KeyFrame. I could store the different calibrations and have each Keyframe linked to its own one but that also sounds a bit complicated.
I guess my question is: do we want to have the possibility of having several calibrations coexisting in one map? or was ChangeCalibration intended to be used in conjunction with a map reset and we can assume that all the Frames in a map use the same camera and the same calibration?

Oh... and once again, thank you so much Raul for your awesome work and your code. I learned so much by reading it, you are my hero!

@poine thats great news and great work, can you give an estimate on when you can release a patch?

poine commented

Depends on what kind of patch you want. As I said, I butchered orbslam2
quite a bit. For example, I made camera-related stuff common to all frames,
which allowed me to not store anything camera-related in the map. Is that
what we want?
My first patch, related to the dictionary, did not get accepted (nor
rejected) so I am not sure what to do nor where to start from.
As I said before, I am a noob at C++, vision and git. I need guidance.
On Mar 2, 2016 2:06 PM, "khedd" notifications@github.com wrote:

@poine https://github.com/poine thats great news and great work, can
you give an estimate on when you can release a patch?


Reply to this email directly or view it on GitHub
#19 (comment).

Any kind of patch will work for me.

However I do not know why your first patch did not get accepted, I see that
you have you own repository. Was you first patch about speeding up the
loading time? If so I can see that in https://github.com/poine/ORB_SLAM2.

2016-03-02 23:38 GMT+02:00 poine notifications@github.com:

Depends on what kind of patch you want. As I said, I butchered orbslam2
quite a bit. For example, I made camera-related stuff common to all frames,
which allowed me to not store anything camera-related in the map. Is that
what we want?
My first patch, related to the dictionary, did not get accepted (nor
rejected) so I am not sure what to do nor where to start from.
As I said before, I am a noob at C++, vision and git. I need guidance.
On Mar 2, 2016 2:06 PM, "khedd" notifications@github.com wrote:

@poine https://github.com/poine thats great news and great work, can
you give an estimate on when you can release a patch?


Reply to this email directly or view it on GitHub
#19 (comment).


Reply to this email directly or view it on GitHub
#19 (comment).

@poine i tried serializing and deserializing the ORB map and i have a couple of questions to ask you.
I am storing the list of mappoints and keyframes in the Map class and I just store the ids of the observations ,the parentKFs , the spanning tree etc for each item. During loading, after loading the saved lists, im searching and the list of ids in the original lists of mappoints and keyframes and then referencing them.

In this way , I found there are non corresponding KF and Mappoint ids during crossreferencing. I can circumvent by checking for nonexistant KFs / Map points at multiple locations during run time.I am able to run in localization or mapping mode with the loaded map but fails during the instance of a loop closure.
Could you advise if i would need to serialize other elements like the Local Graph or just identify and save the missing elements also. Have you faced this situation?

poine commented

@denny
I am on vacations away from my computer. I'll answer in a few days.

On Fri, Mar 25, 2016 at 5:04 AM, Denny notifications@github.com wrote:

@poine https://github.com/poine i tried serializing and deserializing
the ORB map and i have a couple of questions to ask you.
I am storing the list of mappoints and keyframes in the Map class and I
just store the ids of the observations ,the parentKFs , the spanning tree
etc for each item. During loading, after loading the saved lists, im
searching and the list of ids in the original lists of mappoints and
keyframes and then referencing them.

In this way , I found there are non corresponding KF and Mappoint ids
during crossreferencing. I can circumvent by checking for nonexistant KFs /
Map points at multiple locations during run time.I am able to run in
localization or mapping mode with the loaded map but fails during the
instance of a loop closure.
Could you advise if i would need to serialize other elements like the
Local Graph or just identify and save the missing elements also. Have you
faced this situation?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#19 (comment)

@poine To answer your request for comments:
I don't see the function ChangeCalibration actually getting called anywhere. I think it's a very safe to assume a constant calibration throughout a map. If you're willing to commit what you have to your fork, I'd be happy to take a look at it.

poine commented

@michael: i am not comfortable with git and a bit short in time at the
moment to remedy it. I've uploaded an archive of my current tree here:
http://recherche.enac.fr/~drouin/slam/orbslam2/poine_orbslam2_04_07_16.tgz

The code for loading/saving maps is in Map.cc .It's kind of ugly at the
moment, but it's good enough for my needs. I have assumed a common camera
calibration for all frames and stored it with the map.

If you (or someone else) is willing to use that code, I am willing to take
the time to polish it and publish it on github.

hth

Poine

On Wed, Apr 6, 2016 at 10:56 PM, Michael Shomin notifications@github.com
wrote:

@poine https://github.com/poine To answer your request for comments:
I don't see the function ChangeCalibration actually getting called
anywhere. I think it's a very safe to assume a constant calibration
throughout a map. If you're willing to commit what you have to your fork,
I'd be happy to take a look at it.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#19 (comment)

@poine I'll look over the code and give it a try. Your link appears to be broken though.

poine commented

@michael: sorry for the broken link. Should be fixed now

On Thu, Apr 7, 2016 at 7:29 PM, Michael Shomin notifications@github.com
wrote:

@poine https://github.com/poine I'll look over the code and give it a
try. Your link appears to be broken though.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#19 (comment)

@poine Looking forward to see this feature been published, but maybe the link is still broken.

bhack commented

@poine I hope that you can push your code on github soon. Would be very helpful.

@poine I'm glad your code released, but the link may broken...anyway, thanks for your efforts

poine commented

@zsy372901
The link seems to be working from my side (it was broken last night). Can
you check and let me know ?

@bhack

I'll try to free some time and look again at git oddities next week

On Fri, Apr 8, 2016 at 10:16 AM, zsy372901 notifications@github.com wrote:

@poine https://github.com/poine I'm glad your code released, but the
link may broken...anyway, thanks for your efforts


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#19 (comment)

@poine aha, it is worked:D thanks a lot!

@poine Wow, I just gave myself a headache... There seems to be a bug in your PublishCurrentCamera function used in rgbd. I added the save subscriber from ros_mono and was trying it on a bag, but I was getting an exception after about 20 seconds of running. Very strange. I'll look into it later, but for now, the save functionality seems to be working. I'll add the loading to System.cc and try it through ros.

@poine Would you like me to package up the save/load functionality into commits and make a pull request, or do you plan to? Also, nice work!

poine commented

@michael: Sure, whatever... i'm not fluent with git, so it would take me a
long time figure it. Also the code is not really finished. It only works
for monocular and i vaguely recall very inefficiently storing an array of
pointers which were mostly null.
But for now, it fills my need which was to have a georeferenced slam.

On Tue, Apr 12, 2016 at 4:39 AM, Michael Shomin notifications@github.com
wrote:

@poine https://github.com/poine Would you like me to package up the
save/load functionality into commits and make a pull request, or do you
plan to?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#19 (comment)

@poine Thanks for your great work! I have downloaded your codes and see that in Map.cc, you implemented a function called _ReadKeyFrame. And there is a comment 'mono only for now'. I have been running ORB-SLAM2 with a bumblebee2 stereo camera, that is, I need to save map in stereo mode. So could you tell me whether I can reuse your codes on my stereo camera. Thanks again.

Thanks @poine for the great job. But I still have an issue:
If I just save map and next time load map, it loaded well but does not work on tracking stage.

It crashes on this line:

    mlRelativeFramePoses.push_back(mlRelativeFramePoses.back());<=== Crash Error: EXC_BAD_ACCESS
    mlpReferences.push_back(mlpReferences.back());
    mlFrameTimes.push_back(mlFrameTimes.back());
    mlbLost.push_back(mState==LOST);

because mlRelativeFramePoses is empty.
Any ideas on how to fix this or did I miss something?
Thanks.

poine commented

@skylook: the code i use to restart orbslam2 after loading a map is
here: ORB_SLAM2/test/restart_slam_on_images.cc

On Tue, Apr 26, 2016 at 11:32 AM, skylook notifications@github.com wrote:

Thanks @poine https://github.com/poine for the great job. But I still
have an issue of how to use map load function?
If I just save map and next time load map, it loaded well but does not
work on tracking because the value of mState is still NOT_INITIALIZED and
some other parameters are not set.
Any body can give a working example of Save&Load.
Thanks!


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#19 (comment)

Thanks for your reply @poine , I already tried what you did in restart_slam_on_images.cc, it still crashes on the following line in Tracking.cc:

mlRelativeFramePoses.push_back(mlRelativeFramePoses.back());

This line is touched when it is failed tracking on the first frame (mCurrentFrame.mTcw.empty()). When it runs without an initial map, it always has a mlRelativeFramePoses, but when it runs with a initial map, it is empty.

I go through your code but I haven't catch the point on how to fix this. Any idea? Thanks so much :)

@dannyway03 Have you realized your goal of reusing the slam map?

I have found a problem of map load function. Because mspMapPoints is stored in std::set which means when using
std::vector<MapPoint*> amp = GetAllMapPoints();
the return vector is not always in the same order (set is ordered by the pointer address). That makes _ReadKeyFrame() function gets a wrong result. @poine

@poine Thanks for your great job! Could I ask about the modification of your package comparing with the original ORB-SLAM? For example, the map save/load in map.cc and the example codes. So nice of you to help me learn more about SLAM.

@highlightz not so much time for this lately...anyway, i have been trying with serialization, somehow inspired by @MathewDenny..

@poine
2 Questions:

  1. Are you able to switch back from the Localisation Mode to the SLAM Mode after loading the Map?
  2. Are you able to reset the System after loading the Map?

I'm also currently writing my code to save and load the map and it works fine, but still got problems with this 2 issues.

Thanks @dannyway03 . Im sure you can devise something better..
@chwimmer on paper these should be definitely possible.
If its of any use check out the monocular specific code i put up sometime back.

hey @poine: I have tried to run your code and while the LoadMap and SaveKITTIMap files work fine, the restartSLAMOnImage seems to be broken (at least for me). There seems to be a memory related bug as in my Virtual Machine the kernel kills the process after filling up the whole RAM. @skylook Do you have any fixes for the bugs u mentioned in the code - could be related!

edit: so far I've started the SaveKitti which outputs a map.bin file. ViewMap can load the map and show it. Now I wanted to load the map and localize myself with a given dataset by using restartSLAMOnImage. Maybe I'm missing a step here?

poine commented

Hello World

@lschaupp
I am aware there is a problem with restarting SLAM (retarting in
localization mode works, which is what i was doing) - I believe it is due
to me not storing the last keyframe index with the map. So... restarting
works sometimes, when the last keyframe has not been culled. I'm a bit
overwhelmed at the moment, but i can fix that maybe next week.

On Tue, Jun 28, 2016 at 1:05 AM, lschaupp notifications@github.com wrote:

hey @poine https://github.com/poine: I have tried to run your code and
while the LoadMap and SaveKITTIMap files work fine, the restartSLAMOnImage
seems to be broken (at least for me). There seems to be a memory related
bug as in my Virtual Machine the kernel kills the process after filling up
the whole RAM. @skylook https://github.com/skylook Do you have any
fixes for the bugs u mentioned in the code - could be related!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#19 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAGTz30RpE7AoQhySUFtu3l3uCAg-BwFks5qQFc6gaJpZM4HVJUE
.

@poine thx for your reply. So far I could fix my problem (mistake in the map path) and it runs really well with the localization. So thanks again! Thanks for all your effort.

poine commented

On Tue, Jun 28, 2016 at 9:30 PM, lschaupp notifications@github.com wrote:

@poine https://github.com/poine thx for your reply. So far I could fix
my problem (mistake in the map path)

sorry... that code is not really written. We should write errors handling.
It was just a quick and dirty proof of concept.

and it runs really well with the localization. So thanks again! Thanks for
all your effort.

You're very welcome

Does anybody have ideas or even better has started to work on map
management ( like georeferencing, offline optimization, map merging,
collaborative mapping, etc... )? I'm thinking of a fleet of network
connected robots using and maintaining a map, a bit like what the
autonomous cars seem to be doing.

Oh, and on another topic, i have started to write a python binding (cython)
to ORBSLAM2. I find it much easier to experiment and write test in python
than in C++. Is anybody interested in that?

@MathewDenny
Thank you so much. Tried your code and it works out of the box for me (only the tool folder from poine is missing in your repository so your build.sh is not working out of the box but thats not really the point). The only thing is that a reset is not working after loading the map but thats subsidiary for me.

@MathewDenny , I was looking at your last commit and the only modified file in ROS folder is ros_mono.cc. Does it mean the save/load functionality is only working for monocular?

@aseyfi
No it also works with RGBD or Stereo. You just have to modifie the other files like ros_mono.cc

Hey @poine, regarding your last comment, I would be interested in Python bindings!

Hey @poine I'm also doing work on robotic fleets doing offline shared mapping. I'm both interested in developing the cython bindings and adding additional functionality to ORB-SLAM2 to support Octomap integration. If you'd like to work with me on this you can hit me up at tragas@cs.toronto.edu and we can talk further.

@poine hi, I'm working on reload map. There is a problem like that : first i save the map using "Save" in "map.cc" and close the program; second I load ("Load in map.cc") the map and using it as initialization, then I save the map again, there is an error "segmentation fault" . I guess maybe the
f.write((char*)&ckf->mnId, sizeof(ckf->mnId)); cause the error, but i don't know how to solve it. Do you have some good ideas?

you just have to check if it is a NULL Pointer and if it is don't write it into the File.
But checkout the Code of @MathewDenny. Its working pretty good.

@chwimmer hi, I download the code of @MathewDenny , and it work well for just creating a new map, and when the bReuseMap=true, there is also a problem as follows
terminate called after throwing an instance of 'boost::archive::archive_exception'
what(): input stream error
Aborted (core dumped)

I've checked the threads and the stack, and it doesn't have any wrong things, could you have some advise for me ?

This is normally the error Message when the Path to the Map is wrong. I'm not sure what is the default path from Mathew. I changed it that I give the constructor the path to the map so I have:
LoadMap(path_map.c_str());
with the new constructor:
System::System(const string &strVocFile, const string &strSettingsFile, const eSensor sensor,const string &path_map, const bool bUseViewer, const bool bReuse)

Any idea what's going wrong for me here?

When I clone the repo, I get an error when trying to build though I can build the latest ORB_SLAM2.git from raulmur fine and it runs, so I know my dependencies are right...

Uncompress vocabulary ...
Configuring and building ORB_SLAM2 ...
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- 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
-- 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
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.54.0
-- Found the following Boost libraries:
-- serialization
-- Configuring done
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: directory...
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

poine commented

Looks like the "bin_vocabulary" program failed to build ( the 'Cannot find
source file line' ). Later build.sh tries to use that program to convert
the text vocabulary into binary and fails.
I don't know why the program failed to build in the first place, though. Do
you have the source file (tools/bin_vocabulary.cc) ?

On Aug 11, 2016 9:04 PM, "MCoder1" notifications@github.com wrote:

Any idea what's going wrong for me here?

When I clone the repo, I get an error when trying to build though I can
build the latest ORB_SLAM2.git from raulmur fine.

Uncompress vocabulary ...
Configuring and building ORB_SLAM2 ...
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- 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
-- 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
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.54.0
-- Found the following Boost libraries:
-- serialization
-- Configuring done
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/mchong5/Projects/ORB_SLAM2_MapSaveLoad/ORB_SLAM2_SaveLoad/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


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@poine

I do not have the source file tools/bin_vocabulary.cc. It isn't included when I cloned the repo. It doesn't seem to be a part of raulmur's orb slam repo, so I'm not sure what it's for.

poine commented

@MCoder1

Where does the build.sh that builds and uses bin_vocabulary come from? I
just checked in Raul's repo and i did not see the binary vocabulary things.

I assume you took the binary vocabulary from my repo (
https://github.com/poine/ORB_SLAM2 ) or from the tarball i released with
the map save/load feature:

http://recherche.enac.fr/~drouin/slam/orbslam2/poine_orbslam2_04_07_16.tgz

On Thu, Aug 11, 2016 at 9:20 PM, MCoder1 notifications@github.com wrote:

@poine https://github.com/poine

I do not have the source file tools/bin_vocabulary.cc. It isn't included
when I cloned the repo. It doesn't seem to be a part of raulmur's orb slam
repo, so I'm not sure what it's for.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#19 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGTzzqXKqNPdP2Sk1kpR-tNWd8YxJxGks5qe3YWgaJpZM4HVJUE
.

@poine

I took it from https://github.com/MathewDenny/ORB_SLAM2; some of the comments seemed to suggest it works well. If I clone your repo, will that build and run fine? If so, I'll try that.

poine commented

I had a quick look at Mathew's repository. It looks like he wrote a
different map save/load code but included my binary vocabulary code, minus
the tool/bin_vocabulary program. Maybe you can get Mathew's code to build
by just adding the tools/bin_vocabulary.cc file from my repository.

On Thu, Aug 11, 2016 at 9:57 PM, MCoder1 notifications@github.com wrote:

@poine https://github.com/poine

I took it from https://github.com/MathewDenny/ORB_SLAM2; some of the
comments seemed to suggest it works well. If I clone your repo, will that
build and run fine? If so, I'll try that.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#19 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGTz89VKXvMJeyA_qg5Q5AAPzP6vX1tks5qe36OgaJpZM4HVJUE
.

yes poine is right. I got the same problem but when you just add the folder it works fine

hi, when I load the map, I want the color of map line is green, and when there is a new keyframe, the insert line is another color, but I found that the "drawkeyframe()" draw ALL the keyframes again. Do I think right? And I wonder wether the method of map-draw can be changed as keyframe one-by-one? May be it can save time..

@poine

I got it working over the weekend and am in a similar state where I'm able to save a map and then view the map, but what is the .ts file in restart_slam_on_images.cc?

poine commented

It has nothing to do with the map. It's just a text file holding lines with
images filename and timestamps.

On Aug 15, 2016 9:16 PM, "MCoder1" notifications@github.com wrote:

@poine https://github.com/poine

I got it working over the weekend and am in a similar state where I'm able
to save a map and then view the map, but what is the .ts file in
restart_slam_on_images.cc?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#19 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGTz47qcdwnKpFCI0x-XAjZegDNwjC5ks5qgLsOgaJpZM4HVJUE
.

Hi @poine (hi @shomin )
Thanks for the great job. I downloaded your code from Shomin's repository (https://github.com/shomin/ORB_SLAM2). I can build and run it from mono_kitti (or mono_tum), but it seems to not calling any SaveMap functionality you provided in map.cc. Do I need to add some codes or I'm using a wrong piece of code? (I would like to just save the map points not reuse them)

Hi @emphos1
I am new to ORB_SLAM and I am trapped in the same situation as you. I don't know if you have resolved this problem. If you did please tell me how to do with it. Thanks!

Hi @ywj447
Unfortunately I have not resolved the problem yet :(
I'm still waiting for getting response from @poine who is expert in this field.

Hello @emphos1 Hello @ywj447 ,

you cant find this functionality because both of them are using the ROS Examples and not the Examples of KITTI or TUM. So you have to implement it on your own what should be to diffcult because its the same as for the ROS Examples. So you just have to put this line where you want to save the map:
mpSLAM->SaveMap("enter here a string where to save the map");

Hi@chwimmer and thanks for your help
You mean I have to put mpSLAM->SaveMap("enter here a string where to save the map"); in the ros_rgbd.cc(ros_mono.cc and ros_stereo.cc), but I find that there is not a SaveMap.cc in the src file that is to say I have to write a SaveMap.cc on my own? I'm totally new in this field and have no idea how to going on.
Thanks again!

@ywj447:
Ok first the question: Are you using ROS?
When you are doing so and I expect you are using the code of shomin than its already impemented:
SaveMapCallback.

Than you just have to publish a string to the topic where you want so save the map: "/ORB_SLAM2/save_map".

If you are not using ROS you just have to add the Line
SLAM->SaveMap("enter here a string where to save the map");
in for example the rgbd_tum.cc

thank you very much @chwimmer
I tried it without ROS using RGB-D dataset, it work! But I saved the map as .vtk and .pcd, another obstacle occurs:

exbot@ubuntu:~/shomin$ pcl_viewer savedmap.pcd
The viewer window provides interactive commands; for help, press 'h' or 'H' from within the window.

Loading savedmap.pcd [pcl::PCDReader::readHeader] No points to read
exbot@ubuntu:~/shomin$

exbot@ubuntu:~/shomin$ pcl_viewer savedmap.vtk
The viewer window provides interactive commands; for help, press 'h' or 'H' from within the window.

Loading savedmap.vtk ERROR: In /build/buildd/vtk-5.8.0/IO/vtkDataReader.cxx, line 500
vtkPolyDataReader (0x8e44950): Unrecognized file type: * for file: savedmap.vtk
[done, 26 ms : 0 points]

Did I choose a wrong format of the map? if so, how could I open the map. When I fix this problem, I'm gonna try it in ROS-indigo.
I appreciate your generous help @chwimmer

@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.

@chwimmer
OK, now, I am crystal clear about it. Thanks again!

Hi @MathewDenny @chwimmer

I've cloned @MathewDenny's version and changed stereo_kitti.cc to accommodate the map saving and loading ability;

bool bReuseMap = false;
ORB_SLAM2::System* SLAM;
if (!strcmp(argv[4], "true")) {
    bReuseMap = true;
    SLAM = new ORB_SLAM2::System(argv[1],argv[2],ORB_SLAM2::System::STEREO,true, bReuseMap,  argv[5]);
}else{
    SLAM = new ORB_SLAM2::System(argv[1],argv[2],ORB_SLAM2::System::STEREO,true, bReuseMap);
}

where argv[5] is the map filename. I saved one map to file. All good. But when loading it, initially I got the input stream error. Following @chwimmer's advise, I changed

LoadMap(path_map); 

to

LoadMap(path_map.c_str()); 

But then I got the following error:

stereo_kitti: /usr/local/include/boost/archive/basic_binary_iprimitive.hpp:102: void boost::archive::basic_binary_iprimitive<Archive, Elem, Tr>::load(bool&) [with Archive = boost::archive::binary_iarchive; Elem = char; Tr = std::char_traits]: Assertion `0 == i || 1 == i' failed.

Seems to be formatting issue in the map binary? Any thoughts?
Much appreciated!

Bug fixed by initializing mbTrackInView in the MapPoint constructor. :)
It seems that SLAM is fine without initializing it. The default would be false. But the variable could be random after being saved and loaded via boost, and cannot pass this boost library loading trap.

@poine hello, I read your save/load map code and I have a question. It seems that you just save the map points, keyframes, tree and graph. Is it enough for global relocalization?? it seems that the KeyFrameDatabase is need by global relocalization...I do not know ....could you please give some explanation?

poine commented

Hi Ysunar

I rebuild the KeyframeDatabase when loading the map.

On Tue, Oct 11, 2016 at 5:41 AM, ysunar notifications@github.com wrote:

@poine https://github.com/poine hello, I read your save/load map code
and I have a question. It seems that you just save the map points,
keyframes, tree and graph. Is it enough for global relocalization?? it
seems that the KeyFrameDatabase is need by global relocalization...I do not
know ....could you please give some explanation?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#19 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGTz4opzDt59LWs3eLLm8msXlTn4j0Fks5qywVSgaJpZM4HVJUE
.

@poine @hangqiu @MathewDenny I have already tried your save/load map versions. They are all great. Yet I want to know if there is a way to save a partial map and later load that map so as to use it and complete it with new input data.

Hi, @poine
Thanks for your great work! I tried your restart_slam.cc and also get crash like @skylook . I noticed that in restart_slam.cc, there is a line

SLAM.ActivateLocalizationMode();

Does that mean localization mode is on? Due to your replies, it will work in localization mode. Do you have any suggestions on how to fix this? Thanks!

Hi,@MathewDenny i have tried your save/load map versions with camera on my computer ,but the result showed this:

:~/catkin_ws/src/mathew_ORB_SLAM2$ rosrun ORB_SLAM2 Mono Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml

Segmentation fault (core dumped)

can somebody tell me where's the problem or i miss some file?totally new in this field, hope to hear your suggestions.

Hello @Claire0409coder
The Segmentation fault is pretty weird, because when you start ORB_SLAM2 like you did you should run into this.
Thats because you didn’t add the argument if yo want to load the map or not.
Did you change the code? When you are checking only if(argc < 3) than you trying in the next step
if (!strcmp(argv[3], "true")) what would lead to an Segmentation fault.
Perhaps you can try to start the application with
rosrun ORB_SLAM2 Mono Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml false

Thanks!@chwimmer
It works! But what to do to turn this .bin map file to a pointcloud file or octomap for navigation?Just a .bin map is not enough

There is no public code available now to do this.
But it is not too difficult to do this. Just get the Mappoints of the Map and convert it in a OctoMap or a PCLPointcloud

Really thanks, I'll have a try!

yuyou commented

@poine both features are so interesting. Is it possible to share your Python binding somewhere? Thanks.

Hi @ywj447
Have you used Shomin's code (https://github.com/shomin/ORB_SLAM2) for saving/loading map? Is it working without ROS? I have installed Shomin's code successfully but when I run it, (mono_tum, mono_KITTI), it couldn't initialize itself so I can't see any point cloud or camera trajectory on the viewer. obviously, because of that, it would not save any map. Is Shomin's code only working for rgb-d?
Does anybody try another code for saving map without ROS? any suggestion?
Thanks

mtee commented

Does anybody esle get Segmentation Faults with the solutions of @hangqiu, @MathewDenny ?

Start processing sequence ...
Images in the sequence: 4661

Local Mapping STOP
Segmentation fault

From what I understand, it happens in Track() method of Tracking.cc in the first line of the else-block during the processing of the first frame already:

else
{
    // This can happen if tracking is lost
    mlRelativeFramePoses.push_back(mlRelativeFramePoses.back());  // Segfault during this call
    mlpReferences.push_back(mlpReferences.back());
    mlFrameTimes.push_back(mlFrameTimes.back());
    mlbLost.push_back(mState==LOST);
}

I have also noticed many debug statements that look like warnings:

Slam_latest_Map.bin : Map Loaded!
map point [7124] not found in KF 10
map point [7133] not found in KF 10
...

refernce KF - 29is not found for mappoint 29676
refernce KF - 29is not found for mappoint 29677

Update:
here is the actual error message from gdb:

Thread 1 "stereo_kitti" received signal SIGSEGV, Segmentation fault.
cv::Mat::Mat (this=0x10f42f90, m=...) at /usr/local/include/opencv2/core/mat.inl.hpp:416

416 step[0] = m.step[0]; step[1] = m.step[1];

am I doing anything wrong?

Update2: sure enough, if I start the tracking with the bUseMap = true, for the first frame
if(!mCurrentFrame.mTcw.empty() && mCurrentFrame.mpReferenceKF) this evaluates to false, mlRelativeFramePoses is indeed empty, hence mlRelativeFramePoses.back() is a null pointer, which causes the segfault mentioned above. I don't comprehend yet, how exactly the Track() method works, but it's fair to say that there is some sort of conflict due to the added map loading. It surprises me though, that nobody reported the same problem yet, as it does not seem setup-specific.

@emphos1, I don't have ROS and I also don't see any dependencies on ROS in the loading/saving classes, so I assume ROS is not needed. The map is saved in my case, but there is a problem with tracking when its loaded back.

yuyou commented

I created a fork and merged few fixed from the other contributors. The fork works with the binary vocabulary and map saving and loading. Also a Docker build with Docker file is available.

@poine I have tried your save/load map, but after loading the map, it can only run at LOCALIZATION mode, when I change it into SLAM mode, it lost, the map points are all cleared.

Hi all, I wanna discuss about the tracking time on localization mode...
I ran with KITTI dataset stereo seq. 12 with 32 core CPU, the mean tracking time is 0.18 s... Is it a reasonable number for only visual odometry (Not the whole SLAM)? Thanks in adavnce!

@poine I am trying to port your save & load map code in windows it works in debug mode but not release. And in ubuntu it works.

Is someone tried to save & load map in windows?

@francotestori @poine @hangqiu @MathewDenny, I have the same question as below. Would it be possible, starting with your code, to run Slam, save a map, then run again using that map as a base, but add to it as tracking adds more map points? What i would like to do is run stereo slam, save a map, and load it into mono slam to use as a world scale initialization. Thanks!

I have already tried your save/load map versions. They are all great. Yet I want to know if there is a way to save a partial map and later load that map so as to use it and complete it with new input data.

mtee commented

@skylook @lschaupp @jiuerbujie Has anybody been successful in working around the crash in the line
mlRelativeFramePoses.push_back(mlRelativeFramePoses.back());
?
The issue persists for me in all forks, so I assume it works like this at least for authors of the forks? It's clear, that the reason for the crash is that mlRelativeFramePoses is empty. But why is it not empty for some but not others? Is it a OS-dependent thing, connected to this problem:

I have found a problem of map load function. Because mspMapPoints is stored in std::set which means when using
std::vector<MapPoint*> amp = GetAllMapPoints();
the return vector is not always in the same order (set is ordered by the pointer address). That makes _ReadKeyFrame() function gets a wrong result.

Sure, if I add a check for _(mlRelativeFramePoses.empty())_it does not crash in the line, but I am not sure, whether the algorithm works as intended then.

I've run @MathewDenny 's code and saved Slam_latest_Map.bin. But it is really not clear for me how to load and use it? Any help!

Thats because @MathewDenny hard coded the path to the Map here
You can change it and for example give the constructor of System the path to the map so you have:
LoadMap(path_map.c_str());
with the new constructor:
System::System(const string &strVocFile, const string &strSettingsFile, const eSensor sensor,const string &path_map, const bool bUseViewer, const bool bReuse)

I've builded with full to path map and the result is
map_not_used1
map_not_used2

Hi @mtee ! Thanks for your debug work. I repeat the bug you mentioned. The cause of core dumped is that, in the Tracking.cc with line of 537, the list named as "mlRelativeFramePoses" is empty. Hence it's impossible for "mlRelativeFramePoses.back()" to give any return value. To solve this, it's recommended to check the size of "mlRelativeFramePoses". DO NOT CALL "mlRelativeFramePoses.back()" when it is size of 0. I replaced the original line with following codes:
if(mlRelativeFramePoses.size() != 0)
{
mlRelativeFramePoses.push_back(mlRelativeFramePoses.back());
}
And now it should work fine.

Thanks to @mtee for locating the problem. Without your help I'd never know what happened.

Hi all, has anyone successfully got this running with map save and load? Which repo / branch is working? Thanks!

Hi all,
I have just combined map save/load and binary vocabulary with raulmur's latest updates(commit 5ad09bf)
Welcome to have a try at https://github.com/Alkaid-Benetnash/ORB_SLAM2. See README.md for common usage.
I use boost serialization library, and let it handle complicated pointer reference graph as well. I have tested mono slam with boost 1.64 on linux, and it seems to work well most of the time.
@francotestori @antithing I think my solution suits your needs.

Hi @Alkaid-Benetnash , thanks! I am trying to build your code, and am getting these errors:

error LNK2001: unresolved external symbol "private: void __cdecl ORB_SLAM2::KeyFrame::serialize<class boost::archive::binary_oarchive>(class boost::archive::binary_oarchive &,unsigned int)" (??$serialize@Vbinary_oarchive@archive@boost@@@KeyFrame@ORB_SLAM2@@AEAAXAEAVbinary_oarchive@archive@boost@@I@Z)
error LNK2001: unresolved external symbol "private: void __cdecl ORB_SLAM2::KeyFrame::serialize<class boost::archive::binary_iarchive>(class boost::archive::binary_iarchive &,unsigned int)" (??$serialize@Vbinary_iarchive@archive@boost@@@KeyFrame@ORB_SLAM2@@AEAAXAEAVbinary_iarchive@archive@boost@@I@Z)
error LNK2001: unresolved external symbol "public: __cdecl ORB_SLAM2::KeyFrame::KeyFrame(void)" (??0KeyFrame@ORB_SLAM2@@QEAA@XZ)

the ORBSLAM lib builds ok, but when I call it from my project, i get the errors.
Have you added any extra dependencies here? Thanks again!

I am on windows, with boost 1.63

@antithing
I didn't add any other extra dependencies except boost. I am not familiar with windows build system, but
the symbol can't be resolved in the first two lines can be found declared here and defined here.
May be you should check the macro defined in cmake configuration: FUNC_MAP_SAVE_LOAD

Thanks @Alkaid-Benetnash, it was actually because I was using an old version of DBoW2, now I have it building.

Quick question though... do you have an example the uses your updates? I have tried:

SLAM = new ORB_SLAM2::System(strORBvoc, strCamSet, ORB_SLAM2::System::STEREO, false,true);

and

SLAM = new ORB_SLAM2::System(strORBvoc, strCamSet, ORB_SLAM2::System::STEREO, false,false);

and both seem to try and load a map file. It doesn't exist, as I haven't saved it yet!

How can I run and save a map?

Thanks again!

@antithing
Please read the Section 11 of the README.md
As long as you set the mapfile in the setting file, System always tries to load the map.
With SLAM = new ORB_SLAM2::System(strORBvoc, strCamSet, ORB_SLAM2::System::STEREO, false, true);, no matter you have had a map already or not, System will save a new map when ShutDown.

Dear @Alkaid-Benetnash ,
Thanks for sharing.

But I get some error when I run build.sh and build_ros.sh

When I run build.sh, it will get some warning from System.h and System.cc, but it still can run pass,
then I run build_ros.sh, it will get error about undefined reference to ORB_SLAM2::System::System

Did you have ever seen this error?
the log message as following, thank you for your help.

build.sh

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") 
-- Compile With map save/load function
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/ros_build/ORB_SLAM2/build
Scanning dependencies of target bin_vocabulary
Scanning dependencies of target ORB_SLAM2
[  2%] Building CXX object CMakeFiles/bin_vocabulary.dir/Vocabulary/bin_vocabulary.cpp.o
[  5%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/System.cc.o
[  8%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/LocalMapping.cc.o
[ 11%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Tracking.cc.o
[ 14%] Linking CXX executable ../Vocabulary/bin_vocabulary
[ 14%] Built target bin_vocabulary
[ 17%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/LoopClosing.cc.o
In file included from /home/ubuntu/ros_build/ORB_SLAM2/src/System.cc:23:0:
/home/ubuntu/ros_build/ORB_SLAM2/include/System.h: In constructor ‘ORB_SLAM2::System::System(const string&, const string&, ORB_SLAM2::System::eSensor, bool, bool)’:
/home/ubuntu/ros_build/ORB_SLAM2/include/System.h:183:10: warning: ‘ORB_SLAM2::System::mbDeactivateLocalizationMode’ will be initialized after [-Wreorder]
     bool mbDeactivateLocalizationMode;
          ^
/home/ubuntu/ros_build/ORB_SLAM2/include/System.h:150:10: warning:   ‘bool ORB_SLAM2::System::is_save_map’ [-Wreorder]
     bool is_save_map;
          ^
/home/ubuntu/ros_build/ORB_SLAM2/src/System.cc:38:1: warning:   when initialized here [-Wreorder]
 System::System(const string &strVocFile, const string &strSettingsFile, const eSensor sensor,
 ^
[ 20%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/ORBextractor.cc.o
[ 23%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/ORBmatcher.cc.o
[ 26%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/FrameDrawer.cc.o
[ 29%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Converter.cc.o
[ 32%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/MapPoint.cc.o
[ 35%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/KeyFrame.cc.o
[ 38%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Map.cc.o
[ 41%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/MapDrawer.cc.o
[ 44%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Optimizer.cc.o
[ 47%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/PnPsolver.cc.o
[ 50%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Frame.cc.o
[ 52%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/KeyFrameDatabase.cc.o
[ 55%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Sim3Solver.cc.o
[ 58%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Initializer.cc.o
[ 61%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Viewer.cc.o
[ 64%] Linking CXX shared library ../lib/libORB_SLAM2.so
[ 64%] Built target ORB_SLAM2
Scanning dependencies of target mono_euroc
Scanning dependencies of target mono_tum
Scanning dependencies of target mono_kitti
Scanning dependencies of target rgbd_tum
[ 67%] Building CXX object CMakeFiles/mono_euroc.dir/Examples/Monocular/mono_euroc.cc.o
[ 70%] Building CXX object CMakeFiles/mono_tum.dir/Examples/Monocular/mono_tum.cc.o
[ 73%] Building CXX object CMakeFiles/mono_kitti.dir/Examples/Monocular/mono_kitti.cc.o
[ 76%] Building CXX object CMakeFiles/rgbd_tum.dir/Examples/RGB-D/rgbd_tum.cc.o
[ 79%] Linking CXX executable ../Examples/Monocular/mono_tum
[ 82%] Linking CXX executable ../Examples/RGB-D/rgbd_tum
[ 85%] Linking CXX executable ../Examples/Monocular/mono_euroc
[ 88%] Linking CXX executable ../Examples/Monocular/mono_kitti
[ 88%] Built target mono_tum
Scanning dependencies of target stereo_kitti
[ 91%] Building CXX object CMakeFiles/stereo_kitti.dir/Examples/Stereo/stereo_kitti.cc.o
[ 91%] Built target rgbd_tum
[ 91%] Built target mono_euroc
Scanning dependencies of target stereo_euroc
[ 94%] Building CXX object CMakeFiles/stereo_euroc.dir/Examples/Stereo/stereo_euroc.cc.o
[ 94%] Built target mono_kitti
[ 97%] Linking CXX executable ../Examples/Stereo/stereo_kitti
[100%] Linking CXX executable ../Examples/Stereo/stereo_euroc
[100%] Built target stereo_kitti
[100%] Built target stereo_euroc
Converting vocabulary to binary version
BoW load/save benchmark
Loading fom text: 7.93s
Saving as binary: 0.23s

build_ros.sh

Building ROS nodes
-- 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
-- Found PythonInterp: /usr/bin/python (found version "2.7.12") 
[rosbuild] Building package ORB_SLAM2
[rosbuild] Cached build flags older than manifests; calling rospack to get flags
-- Using CATKIN_DEVEL_PREFIX: /home/ubuntu/ros_build/ORB_SLAM2/Examples/ROS/ORB_SLAM2/build/devel
-- Using CMAKE_PREFIX_PATH: /home/ubuntu/ros_build/catkin_ws/devel;/opt/ros/kinetic
-- This workspace overlays: /home/ubuntu/ros_build/catkin_ws/devel;/opt/ros/kinetic
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Skip enable_testing() for dry packages
-- Using CATKIN_TEST_RESULTS_DIR: /home/ubuntu/ros_build/ORB_SLAM2/Examples/ROS/ORB_SLAM2/build/test_results
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.6
[rosbuild] using multiarch 'x86_64-linux-gnu' for finding Boost
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
[rosbuild] Including /opt/ros/kinetic/share/roslisp/rosbuild/roslisp.cmake
[rosbuild] Including /opt/ros/kinetic/share/roscpp/rosbuild/roscpp.cmake
[rosbuild] Including /opt/ros/kinetic/share/rospy/rosbuild/rospy.cmake
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") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/ros_build/ORB_SLAM2/Examples/ROS/ORB_SLAM2/build
Scanning dependencies of target rospack_genmsg_libexe
[  0%] Built target rospack_genmsg_libexe
Scanning dependencies of target rosbuild_precompile
[  0%] Built target rosbuild_precompile
Scanning dependencies of target Mono
Scanning dependencies of target MonoAR
Scanning dependencies of target RGBD
Scanning dependencies of target Stereo
[ 11%] Building CXX object CMakeFiles/Mono.dir/src/ros_mono.cc.o
[ 22%] Building CXX object CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o
[ 33%] Building CXX object CMakeFiles/Stereo.dir/src/ros_stereo.cc.o
[ 44%] Building CXX object CMakeFiles/MonoAR.dir/src/AR/ros_mono_ar.cc.o
[ 55%] Linking CXX executable ../Mono
[ 66%] Building CXX object CMakeFiles/MonoAR.dir/src/AR/ViewerAR.cc.o
CMakeFiles/Mono.dir/src/ros_mono.cc.o: In function `main':
ros_mono.cc:(.text.startup+0x104): undefined reference to `ORB_SLAM2::System::System(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ORB_SLAM2::System::eSensor, bool)'
collect2: error: ld returned 1 exit status
CMakeFiles/Mono.dir/build.make:270: recipe for target '../Mono' failed
make[2]: *** [../Mono] Error 1
CMakeFiles/Makefile2:718: recipe for target 'CMakeFiles/Mono.dir/all' failed
make[1]: *** [CMakeFiles/Mono.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 77%] Linking CXX executable ../Stereo
[ 88%] Linking CXX executable ../RGBD
CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o: In function `main':
ros_rgbd.cc:(.text.startup+0x111): undefined reference to `ORB_SLAM2::System::System(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ORB_SLAM2::System::eSensor, bool)'
collect2: error: ld returned 1 exit status
CMakeFiles/RGBD.dir/build.make:270: recipe for target '../RGBD' failed
make[2]: *** [../RGBD] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/RGBD.dir/all' failed
make[1]: *** [CMakeFiles/RGBD.dir/all] Error 2
CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: In function `main':
ros_stereo.cc:(.text.startup+0xaa8): undefined reference to `ORB_SLAM2::System::System(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ORB_SLAM2::System::eSensor, bool)'
collect2: error: ld returned 1 exit status
CMakeFiles/Stereo.dir/build.make:270: recipe for target '../Stereo' failed
make[2]: *** [../Stereo] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/Stereo.dir/all' failed
make[1]: *** [CMakeFiles/Stereo.dir/all] Error 2
[100%] Linking CXX executable ../MonoAR
CMakeFiles/MonoAR.dir/src/AR/ros_mono_ar.cc.o: In function `main':
ros_mono_ar.cc:(.text.startup+0xbfc): undefined reference to `ORB_SLAM2::System::System(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ORB_SLAM2::System::eSensor, bool)'
collect2: error: ld returned 1 exit status
CMakeFiles/MonoAR.dir/build.make:352: recipe for target '../MonoAR' failed
make[2]: *** [../MonoAR] Error 1
CMakeFiles/Makefile2:820: recipe for target 'CMakeFiles/MonoAR.dir/all' failed
make[1]: *** [CMakeFiles/MonoAR.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

@stevenyslin I didn't test with ros before. It seems like you need to add USE_MAP_SAVE_LOAD definition in the build_ros.sh as well.
As for the compilation warning, I think it also exists in this upstream repo and actually there should be so many warnings that I finally gave up fixing them.

Dear @Alkaid-Benetnash ,
I found the warning reason, it is in System.h, you can put the FUNC_MAP_SAVE_LOAD definition in the last.

   // Change mode flags
    std::mutex mMutexMode;
    bool mbActivateLocalizationMode;
    bool mbDeactivateLocalizationMode;

    // Tracking state
    int mTrackingState;
    std::vector<MapPoint*> mTrackedMapPoints;
    std::vector<cv::KeyPoint> mTrackedKeyPointsUn;
    std::mutex mMutexState;

// add here
#ifdef FUNC_MAP_SAVE_LOAD
    string mapfile;
    bool is_save_map;
#endif
};

}// namespace ORB_SLAM

#endif // SYSTEM_H

But the error build in build_ros.sh, I still cannot resolve, sh, should I add anything in ORB_SLAM2/Examples/ROS/ORB_SLAM2CMakeLists.txt ?
And my environment is as following:
Ubuntu 16.04
gcc : 5.4.0
boost: 1.64

May I refer your environment? Thank you so much.

@stevenyslin
Yes, the compilation warning is my fault and I have fixed it.
My environment is:
Archlinux, gcc 7.1.1, boost: 1.64
I think the error has nothing to do with environment.

I believe it is the conditional compilation which really troubles you. Because this functionality doesn't hurt performance much and conditional compilation is annoying, I have removed extra conditional compilation flags now.
Please master branch try again, I'm looking forward to your success.

Dear @Alkaid-Benetnash ,
It worked!! Really thanks for your quickly responese.

But there is a little problem, when I first open Mono library,
it will show "Cannot Open Mapfile: map.bin, Create a new one",
then I open it a while, then "ctrl + c " to close,
but I cannot see map.bin in local folder.
Thank you for your help.

@stevenyslin
Please read the readme first.
I think how to use this functionality is explained clearly there.