From 805db82b172bafa99bf2c4979f2e4bcac148a893 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Mon, 9 Sep 2024 20:13:15 +0200 Subject: [PATCH 1/5] add test for MergeReconstructions. --- src/colmap/estimators/alignment_test.cc | 30 +++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/colmap/estimators/alignment_test.cc b/src/colmap/estimators/alignment_test.cc index 069c0c09c0..a1eab13ef3 100644 --- a/src/colmap/estimators/alignment_test.cc +++ b/src/colmap/estimators/alignment_test.cc @@ -55,8 +55,6 @@ void ExpectEqualSim3d(const Sim3d& gt_tgt_from_src, const Sim3d& tgt_from_src) { } Reconstruction GenerateReconstructionForAlignment() { - // const std::string database_path = CreateTestDir() + "/database.db"; - // Database database(database_path); Reconstruction reconstruction; SyntheticDatasetOptions synthetic_dataset_options; synthetic_dataset_options.num_cameras = 2; @@ -116,4 +114,32 @@ TEST(Alignment, AlignReconstructionsViaPoints) { ExpectEqualSim3d(gt_tgt_from_src, tgt_from_src); } +TEST(Alignment, MergeReconstructions) { + // Synthesize a reconstruction which has at least two cameras + Reconstruction src_reconstruction; + SyntheticDatasetOptions synthetic_dataset_options; + synthetic_dataset_options.num_cameras = 2; + synthetic_dataset_options.num_images = 20; + synthetic_dataset_options.num_points3D = 50; + synthetic_dataset_options.point2D_stddev = 0; + SynthesizeDataset(synthetic_dataset_options, &src_reconstruction); + Reconstruction tgt_reconstruction = src_reconstruction; + + // Remove first camera from the target reconstruction + for (const auto& image_id : tgt_reconstruction.RegImageIds()) { + if (tgt_reconstruction.Image(image_id).CameraId() == 0) { + tgt_reconstruction.DeRegisterImage(image_id); + } + tgt_reconstruction.TearDown(); + } + EXPECT_EQ(tgt_reconstruction.NumCameras(), 1); + EXPECT_EQ(tgt_reconstruction.NumImages(), 10); + MergeReconstructions(0.01, src_reconstruction, tgt_reconstruction); + EXPECT_EQ(tgt_reconstruction.NumCameras(), 2); + EXPECT_EQ(tgt_reconstruction.NumImages(), 20); + EXPECT_EQ(tgt_reconstruction.NumPoints3D(), 50); + EXPECT_EQ(tgt_reconstruction.ComputeNumObservations(), + src_reconstruction.ComputeNumObservations); +} + } // namespace colmap From 857151cbb4c637e0ea0597512c9cdb2598797552 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Mon, 9 Sep 2024 20:16:06 +0200 Subject: [PATCH 2/5] update. --- src/colmap/estimators/alignment_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/colmap/estimators/alignment_test.cc b/src/colmap/estimators/alignment_test.cc index a1eab13ef3..63b6eae027 100644 --- a/src/colmap/estimators/alignment_test.cc +++ b/src/colmap/estimators/alignment_test.cc @@ -130,8 +130,8 @@ TEST(Alignment, MergeReconstructions) { if (tgt_reconstruction.Image(image_id).CameraId() == 0) { tgt_reconstruction.DeRegisterImage(image_id); } - tgt_reconstruction.TearDown(); } + tgt_reconstruction.TearDown(); EXPECT_EQ(tgt_reconstruction.NumCameras(), 1); EXPECT_EQ(tgt_reconstruction.NumImages(), 10); MergeReconstructions(0.01, src_reconstruction, tgt_reconstruction); From 6c6e55343984b74e98065aeadf6e2b2a5078e7f6 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Mon, 9 Sep 2024 20:17:53 +0200 Subject: [PATCH 3/5] update. --- src/colmap/estimators/alignment_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/colmap/estimators/alignment_test.cc b/src/colmap/estimators/alignment_test.cc index 63b6eae027..29366c190e 100644 --- a/src/colmap/estimators/alignment_test.cc +++ b/src/colmap/estimators/alignment_test.cc @@ -139,7 +139,7 @@ TEST(Alignment, MergeReconstructions) { EXPECT_EQ(tgt_reconstruction.NumImages(), 20); EXPECT_EQ(tgt_reconstruction.NumPoints3D(), 50); EXPECT_EQ(tgt_reconstruction.ComputeNumObservations(), - src_reconstruction.ComputeNumObservations); + src_reconstruction.ComputeNumObservations()); } } // namespace colmap From cbc13b2e8ee6b61d1d2bf5d911c3a52bf34069d0 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Mon, 9 Sep 2024 20:26:47 +0200 Subject: [PATCH 4/5] update. --- src/colmap/estimators/alignment_test.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/colmap/estimators/alignment_test.cc b/src/colmap/estimators/alignment_test.cc index 29366c190e..61e671ded0 100644 --- a/src/colmap/estimators/alignment_test.cc +++ b/src/colmap/estimators/alignment_test.cc @@ -125,9 +125,11 @@ TEST(Alignment, MergeReconstructions) { SynthesizeDataset(synthetic_dataset_options, &src_reconstruction); Reconstruction tgt_reconstruction = src_reconstruction; - // Remove first camera from the target reconstruction - for (const auto& image_id : tgt_reconstruction.RegImageIds()) { - if (tgt_reconstruction.Image(image_id).CameraId() == 0) { + // Remove the camera of the first image from the target reconstruction + const std::vector& image_ids = tgt_reconstruction.RegImageIds(); + camera_t camera_id = tgt_reconstruction.Image(image_ids[0]).CameraId(); + for (const auto& image_id : image_ids) { + if (tgt_reconstruction.Image(image_id).CameraId() == camera_id) { tgt_reconstruction.DeRegisterImage(image_id); } } From 3896096db95f3c81b804cffdcabcc82bf8bcfde2 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Mon, 9 Sep 2024 20:57:41 +0200 Subject: [PATCH 5/5] minor. --- src/colmap/estimators/alignment_test.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/colmap/estimators/alignment_test.cc b/src/colmap/estimators/alignment_test.cc index 61e671ded0..693ee2c6a7 100644 --- a/src/colmap/estimators/alignment_test.cc +++ b/src/colmap/estimators/alignment_test.cc @@ -136,6 +136,8 @@ TEST(Alignment, MergeReconstructions) { tgt_reconstruction.TearDown(); EXPECT_EQ(tgt_reconstruction.NumCameras(), 1); EXPECT_EQ(tgt_reconstruction.NumImages(), 10); + + // Merge reconstructions MergeReconstructions(0.01, src_reconstruction, tgt_reconstruction); EXPECT_EQ(tgt_reconstruction.NumCameras(), 2); EXPECT_EQ(tgt_reconstruction.NumImages(), 20);