66#include " kitti_tools.h"
77#include < limits>
88#include " orb_slam/include/System.h"
9+ #include < yaml-cpp/yaml.h>
10+ #include < vector>
11+ #include < map>
912
1013int main (int argc, char ** argv){
11- if (argc < 8 ){
12- std::cout << " Got " << argc - 1 << " Parameters, but expected 7" ;
13- throw std::invalid_argument (" Expected parameters: Twc_file Twl_file res_file orb_setting_file orb_vocabulary_file keyFrame_dir map_file" );
14+ if (argc < 4 ){
15+ std::cerr << " Got " << argc - 1 << " Parameters, but Expected parameters: yaml_file orb_setting_file orb_vocabulary_file" << std::endl;
1416 exit (0 );
1517 }
16- std::vector<Eigen::Isometry3d> vTwc, vTwl;
17- std::string TwcFilename (argv[1 ]), TwlFilename (argv[2 ]), resFileName (argv[3 ]);
18- std::string ORBSetFilename (argv[4 ]), VocFilename (argv[5 ]), KeyFrameDir (argv[6 ]), MapFileNmae (argv[7 ]);
18+ std::string config_file (argv[1 ]), ORBSetFilename (argv[2 ]), VocFilename (argv[3 ]);
19+ YAML::Node config = YAML::LoadFile (config_file);
20+ std::string base_dir = config[" BaseDir" ].as <std::string>();
21+ checkpath (base_dir);
22+ std::vector<Eigen::Isometry3d> vTwc, vTwl, vTwlraw;
23+ std::string TwcFilename = base_dir + config[" VOFile" ].as <std::string>();
24+ std::string TwlFilename = base_dir + config[" LOFile" ].as <std::string>();
25+ std::string resFileName = base_dir + config[" ResFile" ].as <std::string>();
26+ std::string KeyFrameDir = base_dir + config[" KeyFrameDir" ].as <std::string>();
27+ std::string KyeFrameIdFile = base_dir + config[" VOIdFile" ].as <std::string>();
28+ std::string MapFileNmae = base_dir + config[" MapFile" ].as <std::string>();
29+ std::map<std::string, int > method_options = config[" method_options" ].as <std::map<std::string, int > >();
30+ std::string method = config[" method" ].as <std::string>();
31+ assert (method_options.count (method)>0 );
32+ std::cout << " Use " << method << " Bundle Adjustment for calibration." << std::endl;
1933 ReadPoseList (TwcFilename, vTwc);
20- ReadPoseList (TwlFilename, vTwl);
34+ ReadPoseList (TwlFilename, vTwlraw);
35+ YAML::Node FrameIdCfg = YAML::LoadFile (KyeFrameIdFile);
36+ std::vector<int > vKFFrameId = FrameIdCfg[" mnFrameId" ].as <std::vector<int >>();
37+ for (auto &KFId:vKFFrameId)
38+ vTwl.push_back (vTwlraw[KFId]);
39+ vTwlraw.clear ();
2140 std::cout << " Load " << vTwc.size () << " Twc Pose files." << std::endl;
2241 std::cout << " Load " << vTwl.size () << " Twl Pose files." << std::endl;
2342 assert (vTwc.size ()==vTwl.size ());
@@ -31,8 +50,7 @@ int main(int argc, char** argv){
3150 double s;
3251
3352
34- // writePose(resFileName, rigidTCL, s);
35- // std::cout << "Result of Hand-eye Calibration saved to " << resFileName << std::endl;
53+
3654 ORB_SLAM2::System VSLAM (VocFilename, ORBSetFilename, ORB_SLAM2::System::MONOCULAR, false );
3755 VSLAM.Shutdown (); // Do not need any thread
3856 VSLAM.RestoreSystemFromFile (KeyFrameDir, MapFileNmae);
@@ -44,28 +62,36 @@ int main(int argc, char** argv){
4462 std::cout << " s :" << s << std::endl;
4563
4664 std::tie (RCL,tCL,s) = HECalibRobustKernelg2o (vmTwc, vmTwl, RCL, tCL, s, true , 0.003 );
47- std::cout << " Robust Kernel Hand-eye Calibration:\n " ;
65+ std::cout << " Robust Kernel Hand-eye Calibration with Regulation :\n " ;
4866 std::cout << " Rotation: \n " << RCL << std::endl;
4967 std::cout << " Translation: \n " << tCL << std::endl;
5068 std::cout << " s :" << s << std::endl;
5169 Eigen::Isometry3d rigidTCL = Eigen::Isometry3d::Identity ();
5270 rigidTCL.rotate (RCL);
53- // rigidTCL.pretranslate(tCL);
71+ rigidTCL.pretranslate (tCL);
5472
5573 Eigen::Isometry3d TCL0 (rigidTCL);
5674 int ngood;
57- // ngood = VSLAM.OptimizeExtrinsicGlobal(vTwl, TCL0, s);
58- // std::cout << "Bundle Adjustment Optimization (Global):\n";
59- // std::cout << "Rotation: \n" << TCL0.rotation() << std::endl;
60- // std::cout << "Translation: \n" << TCL0.translation() << std::endl;
61- // std::cout<< "scale= "<< s <<" "<<"ngood= "<<ngood<<std::endl;
75+ if (method == " global" ){
76+ ngood = VSLAM.OptimizeExtrinsicGlobal (vTwl, TCL0, s);
77+ std::cout << " Bundle Adjustment Optimization (Global):\n " ;
78+ std::cout << " Rotation: \n " << TCL0.rotation () << std::endl;
79+ std::cout << " Translation: \n " << TCL0.translation () << std::endl;
80+ std::cout<< " scale= " << s <<" " <<" ngood= " <<ngood<<std::endl;
81+ }
82+ else
83+ {
84+ TCL0 = rigidTCL;
85+ ngood = VSLAM.OptimizeExtrinsicLocal (vTwl, TCL0, s);
86+ std::cout << " Bundle Adjustment Optimization (Local):\n " ;
87+ std::cout << " Rotation: \n " << TCL0.rotation () << std::endl;
88+ std::cout << " Translation: \n " << TCL0.translation () << std::endl;
89+ std::cout<< " scale= " << s <<" " <<" ngood= " << ngood <<std::endl;
90+ }
91+ writeSim3 (resFileName, TCL0, s);
92+ std::cout << " Result of BA Calibration saved to " << resFileName << std::endl;
93+
6294
63- TCL0 = rigidTCL;
64- ngood = VSLAM.OptimizeExtrinsicLocal (vTwl, TCL0, s);
65- std::cout << " Bundle Adjustment Optimization (Local):\n " ;
66- std::cout << " Rotation: \n " << TCL0.rotation () << std::endl;
67- std::cout << " Translation: \n " << TCL0.translation () << std::endl;
68- std::cout<< " scale= " << s <<" " <<" ngood= " << ngood <<std::endl;
6995
7096 // std::tie(RCL,tCL,s) = HECalibRobustKernelg2o(vmTwc, vmTwl, RCL, tCL, s);
7197 // std::cout << "Robust Hand-eye Calibration:\n";
0 commit comments