-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map save load and bin vocabulary #381
base: master
Are you sure you want to change the base?
Map save load and bin vocabulary #381
Conversation
f2fea44
to
b458bf6
Compare
I needed this functionality and your code worked like a charm. There's a couple simple bugs that need to be fixed when you build without -DUSE_MAP_SAVE_LOAD=1. Also it would be great if you changed your documentation slightly: Since "Examples/settings_with_map.yaml" didn't exist in the pull request, I was a little confused and had to look into the code to see what it referred to. Perhaps a better way to document the above is: |
a6e5afa
to
08e3531
Compare
@xinyutan17 |
I'm having trouble with the MapSave function resulting in segfault. I'm fairly certain it's due to multi-threading issues because of not locking the mutex for the "mutex needed variables" during serialization in KeyFrame.cc. Is there a reason why you did not lock the mutex? Otherwise I will try to implement that soon and see whether or not it works. Also lines 420-425 in MapPoint.cc may be causing a segfault since you initialize mpReplaced to a NULL pointer which will be serialized on save, deserialized on load, and then referenced by the algorithm:
|
@xinyutan17 As for the |
Okay, thanks! Your explanations for both the mutex and the NULL makes sense. I was experiencing issues with saving a map that was too large (because the saving operation wouldn't complete before the process was killed by ROS), so I created a SaveMap button in the Pangolin viewer to save the map at any time. This probably caused my issues with the mutexes. |
ba416ed
to
fea885e
Compare
mutex is locked now, will it solve your problems? |
Yes mutex locking does solve the segfault problem. (I implemented it in a similar fashion the rest of the code does it using for example It doesn't trigger out of memory. I believe ROS first sends a sigterm, and if the node is taking too long to exit (in this case because it's saving a 400 MB map file), ROS sends a sigkill and I end up with a corrupted map.bin file. |
Hi @Alkaid-Benetnash. This code is pretty awesome and does most of what I want! Kudos! However, I am having a problem with segfaults with a loaded map. It seems that if I am using an already created map with a new video, I sometimes get a segfault. What is interesting is that the segfault either happens almost right away, or it happens at the place where it would be able to relocalize into the old map. Any thoughts? Have you encountered this? |
@bmende I am happy that this code can help you. This code indeed crashes at certain circumstances sometimes. I didn't port later changes to this pull request branch. Can you try the master branch of my fork? |
Thanks @Alkaid-Benetnash for the map saving/load feature and it works nicely. Just one question about the In the end of System::LoadMap, I did something like this. Please correct me if it is wrong.
|
update README.md for map save/load and binary vocabulary format just use boost to serialization to handle complicated pointer reference graph.
fea885e
to
cb63a7c
Compare
@yuyou |
@Alkaid-Benetnash I found the segfault! and how to fix it! In Tracking.cc, during the relocalization function (starts on line 1343), we set the mCurrentFrame.mTcw to an estimated pose and then try to refine it. But if we can't refine it enough, then we exit the relocalization function without emptying the mTcw pose matrix on the current frame. Then, later in Track(..) we try to save the the current pose in order to reconstruct the trajectory later. In order to do this we check if the current frame has a pose, and since it is not empty because of the checks during reloc, we try to add a non-existent reference keyframe. So the solution is in relocalization to set the mTcw matrix back to empty before exiting reloc if we fail to relocalize. line: 1494 in Tracking.cc
|
During the relocalization function (starts on line 1343), we set the mCurrentFrame.mTcw to an estimated pose and then try to refine it. But if we can't refine it enough, then we exit the relocalization function without emptying the mTcw pose matrix on the current frame. Then, later in Track(..) we try to save the the current pose in order to reconstruct the trajectory later. In order to do this we check if the current frame has a pose, and since it is not empty because of the checks during reloc, we try to add a non-existent reference keyframe. So the solution is in relocalization to set the mTcw matrix back to empty before exiting reloc if we fail to relocalize. by @bmende
@xinyutan17 I have check my source code, the git log contains the Alkaid patch as follows, So does this patch fix your segfault already or I have the other segfault case? @Alkaid-Benetnash Is the segfault in SaveMap function solved or it still happens in some case?My problem still exists, and 100% can be reproduced the segfaults. The files link (video sequences, ZED_stereo_video.yaml, modified stereo_kitti.cc) are listed as below, Google Drive - ORB_SLAM Could you do me a favor to check it? I really appreciate your help. Here is the backtrace when segfault happened. |
@Alkaid-Benetnash |
@finphin And I want to comment on the "map size", I found that many unused MapPoint and KeyFrame (e.g. marked with |
@Alkaid-Benetnash Besides, due to the stack size issue is caused by deep call stack, may I know the related between KFs/MPs and stack size? I have to estimate the stack size if map grows bigger. |
Don't need the dataset anymore.
Sorry, I can't estimate a sufficient stack size, either. I think there are two reasons for the deep call stack:
|
@bmende still getting a segfault after loading map when pushing new images... im researching this issue |
@Alkaid-Benetnash You mentioned other threads are guaranteed to be closed. But this is not the case for me. The BA threads generated by LoopClosing are not closed for some cases. The system will get stuck at BA forever. I am not sure about the exact reason yet. If I break out from waiting BA finish, the map cannot be saved. Does anyone have experience on this problem? ? |
@rpfly3 do you invoke the System::SaveMap() at arbitrary place in the code or invoke it through System::ShutDown() ? |
@Alkaid-Benetnash I invoked savemap after waiting other threads to shutdown in System::ShutDown. I read the loop closing code. I found the main reasons are BA threads are not well managed. These threads are just left there. There could be BA threads and they probably always run without finish. But I have no idea on how to solve it yet. |
@Alkaid-Benetnash @finphin I am getting a similar error where I am able to load maps that are smaller but get errors with bigger maps. I tried increasing the stack size in my ros_stereo.cc file right after I initialize and start ROS, but this did not work. Here is the error I am getting:
Any help or guidance on this would be very much appreciated, thank you in advance! |
@ksivakumar Have you solved your problems? Can you use the |
@Alkaid-Benetnash I create a new pull request solving the bugs. Plz checkout my PR: #638 |
I will check your PR and see if I can merge it to my fork. I guess raulmur will never merge these PRs. |
Hi @Alkaid-Benetnash, In order to make it more user friendly, I add a button on the viewer (image below). Like this, the user can save the map when he wants instead of shutdown ORB-SLAM. However, doing that I have sometimes some issues "Segmentation fault (core dumped)".
In the terminal I have this:
As you can see it works two times and then it crashes when writing mpMap to oa.
Do you think it's because of multithreading ? |
@PierBJX Can you try my master branch? (I gave up maintaining this PR for now, since it won't be merged anyway). I just commit |
@Alkaid-Benetnash Finally, I succeeded to fix it. I just needed to stop the local mapping, save the map and release after. |
Hi @PierBJX , @Alkaid-Benetnash , |
This is not in this pull request. Indeed, only @Alkaid-Benetnash works on this pull request.
Yes, I think @Alkaid-Benetnash only did it for monocular |
Hi @PierBJX , Can you tell me how can i modify that option on GUI? |
In viewer.cc after Then in the while loop add these lines :
Then in System.cc modify the function SaveMap like this:
|
Hi @PierBJX , |
Sorry I forgot to remove it. It's because I modify a lot ORB-SLAM with many functionalities. |
Thanks for the guidance. And one more question- |
If the load map is done during the initialization it will be fine, no need to modify LoadMap(). No I didn't |
Thanks @PierBJX . And how can i view the generated map.bin file separately from Orbslam. Any tool? |
Honestly, I do not know about stereo with ORB-SLAM sorry ...
No you can not because it is only for ORB-SLAM. What you can do is save the pointclouds. |
@PierBJX |
Great job! I've wanted this functionality so much. One question: |
@Toraudonn |
Thanks. |
Hi to all, |
thank you for your work. I just compiled your code, but I have some doubts about saving and loading maps with monocular and binocular cameras, because they run on ros. Can you tell me how I should modify the code? Looking forward to hearing from you.thanks in advance |
Binary vocabulary format is much faster than text. And I am sorry that I can't find out who really contribute related code.
implement #19 with the help of boost serialization library.