Skip to content
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

saving and loading maps #526

Open
hesamira opened this issue Feb 21, 2018 · 9 comments
Open

saving and loading maps #526

hesamira opened this issue Feb 21, 2018 · 9 comments

Comments

@hesamira
Copy link

hesamira commented Feb 21, 2018

Hello,
I want to save map and load the data in ORB_SLAM2. I have performed the changes in ORBSLAM2 (I have made some changes to System.cc, System.h, and ros_mono.cc.). based on : raulmur/ORB_SLAM#5

For System.cc, I added the following code:

void System::SaveMapPoints(const string &filename) {
cout << endl << "Saving map points to " << filename << " ..." << endl;

vector<MapPoint*> vpMPs = mpMap->GetAllMapPoints();

// Transform all keyframes so that the first keyframe is at the origin.
// After a loop closure the first keyframe might not be at the origin.
ofstream f;
f.open(filename.c_str());
f << fixed;

for(size_t i=0; i<vpMPs.size(); i++) {
    MapPoint* pMP = vpMPs[i];

    if(pMP->isBad())
        continue;

    cv::Mat MPPositions = pMP->GetWorldPos();

    f << setprecision(7) << " " << MPPositions.at<float>(0) << " " << MPPositions.at<float>(1) << " " << MPPositions.at<float>(2) << endl;
}

f.close();
cout << endl << "Map Points saved!" << endl;

}

For System.h, I added the following code:

void SaveMapPoints(const string &filename);

For ros_mono.cc, I added the following code:

SLAM.SaveMapPoints("MapPointsSave.txt");

The MapPointsSave.txt contains all the map points in terms of global locations, i.e., xyz coordinate. But I could not save a map and load the data. I also have created a package for pcd (http://pointclouds.org/documentation/tutorials/writing_pcd.php) which I can convert the saved map points in .txt file into .pcd file. I could not run it. I have tested it by:
$ ./pcd_write

I have used Ubuntu 14.04, ROS indigo and OpenCV 2.4.13.

Please offer help.
Thanks.

@hesamira hesamira changed the title saving/loading maps saving and loading maps Feb 21, 2018
@AlejandroSilvestri
Copy link

@hesamira ,

What do you mean when you say "I could not save a map"?

Does your code abort with errors? Does MapPointsSave.txt generates properly?

@hesamira
Copy link
Author

hesamira commented Mar 4, 2018

Dear @AlejandroSilvestri ,
I have done the above changes in my code, but I could not save the map.
I have not faced with any error, but I could not save the map. So, MapPointsSave.txt has not been generated.

@AlejandroSilvestri
Copy link

@hesamira,

How do you call SLAM.SaveMapPoints("MapPointsSave.txt")?

Are you sure this method is invoked at all?

@hesamira
Copy link
Author

hesamira commented Mar 10, 2018

@AlejandroSilvestri ,
I am not sure. I have used this link:
raulmur/ORB_SLAM#5
Can you suggest the better code for save map and load the data in orbslam2? I have used different codes such as poine 's code and math 's code, but I did not succeed.

@AlejandroSilvestri
Copy link

@hesamira ,

There are many ways around to save maps in orb.slam2, but any of them well implemented and documented, perhaps with the exception of poine's.

Make sure you call your savemap in some point of orb.slam2's code. Maybe at the end, near SaveKeyFrameTrajectoryTUM, for example.

Put a console mark (cout << "Saving!" << endl;) as a way to verify your function has been invoked.

@hesamira
Copy link
Author

hesamira commented Mar 23, 2018

@AlejandroSilvestri ,
Hi,
I have used MathewDenny ' code https://github.com/MathewDenny/ORB_SLAM2 . When I have run the ros example, I have got a problem.

sami@sami:/orbslam2_catkin_ws$ source devel/setup.bash
sami@sami:
/orbslam2_catkin_ws$ rosrun ORB_SLAM2 Mono /home/sami/orbslam2_catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml

Usage: rosrun ORB_SLAM2 Mono path_to_vocabulary path_to_settings

I have checked my ROS master. I have checked my path. There are no errors. based on : #43
I think that there is a problem in ros_mono.cc file. Is it correct? I do not know where is the problem. I have tried a lot.
your answer is very important to me. I need to save map and load the data.

Please offer help.
Thanks.

@rahulsharma11
Copy link

Hi @hesamira ,
I checked this and able to save the map.txt file.

@AlejandroSilvestri
Copy link

Hi @rahulsharma11 , did you miss a link? What did you check?

@hesamira , sorry I missed your post. I can't help you though. I'm not familiar with ROS nor have experience with MathewDenny's map save.

@rahulsharma11
Copy link

Hi @AlejandroSilvestri ,
I just confirmed what @hesamira was asking (to save the FrameTrajectory data).
Firstly i was also not getting the file, then i realise that i modified the code to run in infinite loop with live camera feedback. There i just do Ctrl+C to exit the code. In that case, "SaveMapPoints()" was not able to properly invoked. Then i just added added "waitkey()" to properly exit and then it was able to call ""SaveMapPoints()" function.
So in case of @hesamira , the function is not called properly.

Also further this link might be useful, as i got the map.bin file generated and also used that in localization purpose.
"#381"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants