/** @brief (one liner) * * (documentation goes here) */ bool flythrough_c::load(std::string filename) { if (loaded) return false; FILE* f = fopen(filename.c_str(), "rb"); if (!f) return false; flyversion_t ver; flyheader_t head; fread(&ver, sizeof(ver), 1, f); if (!(ver.major == 1 && ver.minor == 0 && ver.revision == 0)) { // version mismatch fclose(f); return false; } fread(&head, sizeof(head), 1, f); for (int i = 0 ; i < head.n ; ++i) { new_keyframe(); fread(kf[i], sizeof(flykf_t), 1, f); } fclose(f); loaded = true; set_active_keyframe(0); player_current_time = 0; player_current_kf_time = 0; return true; }
bool VisualOdometry::AddNewFrame(std::unique_ptr<ImageFrame> frame) { std::vector<cv::DMatch> matches; if (!feature_tracker_->TrackFrame(map_.GetLastKeyframe().image_frame(), *frame, matches)) { std::cerr << "Error: Track new frame failed.\n"; return false; } // TODO: Refine Keyframe Selector. // TODO: Add select keyframe for initialization if (matches.size() < 50) { std::cout << "Too few matches.\n"; // TODO: Use track by matching if (!feature_tracker_->MatchFrame(map_.GetLastKeyframe().image_frame(), *frame, matches)) { std::cout << "Error: Matching frames failed.\n"; return false; } if (matches.size() < 50) { std::cout << "Matching frames too few matches.\n"; return true; } else { tracking_or_matching_ = 2; std::cout << "Matching found " << matches.size() << " features.\n"; } } else { tracking_or_matching_ = 1; std::cout << "Tracking found " << matches.size() << " features.\n"; } /* if (map_.state() == Mapdata::INITIALIZED && !keyframe_selector_.isKeyframe(matches)) { std::cout << "Skipped a frame. Not selected as keyframe.\n\n"; return true; } */ if (plot_tracking_) PlotTracking(*frame, map_.GetLastKeyframe().image_frame(), matches); std::unique_ptr<Keyframe> new_keyframe(new Keyframe(std::move(frame))); if (!map_.AddNewKeyframeMatchToLastKeyframe(std::move(new_keyframe), matches)) return false; if (map_.state() != Mapdata::INITIALIZED) return true; // Estimate last frame if (!EstimateLastFrame()) { map_.DropLastKeyframe(); std::cout << "Skipped a frame. Could not add as new frame.\n"; return true; } map_.PrintStats(); if (map_.num_frame() % optimize_every_frame_ == 0) OptimizeMap(); else if (plot_3d_landmarks_ && map_.num_frame() % plot_3d_landmarks_every_frame_ == 0) VisualizeNewLandmarks(); return true; }