Skip to content

Commit 9f132ea

Browse files
committed
Merge branch 'main' of github.com:colmap/glomap into ra_debug
2 parents aad2630 + 18a70ee commit 9f132ea

23 files changed

+184
-49
lines changed

.github/workflows/ubuntu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ jobs:
107107
libmetis-dev \
108108
libgoogle-glog-dev \
109109
libgtest-dev \
110+
libgmock-dev \
110111
libsqlite3-dev \
111112
libglew-dev \
112113
qtbase5-dev \

cmake/FindDependencies.cmake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ find_package(Boost REQUIRED)
77

88
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
99
find_package(Glog REQUIRED)
10-
if(DEFINED glog_VERSION_MAJOR)
11-
# Older versions of glog don't export version variables.
12-
add_definitions("-DGLOG_VERSION_MAJOR=${glog_VERSION_MAJOR}")
13-
add_definitions("-DGLOG_VERSION_MINOR=${glog_VERSION_MINOR}")
14-
endif()
10+
endif()
11+
12+
if(DEFINED glog_VERSION_MAJOR)
13+
# Older versions of glog don't export version variables.
14+
add_definitions("-DGLOG_VERSION_MAJOR=${glog_VERSION_MAJOR}")
15+
add_definitions("-DGLOG_VERSION_MINOR=${glog_VERSION_MINOR}")
1516
endif()
1617

1718
if(TESTS_ENABLED)
@@ -24,6 +25,7 @@ FetchContent_Declare(PoseLib
2425
GIT_REPOSITORY https://github.com/PoseLib/PoseLib.git
2526
GIT_TAG 0439b2d361125915b8821043fca9376e6cc575b9
2627
EXCLUDE_FROM_ALL
28+
SYSTEM
2729
)
2830
message(STATUS "Configuring PoseLib...")
2931
if (FETCH_POSELIB)
@@ -35,7 +37,7 @@ message(STATUS "Configuring PoseLib... done")
3537

3638
FetchContent_Declare(COLMAP
3739
GIT_REPOSITORY https://github.com/colmap/colmap.git
38-
GIT_TAG 66fd8e56a0d160d68af2f29e9ac6941d442d2322
40+
GIT_TAG 78f1eefacae542d753c2e4f6a26771a0d976227d
3941
EXCLUDE_FROM_ALL
4042
)
4143
message(STATUS "Configuring COLMAP...")

