raulmur / ORB_SLAM2

Real-Time SLAM for Monocular, Stereo and RGB-D Cameras, with Loop Detection and Relocalization Capabilities
Other
9.26k stars 4.69k 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

poine commented 8 years ago

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 https://github.com/raulmur/ORB_SLAM2/issues/19#issuecomment-239273185, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGTz89VKXvMJeyA_qg5Q5AAPzP6vX1tks5qe36OgaJpZM4HVJUE .

chwimmer commented 8 years ago

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

qianwenjun0801 commented 8 years ago

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

MCoder1 commented 8 years ago

@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 8 years ago

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 https://github.com/raulmur/ORB_SLAM2/issues/19#issuecomment-239900119, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGTz47qcdwnKpFCI0x-XAjZegDNwjC5ks5qgLsOgaJpZM4HVJUE .

emphos1 commented 7 years ago

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)

ywj447 commented 7 years ago

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!

emphos1 commented 7 years ago

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.

chwimmer commented 7 years ago

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

ywj447 commented 7 years ago

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!

chwimmer commented 7 years ago

@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

ywj447 commented 7 years ago

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

chwimmer commented 7 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.

ywj447 commented 7 years ago

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

hangqiu commented 7 years ago

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!

hangqiu commented 7 years ago

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.

ysunar commented 7 years ago

@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 7 years ago

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 https://github.com/raulmur/ORB_SLAM2/issues/19#issuecomment-252803655, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGTz4opzDt59LWs3eLLm8msXlTn4j0Fks5qywVSgaJpZM4HVJUE .

francotestori commented 7 years ago

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

jiuerbujie commented 7 years ago

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!

Claire0409coder commented 7 years ago

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.

chwimmer commented 7 years ago

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

Claire0409coder commented 7 years ago

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

chwimmer commented 7 years ago

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

Claire0409coder commented 7 years ago

Really thanks, I'll have a try!

yuyou commented 7 years ago

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

emphos1 commented 7 years ago

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 7 years ago

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 7 years ago

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.

ygx2011 commented 7 years ago

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

shihclin commented 7 years ago

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!

microcompunics commented 7 years ago

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

antithing commented 7 years ago

@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 7 years ago

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

romdos commented 7 years ago

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!

chwimmer commented 7 years ago

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)

romdos commented 7 years ago

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

GarfieldTay commented 7 years ago

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.

antithing commented 7 years ago

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

Alkaid-Benetnash commented 7 years ago

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.

antithing commented 7 years ago

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

Alkaid-Benetnash commented 7 years ago

@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

antithing commented 7 years ago

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!

Alkaid-Benetnash commented 7 years ago

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

stevenyslins commented 7 years ago

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
Alkaid-Benetnash commented 7 years ago

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

stevenyslins commented 6 years ago

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.

Alkaid-Benetnash commented 6 years ago

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

stevenyslins commented 6 years ago

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.

Alkaid-Benetnash commented 6 years ago

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