@@ -45,9 +45,7 @@ void LocalMapper::work() {
45
45
process_new_keyframe ();
46
46
mappoint_culling ();
47
47
create_new_mappoints ();
48
-
49
- if (!check_new_keyframe ())
50
- search_in_neighbors ();
48
+ search_in_neighbors ();
51
49
52
50
if (!check_new_keyframe () && !stop_request ()) {
53
51
local_bundle_adjustment ();
@@ -307,8 +305,7 @@ void LocalMapper::initialize() {
307
305
}
308
306
}
309
307
310
- if (!solver->solve ())
311
- return ;
308
+ solver->solve ();
312
309
313
310
std::vector<double > residuals = solver->evaluate ();
314
311
@@ -319,7 +316,7 @@ void LocalMapper::initialize() {
319
316
if (!mp) continue ;
320
317
float dis = (kf->get_camera_to_world_translation () - mp->get_landmark ()).norm ();
321
318
322
- if (residuals[i] > 3.0 || dis < 0.1 || dis > 20.0 ) {
319
+ if (residuals[i] > 3.0 || dis > 20.0 ) {
323
320
mp->erase_observation (kf);
324
321
size_t idx = mp->get_observations ()[kf];
325
322
kf->get_features ()->erase_mappoint (idx);
@@ -331,6 +328,7 @@ void LocalMapper::initialize() {
331
328
332
329
initialized = true ;
333
330
last_keyframe = curr_keyframe;
331
+ std::cout << " Initialization finished with " << matches << " matches and mappoints " << backend->global_map ->get_mappoints ().size () << std::endl;
334
332
}
335
333
}
336
334
@@ -344,10 +342,9 @@ bool LocalMapper::need_new_keyframe() {
344
342
int n_curr_matches = curr_keyframe->tracked_mappoints (2 );
345
343
346
344
bool c1 = curr_keyframe->frame_id - last_keyframe->frame_id >= 10 ;
347
- bool c2 = n_curr_matches < n_last_matches * 0.9 ;
348
- bool c3 = n_curr_matches < 30 ;
345
+ bool c2 = n_curr_matches < n_last_matches * 0.9 && n_curr_matches > 10 ;
349
346
350
- return (c1 || c2 || c3 );
347
+ return (c1 || c2);
351
348
}
352
349
353
350
void LocalMapper::set_accept_keyframes (bool flag) {
@@ -479,7 +476,8 @@ void LocalMapper::search_local_points() {
479
476
if (to_match>0 ) {
480
477
ORBmatcher matcher;
481
478
int matches = matcher.search_by_projection (curr_keyframe, local_mappoints, 1.0 );
482
- std::cout << " front " << latest_tracked_id << " back " << curr_keyframe->frame_id << " to match " << to_match << " " << matches <<std::endl;
479
+ double dura = curr_keyframe->timestamp - init_keyframe->timestamp ;
480
+ std::cout << " time " << dura << " front " << latest_tracked_id << " back " << curr_keyframe->frame_id << " to match " << to_match << " " << matches <<std::endl;
483
481
}
484
482
485
483
}
@@ -600,29 +598,36 @@ void LocalMapper::mirror_matched_points() {
600
598
if (curr_keyframe->frame_id <= frontend_init_frame_id)
601
599
return ;
602
600
OptimizedData optimized_data;
603
- optimized_data.t = curr_keyframe->timestamp ;
604
- optimized_data.frame_id = curr_keyframe->frame_id ;
605
- optimized_data.pose = curr_keyframe->get_pose ();
606
-
607
- auto features = curr_keyframe->get_features ();
608
- for (size_t i = 0 ; i < features->feature_num (); i++) {
609
- MapPoint *mappoint = features->get_mappoint (i);
610
- if (mappoint && mappoint->tag (MPT_VALID)) {
611
- optimized_data.track_ids .push_back (nil ());
612
- optimized_data.observations .push_back (features->keypoints [i]);
613
- optimized_data.landmarks .push_back (mappoint->get_landmark ());
601
+
602
+ std::vector<KeyFrame *> keyframes = backend->global_map ->get_keyframes_list ();
603
+ for (size_t i = keyframes.size ()-1 ; i > keyframes.size ()-10 && i > 0 ; i--) {
604
+ KeyFrame *kf = keyframes[i];
605
+ optimized_data.connected_frames .push_back (kf->frame_id );
606
+
607
+ std::vector<vector<2 >> observations;
608
+ std::vector<vector<3 >> landmarks;
609
+
610
+ auto features = kf->get_features ();
611
+ for (size_t j = 0 ; j < features->feature_num (); j++) {
612
+ MapPoint *mappoint = features->get_mappoint (j);
613
+ if (mappoint && mappoint->tag (MPT_VALID)) {
614
+ observations.push_back (features->keypoints [j]);
615
+ landmarks.push_back (mappoint->get_landmark ());
616
+ }
614
617
}
615
- }
616
618
617
- auto frontend_features = curr_keyframe ->get_frontend_features ();
618
- for (size_t i = 0 ; i < frontend_features->feature_num (); i ++) {
619
- MapPoint *mappoint = frontend_features->get_mappoint (i );
620
- if (mappoint && mappoint->tag (MPT_VALID)) {
621
- optimized_data. track_ids . push_back (frontend_features->track_ids [i ]);
622
- optimized_data. observations . push_back (frontend_features-> keypoints [i] );
623
- optimized_data. landmarks . push_back (mappoint-> get_landmark ());
619
+ auto frontend_features = kf ->get_frontend_features ();
620
+ for (size_t j = 0 ; j < frontend_features->feature_num (); j ++) {
621
+ MapPoint *mappoint = frontend_features->get_mappoint (j );
622
+ if (mappoint && mappoint->tag (MPT_VALID)) {
623
+ observations. push_back (frontend_features->keypoints [j ]);
624
+ landmarks. push_back (mappoint-> get_landmark () );
625
+ }
624
626
}
627
+ optimized_data.observations .push_back (observations);
628
+ optimized_data.landmarks .push_back (landmarks);
625
629
}
630
+
626
631
backend->detail ->frontend ->mirror_matched_points (optimized_data);
627
632
}
628
633
0 commit comments