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

Add parameters for pose_optimizer_g2o #586

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/stella_vslam/optimize/pose_optimizer_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class pose_optimizer_factory {
static std::unique_ptr<pose_optimizer> create(const YAML::Node& yaml_node) {
const auto& backend = yaml_node["backend"].as<std::string>("g2o");
if (backend == "g2o") {
return std::unique_ptr<pose_optimizer>(new pose_optimizer_g2o());
YAML::Node g2o_node = util::yaml_optional_ref(yaml_node, "g2o");
return std::unique_ptr<pose_optimizer>(new pose_optimizer_g2o(
g2o_node["num_trials_robust"].as<unsigned int>(2),
g2o_node["num_trials"].as<unsigned int>(2),
g2o_node["num_each_iter"].as<unsigned int>(10)));
}
else if (backend == "gtsam") {
#ifdef USE_GTSAM
Expand Down
13 changes: 9 additions & 4 deletions src/stella_vslam/optimize/pose_optimizer_g2o.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
namespace stella_vslam {
namespace optimize {

pose_optimizer_g2o::pose_optimizer_g2o(const unsigned int num_trials, const unsigned int num_each_iter)
: num_trials_(num_trials), num_each_iter_(num_each_iter) {}
pose_optimizer_g2o::pose_optimizer_g2o(const unsigned int num_trials_robust, const unsigned int num_trials, const unsigned int num_each_iter)
: num_trials_robust_(num_trials_robust), num_trials_(num_trials), num_each_iter_(num_each_iter) {}

unsigned int pose_optimizer_g2o::optimize(const data::frame& frm, Mat44_t& optimized_pose, std::vector<bool>& outlier_flags) const {
auto num_valid_obs = optimize(frm.get_pose_cw(), frm.frm_obs_, frm.orb_params_, frm.camera_,
Expand Down Expand Up @@ -114,7 +114,12 @@ unsigned int pose_optimizer_g2o::optimize(const Mat44_t& cam_pose_cw, const data
// 4. Perform robust Bundle Adjustment (BA)

unsigned int num_bad_obs = 0;
for (unsigned int trial = 0; trial < num_trials_; ++trial) {
if (num_trials_robust_ == 0) {
for (auto& pose_opt_edge_wrap : pose_opt_edge_wraps) {
pose_opt_edge_wrap.edge_->setRobustKernel(nullptr);
}
}
for (unsigned int trial = 0; trial < num_trials_robust_ + num_trials_; ++trial) {
optimizer.initializeOptimization();
optimizer.optimize(num_each_iter_);

Expand Down Expand Up @@ -150,7 +155,7 @@ unsigned int pose_optimizer_g2o::optimize(const Mat44_t& cam_pose_cw, const data
}
}

if (trial == num_trials_ - 2) {
if (num_trials_ != 0 && trial + 1 == num_trials_robust_) {
edge->setRobustKernel(nullptr);
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/stella_vslam/optimize/pose_optimizer_g2o.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ class pose_optimizer_g2o : public pose_optimizer {
public:
/**
* Constructor
* @param num_trials_robust
* @param num_trials
* @param num_each_iter
*/
explicit pose_optimizer_g2o(const unsigned int num_trials = 4, const unsigned int num_each_iter = 10);
explicit pose_optimizer_g2o(
unsigned int num_trials_robust = 2,
unsigned int num_trials = 2,
unsigned int num_each_iter = 10);

/**
* Destructor
Expand All @@ -53,10 +57,13 @@ class pose_optimizer_g2o : public pose_optimizer {
std::vector<bool>& outlier_flags) const override;

private:
//! robust optimizationの試行回数
const unsigned int num_trials_ = 4;
//! Number of robust optimization (with outlier rejection) attempts
const unsigned int num_trials_robust_ = 2;

//! 毎回のoptimizationのiteration回数
//! Number of optimization (with outlier rejection) attempts
const unsigned int num_trials_ = 2;

//! Maximum number of iterations for each optimization
const unsigned int num_each_iter_ = 10;
};

Expand Down
Loading