glomap/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set(SOURCES
1919
math/two_view_geometry.cc
2020
processors/image_pair_inliers.cc
2121
processors/image_undistorter.cc
22+
processors/reconstruction_normalizer.cc
2223
processors/reconstruction_pruning.cc
2324
processors/relpose_filter.cc
2425
processors/track_filter.cc
@@ -51,6 +52,7 @@ set(HEADERS
5152
math/union_find.h
5253
processors/image_pair_inliers.h
5354
processors/image_undistorter.h
55+
processors/reconstruction_normalizer.h
5456
processors/reconstruction_pruning.h
5557
processors/relpose_filter.h
5658
processors/track_filter.h

glomap/controllers/global_mapper.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#include "global_mapper.h"
22

3+
#include "glomap/io/colmap_converter.h"
34
#include "glomap/processors/image_pair_inliers.h"
45
#include "glomap/processors/image_undistorter.h"
6+
#include "glomap/processors/reconstruction_normalizer.h"
57
#include "glomap/processors/reconstruction_pruning.h"
68
#include "glomap/processors/relpose_filter.h"
79
#include "glomap/processors/track_filter.h"
810
#include "glomap/processors/view_graph_manipulation.h"
911

12+
#include <colmap/util/file.h>
1013
#include <colmap/util/timer.h>
1114

1215
namespace glomap {
@@ -166,6 +169,10 @@ bool GlobalMapper::Solve(const colmap::Database& database,
166169
images,
167170
tracks,
168171
options_.inlier_thresholds.max_angle_error);
172+
173+
// Normalize the structure
174+
NormalizeReconstruction(cameras, images, tracks);
175+
169176
run_timer.PrintSeconds();
170177
}
171178

@@ -208,6 +215,9 @@ bool GlobalMapper::Solve(const colmap::Database& database,
208215
if (ite != options_.num_iteration_bundle_adjustment - 1)
209216
run_timer.PrintSeconds();
210217

218+
// Normalize the structure
219+
NormalizeReconstruction(cameras, images, tracks);
220+
211221
// 6.3. Filter tracks based on the estimation
212222
// For the filtering, in each round, the criteria for outlier is
213223
// tightened. If only few tracks are changed, no need to start bundle
@@ -291,6 +301,9 @@ bool GlobalMapper::Solve(const colmap::Database& database,
291301
run_timer.PrintSeconds();
292302
}
293303

304+
// Normalize the structure
305+
NormalizeReconstruction(cameras, images, tracks);
306+
294307
// Filter tracks based on the estimation
295308
UndistortImages(cameras, images, true);
296309
LOG(INFO) << "Filtering tracks by reprojection ...";
@@ -325,4 +338,4 @@ bool GlobalMapper::Solve(const colmap::Database& database,
325338
return true;
326339
}
327340

328-
} // namespace glomap
341+
} // namespace glomap

glomap/controllers/track_retriangulation.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
#include "glomap/io/colmap_converter.h"
44

5-
#include <colmap/controllers/incremental_mapper.h>
5+
#include <colmap/controllers/incremental_pipeline.h>
66
#include <colmap/estimators/bundle_adjustment.h>
77
#include <colmap/scene/database_cache.h>
88

9+
#include <set>
10+
911
namespace glomap {
1012

1113
bool RetriangulateTracks(const TriangulatorOptions& options,
@@ -40,7 +42,7 @@ bool RetriangulateTracks(const TriangulatorOptions& options,
4042
std::unordered_map<track_t, Track>(),
4143
*reconstruction_ptr);
4244

43-
colmap::IncrementalMapperOptions options_colmap;
45+
colmap::IncrementalPipelineOptions options_colmap;
4446
options_colmap.triangulation.complete_max_reproj_error =
4547
options.tri_complete_max_reproj_error;
4648
options_colmap.triangulation.merge_max_reproj_error =
@@ -57,13 +59,13 @@ bool RetriangulateTracks(const TriangulatorOptions& options,
5759
const auto tri_options = options_colmap.Triangulation();
5860
const auto mapper_options = options_colmap.Mapper();
5961

60-
const std::vector<image_t>& reg_image_ids = reconstruction_ptr->RegImageIds();
62+
const std::set<image_t>& reg_image_ids = reconstruction_ptr->RegImageIds();
6163

62-
for (size_t i = 0; i < reg_image_ids.size(); ++i) {
63-
std::cout << "\r Triangulating image " << i + 1 << " / "
64+
size_t image_idx = 0;
65+
for (const image_t image_id : reg_image_ids) {
66+
std::cout << "\r Triangulating image " << image_idx++ + 1 << " / "
6467
<< reg_image_ids.size() << std::flush;
6568

66-
const image_t image_id = reg_image_ids[i];
6769
const auto& image = reconstruction_ptr->Image(image_id);
6870

6971
int num_tris = mapper.TriangulateImage(tri_options, image_id);
@@ -96,10 +98,10 @@ bool RetriangulateTracks(const TriangulatorOptions& options,
9698
const size_t num_observations =
9799
reconstruction_ptr->ComputeNumObservations();
98100

99-
// PrintHeading1("Bundle adjustment");
100-
colmap::BundleAdjuster bundle_adjuster(ba_options, ba_config);
101-
// THROW_CHECK(bundle_adjuster.Solve(reconstruction.get()));
102-
if (!bundle_adjuster.Solve(reconstruction_ptr.get())) {
101+
std::unique_ptr<colmap::BundleAdjuster> bundle_adjuster;
102+
bundle_adjuster =
103+
CreateDefaultBundleAdjuster(ba_options, ba_config, *reconstruction_ptr);
104+
if (bundle_adjuster->Solve().termination_type == ceres::FAILURE) {
103105
return false;
104106
}
105107

@@ -128,4 +130,4 @@ bool RetriangulateTracks(const TriangulatorOptions& options,
128130
return true;
129131
}
130132

131-
} // namespace glomap
133+
} // namespace glomap

glomap/estimators/bundle_adjustment.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void BundleAdjuster::Reset() {
5454
ceres::Problem::Options problem_options;
5555
problem_options.loss_function_ownership = ceres::DO_NOT_TAKE_OWNERSHIP;
5656
problem_ = std::make_unique<ceres::Problem>(problem_options);
57+
loss_function_ = options_.CreateLossFunction();
5758
}
5859

5960
void BundleAdjuster::AddPointToCameraConstraints(
@@ -70,14 +71,14 @@ void BundleAdjuster::AddPointToCameraConstraints(
7071
Image& image = images[observation.first];
7172

7273
ceres::CostFunction* cost_function =
73-
colmap::CameraCostFunction<colmap::ReprojErrorCostFunction>(
74+
colmap::CreateCameraCostFunction<colmap::ReprojErrorCostFunctor>(
7475
cameras[image.camera_id].model_id,
7576
image.features[observation.second]);
7677

7778
if (cost_function != nullptr) {
7879
problem_->AddResidualBlock(
7980
cost_function,
80-
options_.loss_function.get(),
81+
loss_function_.get(),
8182
image.cam_from_world.rotation.coeffs().data(),
8283
image.cam_from_world.translation.data(),
8384
tracks[track_id].xyz.data(),

glomap/estimators/bundle_adjustment.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ struct BundleAdjusterOptions : public OptimizationBaseOptions {
2121

2222
BundleAdjusterOptions() : OptimizationBaseOptions() {
2323
thres_loss_function = 1.;
24-
loss_function = std::make_shared<ceres::HuberLoss>(thres_loss_function);
2524
solver_options.max_num_iterations = 200;
2625
}
26+
27+
std::shared_ptr<ceres::LossFunction> CreateLossFunction() {
28+
return std::make_shared<ceres::HuberLoss>(thres_loss_function);
29+
}
2730
};
2831

2932
class BundleAdjuster {
@@ -65,6 +68,7 @@ class BundleAdjuster {
6568
BundleAdjusterOptions options_;
6669

6770
std::unique_ptr<ceres::Problem> problem_;
71+
std::shared_ptr<ceres::LossFunction> loss_function_;
6872
};
6973

7074
} // namespace glomap

glomap/estimators/global_positioning.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ void GlobalPositioner::SetupProblem(
8787
ceres::Problem::Options problem_options;
8888
problem_options.loss_function_ownership = ceres::DO_NOT_TAKE_OWNERSHIP;
8989
problem_ = std::make_unique<ceres::Problem>(problem_options);
90+
loss_function_ = options_.CreateLossFunction();
91+
9092
// Allocate enough memory for the scales. One for each residual.
9193
// Due to possibly invalid image pairs or tracks, the actual number of
9294
// residuals may be smaller.
@@ -169,7 +171,7 @@ void GlobalPositioner::AddCameraToCameraConstraints(
169171
BATAPairwiseDirectionError::Create(translation);
170172
problem_->AddResidualBlock(
171173
cost_function,
172-
options_.loss_function.get(),
174+
loss_function_.get(),
173175
images[image_id1].cam_from_world.translation.data(),
174176
images[image_id2].cam_from_world.translation.data(),
175177
&scale);
@@ -212,19 +214,17 @@ void GlobalPositioner::AddPointToCameraConstraints(
212214

213215
if (loss_function_ptcam_uncalibrated_ == nullptr) {
214216
loss_function_ptcam_uncalibrated_ =
215-
std::make_shared<ceres::ScaledLoss>(options_.loss_function.get(),
217+
std::make_shared<ceres::ScaledLoss>(loss_function_.get(),
216218
0.5 * weight_scale_pt,
217219
ceres::DO_NOT_TAKE_OWNERSHIP);
218220
}
219221

220222
if (options_.constraint_type ==
221223
GlobalPositionerOptions::POINTS_AND_CAMERAS_BALANCED) {
222-
loss_function_ptcam_calibrated_ =
223-
std::make_shared<ceres::ScaledLoss>(options_.loss_function.get(),
224-
weight_scale_pt,
225-
ceres::DO_NOT_TAKE_OWNERSHIP);
224+
loss_function_ptcam_calibrated_ = std::make_shared<ceres::ScaledLoss>(
225+
loss_function_.get(), weight_scale_pt, ceres::DO_NOT_TAKE_OWNERSHIP);
226226
} else {
227-
loss_function_ptcam_calibrated_ = options_.loss_function;
227+
loss_function_ptcam_calibrated_ = loss_function_;
228228
}
229229

230230
for (auto& [track_id, track] : tracks) {

glomap/estimators/global_positioning.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ struct GlobalPositionerOptions : public OptimizationBaseOptions {
4242

4343
GlobalPositionerOptions() : OptimizationBaseOptions() {
4444
thres_loss_function = 1e-1;
45-
loss_function = std::make_shared<ceres::HuberLoss>(thres_loss_function);
45+
}
46+
47+
std::shared_ptr<ceres::LossFunction> CreateLossFunction() {
48+
return std::make_shared<ceres::HuberLoss>(thres_loss_function);
4649
}
4750
};
4851

@@ -104,6 +107,7 @@ class GlobalPositioner {
104107
std::unique_ptr<ceres::Problem> problem_;
105108

106109
// Loss functions for reweighted terms.
110+
std::shared_ptr<ceres::LossFunction> loss_function_;
107111
std::shared_ptr<ceres::LossFunction> loss_function_ptcam_uncalibrated_;
108112
std::shared_ptr<ceres::LossFunction> loss_function_ptcam_calibrated_;
109113

glomap/estimators/gravity_refinement.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ void GravityRefiner::RefineGravity(const ViewGraph& view_graph,
2727
return;
2828
}
2929

30+
loss_function_ = options_.CreateLossFunction();
31+
3032
int counter_progress = 0;
3133
// Iterate through the error prone images
3234
for (auto image_id : error_prone_images) {
@@ -70,8 +72,7 @@ void GravityRefiner::RefineGravity(const ViewGraph& view_graph,
7072

7173
ceres::CostFunction* coor_cost =
7274
GravError::CreateCost(gravities[counter]);
73-
problem.AddResidualBlock(
74-
coor_cost, options_.loss_function.get(), gravity.data());
75+
problem.AddResidualBlock(coor_cost, loss_function_.get(), gravity.data());
7576
counter++;
7677
}
7778

0 commit comments

Comments
 (0)