Aligned BundleAdjustment parameters with Optimizer/Strategy to avoid confusion in the code

This commit is contained in:
matlabbe
2026-05-31 13:51:00 -07:00
parent 71092e7c28
commit b8347613e8
5 changed files with 53 additions and 42 deletions
+4 -4
View File
@@ -517,9 +517,9 @@ class RTABMAP_CORE_EXPORT Parameters
RTABMAP_PARAM(OdomF2M, ScanRange, float, 0, "[Geometry] Distance Range used to filter points of local map (when > 0). 0 means local map is updated using time and not range.");
RTABMAP_PARAM(OdomF2M, ValidDepthRatio, float, 0.75, "If a new frame has points without valid depth, they are added to local feature map only if points with valid depth on total points is over this ratio. Setting to 1 means no points without valid depth are added to local feature map.");
#if defined(RTABMAP_G2O) || defined(RTABMAP_ORB_SLAM)
RTABMAP_PARAM(OdomF2M, BundleAdjustment, int, 1, "Local bundle adjustment: 0=disabled, 1=g2o, 2=cvsba, 3=Ceres.");
RTABMAP_PARAM(OdomF2M, BundleAdjustment, int, 1, uFormat("Local bundle adjustment. Value matches the %s parameter: 0=disabled (TORO is not BA-capable), 1=g2o, 2=GTSAM, 3=Ceres, 4=cvsba.", kOptimizerStrategy().c_str()));
#else
RTABMAP_PARAM(OdomF2M, BundleAdjustment, int, 0, "Local bundle adjustment: 0=disabled, 1=g2o, 2=cvsba, 3=Ceres.");
RTABMAP_PARAM(OdomF2M, BundleAdjustment, int, 0, uFormat("Local bundle adjustment. Value matches the %s parameter: 0=disabled (TORO is not BA-capable), 1=g2o, 2=GTSAM, 3=Ceres, 4=cvsba.", kOptimizerStrategy().c_str()));
#endif
RTABMAP_PARAM(OdomF2M, BundleAdjustmentMaxFrames, int, 10, "Maximum frames used for bundle adjustment (0=inf or all current frames in the local map).");
RTABMAP_PARAM(OdomF2M, BundleAdjustmentMinMotion, float, 0.0, "To create a new keyframe with bundle adjustment, a minimum motion (in pixels) can be required. The motion is computed by the average distance between inliers of the previous keyframe and new frame.");
@@ -780,9 +780,9 @@ class RTABMAP_CORE_EXPORT Parameters
RTABMAP_PARAM(Vis, CorFlowErrorThreshold, float, 20, uFormat("[%s=false] Filter out features with error greater than this threshold.", kVisCorFlowUseMinEigenVals().c_str()));
RTABMAP_PARAM(Vis, CorFlowGpu, bool, false, uFormat("[%s=1] Enable GPU version of the optical flow approach (only available if OpenCV is built with CUDA). Note that %s is not used in the GPU implementation.", kVisCorType().c_str(), kVisCorFlowUseMinEigenVals().c_str()));
#if defined(RTABMAP_G2O) || defined(RTABMAP_ORB_SLAM)
RTABMAP_PARAM(Vis, BundleAdjustment, int, 1, "Optimization with bundle adjustment: 0=disabled, 1=g2o, 2=cvsba, 3=Ceres.");
RTABMAP_PARAM(Vis, BundleAdjustment, int, 1, uFormat("Optimization with bundle adjustment. Value matches the %s parameter: 0=disabled (TORO is not BA-capable), 1=g2o, 2=GTSAM, 3=Ceres, 4=cvsba.", kOptimizerStrategy().c_str()));
#else
RTABMAP_PARAM(Vis, BundleAdjustment, int, 0, "Optimization with bundle adjustment: 0=disabled, 1=g2o, 2=cvsba, 3=Ceres.");
RTABMAP_PARAM(Vis, BundleAdjustment, int, 0, uFormat("Optimization with bundle adjustment. Value matches the %s parameter: 0=disabled (TORO is not BA-capable), 1=g2o, 2=GTSAM, 3=Ceres, 4=cvsba.", kOptimizerStrategy().c_str()));
#endif
// Features matching approaches
+4 -1
View File
@@ -1880,7 +1880,10 @@ Transform RegistrationVis::computeTransformationImpl(
(toSignature.sensorData().stereoCameraModels().size() >= 1 || toSignature.sensorData().cameraModels().size() >= 1))
{
UDEBUG("Refine with bundle adjustment");
Optimizer * sba = Optimizer::create(_bundleAdjustment==3?Optimizer::kTypeCeres:_bundleAdjustment==2?Optimizer::kTypeCVSBA:Optimizer::kTypeG2O, _bundleParameters);
// _bundleAdjustment matches the Optimizer/Strategy parameter 1:1
// (1=g2o, 2=GTSAM, 3=Ceres, 4=cvsba); 0 was filtered out above.
Optimizer * sba = Optimizer::create(
static_cast<Optimizer::Type>(_bundleAdjustment), _bundleParameters);
std::map<int, Transform> poses;
std::multimap<int, Link> links;
+6 -4
View File
@@ -110,13 +110,15 @@ OdometryF2M::OdometryF2M(const ParametersMap & parameters) :
ParametersMap bundleParameters = parameters;
if(bundleAdjustment_ > 0)
{
if((bundleAdjustment_==1 && Optimizer::isAvailable(Optimizer::kTypeG2O)) ||
(bundleAdjustment_==2 && Optimizer::isAvailable(Optimizer::kTypeCVSBA)) ||
(bundleAdjustment_==3 && Optimizer::isAvailable(Optimizer::kTypeCeres)))
// The BundleAdjustment int matches the Optimizer/Strategy parameter
// 1:1 (g2o=1, GTSAM=2, Ceres=3, CVSBA=4). 0 = "disabled" -- it's
// the TORO slot, which isn't BA-capable.
const Optimizer::Type sbaType = static_cast<Optimizer::Type>(bundleAdjustment_);
if(Optimizer::isAvailable(sbaType))
{
// disable bundle in RegistrationVis as we do it already here
uInsert(bundleParameters, ParametersPair(Parameters::kVisBundleAdjustment(), "0"));
sba_ = Optimizer::create(bundleAdjustment_==3?Optimizer::kTypeCeres:bundleAdjustment_==2?Optimizer::kTypeCVSBA:Optimizer::kTypeG2O, bundleParameters);
sba_ = Optimizer::create(sbaType, bundleParameters);
}
else
{
+27 -31
View File
@@ -40,30 +40,28 @@ PostProcessingDialog::PostProcessingDialog(QWidget * parent) :
_ui = new Ui_PostProcessingDialog();
_ui->setupUi(this);
if(!Optimizer::isAvailable(Optimizer::kTypeCVSBA) &&
!Optimizer::isAvailable(Optimizer::kTypeG2O) &&
!Optimizer::isAvailable(Optimizer::kTypeCeres))
int firstAvailable = -1;
for(int i = 0; i < _ui->comboBox_sbaType->count(); ++i)
{
const Optimizer::Type type = static_cast<Optimizer::Type>(i);
const bool usable = type != Optimizer::kTypeTORO && Optimizer::isAvailable(type);
if(usable)
{
if(firstAvailable < 0) firstAvailable = i;
}
else
{
_ui->comboBox_sbaType->setItemData(i, 0, Qt::UserRole - 1);
}
}
if(firstAvailable < 0)
{
_ui->sba->setEnabled(false);
_ui->sba->setChecked(false);
}
else
{
if(!Optimizer::isAvailable(Optimizer::kTypeCVSBA))
{
_ui->comboBox_sbaType->setItemData(1, 0, Qt::UserRole - 1);
_ui->comboBox_sbaType->setCurrentIndex(0);
}
if(!Optimizer::isAvailable(Optimizer::kTypeG2O))
{
_ui->comboBox_sbaType->setItemData(0, 0, Qt::UserRole - 1);
_ui->comboBox_sbaType->setCurrentIndex(1);
}
if(!Optimizer::isAvailable(Optimizer::kTypeCeres))
{
_ui->comboBox_sbaType->setItemData(2, 0, Qt::UserRole - 1);
_ui->comboBox_sbaType->setCurrentIndex(1);
}
_ui->comboBox_sbaType->setCurrentIndex(firstAvailable);
}
restoreDefaults();
@@ -135,8 +133,13 @@ bool PostProcessingDialog::validateForm()
void PostProcessingDialog::updateVisibility()
{
_ui->sba_variance->setVisible(_ui->comboBox_sbaType->currentIndex() == 0);
_ui->label_variance->setVisible(_ui->comboBox_sbaType->currentIndex() == 0);
// Pixel variance applies to every BA backend except CVSBA (its
// underlying Sba::run() API takes 2D points only -- no info-matrix
// knob).
const Optimizer::Type type = static_cast<Optimizer::Type>(_ui->comboBox_sbaType->currentIndex());
const bool usesPixelVariance = type != Optimizer::kTypeCVSBA;
_ui->sba_variance->setVisible(usesPixelVariance);
_ui->label_variance->setVisible(usesPixelVariance);
}
void PostProcessingDialog::saveSettings(QSettings & settings, const QString & group) const
@@ -288,7 +291,7 @@ double PostProcessingDialog::sbaVariance() const
}
Optimizer::Type PostProcessingDialog::sbaType() const
{
return _ui->comboBox_sbaType->currentIndex()==2?Optimizer::kTypeCeres:_ui->comboBox_sbaType->currentIndex()==1?Optimizer::kTypeCVSBA:Optimizer::kTypeG2O;
return static_cast<Optimizer::Type>(_ui->comboBox_sbaType->currentIndex());
}
bool PostProcessingDialog::sbaRematchFeatures() const
{
@@ -349,18 +352,11 @@ void PostProcessingDialog::setSBAVariance(double variance)
}
void PostProcessingDialog::setSBAType(Optimizer::Type type)
{
if(type == Optimizer::kTypeCeres)
if(type < 0 || type >= _ui->comboBox_sbaType->count())
{
_ui->comboBox_sbaType->setCurrentIndex(2);
}
else if(type == Optimizer::kTypeCVSBA)
{
_ui->comboBox_sbaType->setCurrentIndex(1);
}
else
{
_ui->comboBox_sbaType->setCurrentIndex(0);
type = Optimizer::kTypeG2O;
}
_ui->comboBox_sbaType->setCurrentIndex(static_cast<int>(type));
}
void PostProcessingDialog::setSBARematchFeatures(bool value)
{
+12 -2
View File
@@ -267,7 +267,7 @@
<item row="2" column="1">
<widget class="QLabel" name="label_variance">
<property name="text">
<string>Pixel variance used by g2o.</string>
<string>Pixel variance used by g2o / GTSAM / Ceres BA.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@@ -308,6 +308,11 @@
</item>
<item row="0" column="0">
<widget class="QComboBox" name="comboBox_sbaType">
<item>
<property name="text">
<string>TORO</string>
</property>
</item>
<item>
<property name="text">
<string>g2o</string>
@@ -315,7 +320,7 @@
</item>
<item>
<property name="text">
<string>cvsba</string>
<string>GTSAM</string>
</property>
</item>
<item>
@@ -323,6 +328,11 @@
<string>Ceres</string>
</property>
</item>
<item>
<property name="text">
<string>cvsba</string>
</property>
</item>
</widget>
</item>
<item row="3" column="1">