Skip to content

Commit eaebe3c

Browse files
authored
Add ObservationManager (#2575)
* Add ObservationManager * Move visibility pyramid to ObservationManager * Move num_correspondences and num_observation_ * Update bindings * Fix Python example
1 parent 022e42f commit eaebe3c

38 files changed

Lines changed: 1401 additions & 1061 deletions

‎.github/workflows/build-mac.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
- name: Run tests
7777
run: |
7878
cd build
79+
set +e
7980
ctest
8081
tests_pass=$?
8182
if [ $tests_pass -ne 0 ]; then

‎.github/workflows/build-windows.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ jobs:
101101
run: |
102102
./vcpkg/vcpkg.exe integrate install
103103
cd build
104-
ctest -E "(feature/colmap_feature_sift_test)|(util/colmap_util_opengl_utils_test)|(mvs/colmap_mvs_gpu_mat_test)"
104+
$EXCLUDED_TESTS = "(feature/colmap_feature_sift_test)|(util/colmap_util_opengl_utils_test)|(mvs/colmap_mvs_gpu_mat_test)"
105+
ctest -E ${EXCLUDED_TESTS}
105106
$tests_pass=$LastExitCode
106107
if ($tests_pass -ne 0) {
107108
echo "`n`n`nTests failed, rerunning with verbose output"
108-
ctest --rerun-failed --output-on-failure
109+
ctest -E ${EXCLUDED_TESTS} --rerun-failed --output-on-failure
109110
}
110111
exit $tests_pass
111112

‎pycolmap/custom_bundle_adjustment.py‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def adjust_global_bundle(mapper, mapper_options, ba_options):
225225
ba_options_tmp.solver_options.max_linear_solver_iterations = 200
226226

227227
# Avoid degeneracies in bundle adjustment
228-
reconstruction.filter_observations_with_negative_depth()
228+
mapper.observation_manager.filter_observations_with_negative_depth()
229229

230230
# Configure bundle adjustment
231231
ba_config = pycolmap.BundleAdjustmentConfig()
@@ -370,15 +370,19 @@ def adjust_local_bundle(
370370
)
371371

372372
filter_image_ids = {image_id, *local_bundle}
373-
report.num_filtered_observations = reconstruction.filter_points3D_in_images(
374-
mapper_options.filter_max_reproj_error,
375-
mapper_options.filter_min_tri_angle,
376-
filter_image_ids,
373+
report.num_filtered_observations = (
374+
mapper.observation_manager.filter_points3D_in_images(
375+
mapper_options.filter_max_reproj_error,
376+
mapper_options.filter_min_tri_angle,
377+
filter_image_ids,
378+
)
377379
)
378-
report.num_filtered_observations += reconstruction.filter_points3D(
379-
mapper_options.filter_max_reproj_error,
380-
mapper_options.filter_min_tri_angle,
381-
point3D_ids,
380+
report.num_filtered_observations += (
381+
mapper.observation_manager.filter_points3D(
382+
mapper_options.filter_max_reproj_error,
383+
mapper_options.filter_min_tri_angle,
384+
point3D_ids,
385+
)
382386
)
383387
return report
384388

‎pycolmap/custom_incremental_mapping.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ def reconstruct_sub_model(controller, mapper, mapper_options, reconstruction):
122122
break
123123
for reg_trial in range(len(next_images)):
124124
next_image_id = next_images[reg_trial]
125-
next_image = reconstruction.images[next_image_id]
126125
logging.info(
127126
f"Registering image #{next_image_id} "
128127
f"({reconstruction.num_reg_images() + 1})"
129128
)
130-
logging.info(
131-
f"=> Image sees {next_image.num_visible_points3D()} "
132-
f"/ {next_image.num_observations} points"
129+
num_vis = mapper.observation_manager.num_visible_points3D(
130+
next_image_id
133131
)
132+
num_obs = mapper.observation_manager.num_observations(next_image_id)
133+
logging.info(f"=> Image sees {num_vis} / {num_obs} points")
134134
reg_next_success = mapper.register_next_image(
135135
mapper_options, next_image_id
136136
)

‎src/colmap/controllers/bundle_adjustment.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "colmap/controllers/bundle_adjustment.h"
3131

3232
#include "colmap/estimators/bundle_adjustment.h"
33+
#include "colmap/sfm/observation_manager.h"
3334
#include "colmap/util/misc.h"
3435
#include "colmap/util/timer.h"
3536

@@ -80,7 +81,7 @@ void BundleAdjustmentController::Run() {
8081
}
8182

8283
// Avoid degeneracies in bundle adjustment.
83-
reconstruction_->FilterObservationsWithNegativeDepth();
84+
ObservationManager(*reconstruction_).FilterObservationsWithNegativeDepth();
8485

8586
BundleAdjustmentOptions ba_options = *options_.bundle_adjustment;
8687

‎src/colmap/controllers/hierarchical_mapper.cc‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "colmap/estimators/alignment.h"
3333
#include "colmap/scene/scene_clustering.h"
34+
#include "colmap/sfm/observation_manager.h"
3435
#include "colmap/util/misc.h"
3536
#include "colmap/util/threading.h"
3637

@@ -62,9 +63,8 @@ void MergeClusters(const SceneClustering::Cluster& cluster,
6263
for (size_t j = 0; j < i; ++j) {
6364
const double kMaxReprojError = 8.0;
6465
const int num_reg_images_j = reconstructions[j]->NumRegImages();
65-
if (MergeReconstructions(kMaxReprojError,
66-
*reconstructions[j],
67-
reconstructions[i].get())) {
66+
if (MergeAndFilterReconstructions(
67+
kMaxReprojError, *reconstructions[j], *reconstructions[i])) {
6868
LOG(INFO) << StringPrintf(
6969
"=> Merged clusters with %d and %d images into %d images",
7070
num_reg_images_i,

‎src/colmap/controllers/incremental_mapper.cc‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,14 @@ IncrementalMapperController::ReconstructSubModel(
371371
image_t next_image_id;
372372
for (size_t reg_trial = 0; reg_trial < next_images.size(); ++reg_trial) {
373373
next_image_id = next_images[reg_trial];
374-
const Image& next_image = reconstruction->Image(next_image_id);
375374

376375
LOG(INFO) << StringPrintf("Registering image #%d (%d)",
377376
next_image_id,
378377
reconstruction->NumRegImages() + 1);
379-
LOG(INFO) << StringPrintf("=> Image sees %d / %d points",
380-
next_image.NumVisiblePoints3D(),
381-
next_image.NumObservations());
378+
LOG(INFO) << StringPrintf(
379+
"=> Image sees %d / %d points",
380+
mapper.ObservationManager().NumVisiblePoints3D(next_image_id),
381+
mapper.ObservationManager().NumObservations(next_image_id));
382382

383383
reg_next_success =
384384
mapper.RegisterNextImage(mapper_options, next_image_id);
@@ -552,7 +552,8 @@ void IncrementalMapperController::TriangulateReconstruction(
552552
LOG(INFO) << StringPrintf("Triangulating image #%d (%d)", image_id, i);
553553
const size_t num_existing_points3D = image.NumPoints3D();
554554
LOG(INFO) << "=> Image sees " << num_existing_points3D << " / "
555-
<< image.NumObservations() << " points";
555+
<< mapper.ObservationManager().NumObservations(image_id)
556+
<< " points";
556557

557558
mapper.TriangulateImage(options_->Triangulation(), image_id);
558559
VLOG(1) << "=> Triangulated "

‎src/colmap/estimators/alignment.cc‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,10 @@ bool AlignReconstructionsViaPoints(const Reconstruction& src_reconstruction,
410410

411411
bool MergeReconstructions(const double max_reproj_error,
412412
const Reconstruction& src_reconstruction,
413-
Reconstruction* tgt_reconstruction) {
413+
Reconstruction& tgt_reconstruction) {
414414
Sim3d tgt_from_src;
415415
if (!AlignReconstructionsViaReprojections(src_reconstruction,
416-
*tgt_reconstruction,
416+
tgt_reconstruction,
417417
/*min_inlier_observations=*/0.3,
418418
max_reproj_error,
419419
&tgt_from_src)) {
@@ -426,7 +426,7 @@ bool MergeReconstructions(const double max_reproj_error,
426426
std::unordered_set<image_t> missing_image_ids;
427427
missing_image_ids.reserve(src_reconstruction.NumRegImages());
428428
for (const auto& image_id : src_reconstruction.RegImageIds()) {
429-
if (tgt_reconstruction->ExistsImage(image_id)) {
429+
if (tgt_reconstruction.ExistsImage(image_id)) {
430430
common_image_ids.insert(image_id);
431431
} else {
432432
missing_image_ids.insert(image_id);
@@ -439,10 +439,10 @@ bool MergeReconstructions(const double max_reproj_error,
439439
src_image.SetRegistered(false);
440440
src_image.CamFromWorld() =
441441
TransformCameraWorld(tgt_from_src, src_image.CamFromWorld());
442-
tgt_reconstruction->AddImage(src_image);
443-
tgt_reconstruction->RegisterImage(image_id);
444-
if (!tgt_reconstruction->ExistsCamera(src_image.CameraId())) {
445-
tgt_reconstruction->AddCamera(
442+
tgt_reconstruction.AddImage(src_image);
443+
tgt_reconstruction.RegisterImage(image_id);
444+
if (!tgt_reconstruction.ExistsCamera(src_image.CameraId())) {
445+
tgt_reconstruction.AddCamera(
446446
src_reconstruction.Camera(src_image.CameraId()));
447447
}
448448
}
@@ -461,7 +461,7 @@ bool MergeReconstructions(const double max_reproj_error,
461461
std::unordered_set<point3D_t> old_point3D_ids;
462462
for (const auto& track_el : point3D.second.track.Elements()) {
463463
if (common_image_ids.count(track_el.image_id) > 0) {
464-
const auto& point2D = tgt_reconstruction->Image(track_el.image_id)
464+
const auto& point2D = tgt_reconstruction.Image(track_el.image_id)
465465
.Point2D(track_el.point2D_idx);
466466
if (point2D.HasPoint3D()) {
467467
old_track.AddElement(track_el);
@@ -470,7 +470,7 @@ bool MergeReconstructions(const double max_reproj_error,
470470
new_track.AddElement(track_el);
471471
}
472472
} else if (missing_image_ids.count(track_el.image_id) > 0) {
473-
tgt_reconstruction->Image(track_el.image_id)
473+
tgt_reconstruction.Image(track_el.image_id)
474474
.ResetPoint3DForPoint2D(track_el.point2D_idx);
475475
new_track.AddElement(track_el);
476476
}
@@ -483,15 +483,12 @@ bool MergeReconstructions(const double max_reproj_error,
483483
if (create_new_point || merge_new_and_old_point) {
484484
const Eigen::Vector3d xyz = tgt_from_src * point3D.second.xyz;
485485
const auto point3D_id =
486-
tgt_reconstruction->AddPoint3D(xyz, new_track, point3D.second.color);
486+
tgt_reconstruction.AddPoint3D(xyz, new_track, point3D.second.color);
487487
if (old_point3D_ids.size() == 1) {
488-
tgt_reconstruction->MergePoints3D(point3D_id, *old_point3D_ids.begin());
488+
tgt_reconstruction.MergePoints3D(point3D_id, *old_point3D_ids.begin());
489489
}
490490
}
491491
}
492-
493-
tgt_reconstruction->FilterAllPoints3D(max_reproj_error, /*min_tri_angle=*/0);
494-
495492
return true;
496493
}
497494

‎src/colmap/estimators/alignment.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ std::vector<ImageAlignmentError> ComputeImageAlignmentError(
9191
// points3D into the target using the alignment. Returns false on failure.
9292
bool MergeReconstructions(double max_reproj_error,
9393
const Reconstruction& src_reconstruction,
94-
Reconstruction* tgt_reconstruction);
94+
Reconstruction& tgt_reconstruction);
9595

9696
} // namespace colmap

‎src/colmap/exe/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ COLMAP_ADD_LIBRARY(
5959
colmap_geometry
6060
colmap_optim
6161
colmap_scene
62+
colmap_sfm
6263
colmap_util
6364
PRIVATE_LINK_LIBS
6465
Boost::boost
66+
colmap_sfm
6567
)
6668

6769
COLMAP_ADD_EXECUTABLE(

0 commit comments

Comments
 (0)