MCPcopy Create free account
hub / github.com/PeterFWS/Structure-PLP-SLAM / initialize

Method initialize

src/PLPSLAM/initialize/perspective.cc:54–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52 }
53
54 bool perspective::initialize(const data::frame &cur_frm, const std::vector<int> &ref_matches_with_cur)
55 {
56 // set the current camera model
57 cur_camera_ = cur_frm.camera_;
58
59 // store the keypoints and bearings
60 cur_undist_keypts_ = cur_frm.undist_keypts_;
61 cur_bearings_ = cur_frm.bearings_;
62
63 // align matching information
64 ref_cur_matches_.clear(); // std::vector<std::pair<int, int>>, this member inherited from the base!
65 ref_cur_matches_.reserve(cur_frm.undist_keypts_.size());
66 for (unsigned int ref_idx = 0; ref_idx < ref_matches_with_cur.size(); ++ref_idx)
67 {
68 const auto cur_idx = ref_matches_with_cur.at(ref_idx);
69 if (0 <= cur_idx)
70 {
71 ref_cur_matches_.emplace_back(std::make_pair(ref_idx, cur_idx));
72 }
73 }
74
75 // set the current camera matrix
76 cur_cam_matrix_ = get_camera_matrix(cur_frm.camera_);
77
78 // FW: those are old functions used to calculate H and F
79 // compute H and F matrices in two parallel threads
80 // auto homography_solver = solve::homography_solver(ref_undist_keypts_, cur_undist_keypts_, ref_cur_matches_, 1.0);
81 // auto fundamental_solver = solve::fundamental_solver(ref_undist_keypts_, cur_undist_keypts_, ref_cur_matches_, 1.0);
82
83 // FW: same solver but using graph-cut ransac (with image cols and rows as input)
84 auto homography_solver = solve::homography_solver(ref_undist_keypts_, cur_undist_keypts_, ref_cur_matches_, 1.0,
85 cur_frm._img_rgb.cols, cur_frm._img_rgb.rows);
86 auto fundamental_solver = solve::fundamental_solver(ref_undist_keypts_, cur_undist_keypts_, ref_cur_matches_, 1.0,
87 cur_frm._img_rgb.cols, cur_frm._img_rgb.rows);
88
89 // FW: calculate H and F in parallel
90 // std::thread thread_for_H(&solve::homography_solver::find_via_ransac, &homography_solver, num_ransac_iters_, true);
91 // std::thread thread_for_F(&solve::fundamental_solver::find_via_ransac, &fundamental_solver, num_ransac_iters_, true);
92
93 std::thread thread_for_H(&solve::homography_solver::find_via_graph_cut_ransac, &homography_solver);
94 // std::thread thread_for_F(&solve::fundamental_solver::find_via_graph_cut_ransac, &fundamental_solver);
95 std::thread thread_for_F(&solve::fundamental_solver::find_via_ransac, &fundamental_solver, num_ransac_iters_, true);
96 thread_for_H.join();
97 thread_for_F.join(); // wait thread finish
98
99 // compute a score
100 const auto score_H = homography_solver.get_best_score();
101 const auto score_F = fundamental_solver.get_best_score();
102 const float rel_score_H = score_H / (score_H + score_F);
103
104 // select a case according to the score
105 if (0.40 < rel_score_H && homography_solver.solution_is_valid())
106 {
107 const Mat33_t H_ref_to_cur = homography_solver.get_best_H_21();
108 const auto is_inlier_match = homography_solver.get_inlier_matches();
109 return reconstruct_with_H(H_ref_to_cur, is_inlier_match);
110 }
111 else if (fundamental_solver.solution_is_valid())

Callers

nothing calls this directly

Calls 10

homography_solverClass · 0.85
fundamental_solverClass · 0.85
get_best_H_21Method · 0.80
get_best_F_21Method · 0.80
clearMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
get_best_scoreMethod · 0.45
solution_is_validMethod · 0.45
get_inlier_matchesMethod · 0.45

Tested by

no test coverage detected