From 62fc2fa9419ed311272e6e0d310e4ca7e57b33ca Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Wed, 11 Sep 2024 18:41:39 +0200 Subject: [PATCH 1/5] fix missing camera ptr for Reconstruction.DeleteAllPoints2DAndPoints3D() --- src/colmap/scene/reconstruction.cc | 1 + src/colmap/sfm/incremental_mapper.cc | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/colmap/scene/reconstruction.cc b/src/colmap/scene/reconstruction.cc index 40c4c33cd6..3b051d3e0a 100644 --- a/src/colmap/scene/reconstruction.cc +++ b/src/colmap/scene/reconstruction.cc @@ -237,6 +237,7 @@ void Reconstruction::DeleteAllPoints2DAndPoints3D() { new_image.SetImageId(image.second.ImageId()); new_image.SetName(image.second.Name()); new_image.SetCameraId(image.second.CameraId()); + new_image.SetCameraPtr(image.second.CameraPtr()); new_image.SetRegistered(image.second.IsRegistered()); new_image.CamFromWorld() = image.second.CamFromWorld(); image.second = std::move(new_image); diff --git a/src/colmap/sfm/incremental_mapper.cc b/src/colmap/sfm/incremental_mapper.cc index 9b6d3c2b4c..a9d334098f 100644 --- a/src/colmap/sfm/incremental_mapper.cc +++ b/src/colmap/sfm/incremental_mapper.cc @@ -113,7 +113,6 @@ void IncrementalMapper::BeginReconstruction( THROW_CHECK(reconstruction_ == nullptr); reconstruction_ = reconstruction; reconstruction_->Load(*database_cache_); - // reconstruction_->SetUp(); obs_manager_ = std::make_shared( *reconstruction_, database_cache_->CorrespondenceGraph()); triangulator_ = std::make_shared( From 58e3d48af69354bb4c9a5f07c9ef645fccc065f3 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Wed, 11 Sep 2024 21:40:40 +0200 Subject: [PATCH 2/5] add some tests. --- src/colmap/scene/reconstruction.cc | 9 +++++++++ src/colmap/scene/reconstruction.h | 3 +++ src/colmap/scene/reconstruction_test.cc | 14 ++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/colmap/scene/reconstruction.cc b/src/colmap/scene/reconstruction.cc index 3b051d3e0a..e8e716ba87 100644 --- a/src/colmap/scene/reconstruction.cc +++ b/src/colmap/scene/reconstruction.cc @@ -43,6 +43,15 @@ namespace colmap { Reconstruction::Reconstruction() : max_point3D_id_(0) {} +bool Reconstruction::Check() const { + for (const auto& image : images_) { + if (!image.second.HasCameraPtr()) return false; + auto& camera = Camera(image.second.CameraId()); + if (image.second.CameraPtr() != &camera) return false; + } + return true; +} + std::unordered_set Reconstruction::Point3DIds() const { std::unordered_set point3D_ids; point3D_ids.reserve(points3D_.size()); diff --git a/src/colmap/scene/reconstruction.h b/src/colmap/scene/reconstruction.h index 58f325b6b9..ba90b9c0dc 100644 --- a/src/colmap/scene/reconstruction.h +++ b/src/colmap/scene/reconstruction.h @@ -59,6 +59,9 @@ class Reconstruction { public: Reconstruction(); + // [TEST] Check if all camera pointers are correctly set + bool Check() const; + // Get number of objects. inline size_t NumCameras() const; inline size_t NumImages() const; diff --git a/src/colmap/scene/reconstruction_test.cc b/src/colmap/scene/reconstruction_test.cc index 42c0437acf..f31f2fec28 100644 --- a/src/colmap/scene/reconstruction_test.cc +++ b/src/colmap/scene/reconstruction_test.cc @@ -31,6 +31,7 @@ #include "colmap/geometry/pose.h" #include "colmap/geometry/sim3.h" +#include "colmap/scene/synthetic.h" #include "colmap/sensor/models.h" #include @@ -100,6 +101,7 @@ TEST(Reconstruction, AddImage) { EXPECT_EQ(reconstruction.NumImages(), 1); EXPECT_EQ(reconstruction.NumRegImages(), 0); EXPECT_EQ(reconstruction.NumPoints3D(), 0); + EXPECT_TRUE(reconstruction.Check()); } TEST(Reconstruction, AddPoint3D) { @@ -473,5 +475,17 @@ TEST(Reconstruction, UpdatePoint3DErrors) { EXPECT_EQ(reconstruction.Point3D(point3D_id).error, 1); } +TEST(Reconstruction, DeleteAllPoints2DAndPoints3D) { + Reconstruction 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, &reconstruction); + reconstruction.DeleteAllPoints2DAndPoints3D(); + EXPECT_TRUE(reconstruction.Check()); +} + } // namespace } // namespace colmap From 882531d62e5b53cd93d78922860d1d53bb29d8b6 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Wed, 11 Sep 2024 22:12:55 +0200 Subject: [PATCH 3/5] minor add. --- src/colmap/scene/reconstruction_test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/colmap/scene/reconstruction_test.cc b/src/colmap/scene/reconstruction_test.cc index f31f2fec28..3198b06712 100644 --- a/src/colmap/scene/reconstruction_test.cc +++ b/src/colmap/scene/reconstruction_test.cc @@ -484,6 +484,7 @@ TEST(Reconstruction, DeleteAllPoints2DAndPoints3D) { synthetic_dataset_options.point2D_stddev = 0; SynthesizeDataset(synthetic_dataset_options, &reconstruction); reconstruction.DeleteAllPoints2DAndPoints3D(); + EXPECT_EQ(reconstruction.NumPoints3D(), 0); EXPECT_TRUE(reconstruction.Check()); } From 4e0d62b6b22ef959dd746694f6021a8048055b62 Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Wed, 11 Sep 2024 22:29:40 +0200 Subject: [PATCH 4/5] move Check() into test script. --- src/colmap/scene/reconstruction.cc | 9 --------- src/colmap/scene/reconstruction.h | 3 --- src/colmap/scene/reconstruction_test.cc | 14 ++++++++++++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/colmap/scene/reconstruction.cc b/src/colmap/scene/reconstruction.cc index e8e716ba87..3b051d3e0a 100644 --- a/src/colmap/scene/reconstruction.cc +++ b/src/colmap/scene/reconstruction.cc @@ -43,15 +43,6 @@ namespace colmap { Reconstruction::Reconstruction() : max_point3D_id_(0) {} -bool Reconstruction::Check() const { - for (const auto& image : images_) { - if (!image.second.HasCameraPtr()) return false; - auto& camera = Camera(image.second.CameraId()); - if (image.second.CameraPtr() != &camera) return false; - } - return true; -} - std::unordered_set Reconstruction::Point3DIds() const { std::unordered_set point3D_ids; point3D_ids.reserve(points3D_.size()); diff --git a/src/colmap/scene/reconstruction.h b/src/colmap/scene/reconstruction.h index ba90b9c0dc..58f325b6b9 100644 --- a/src/colmap/scene/reconstruction.h +++ b/src/colmap/scene/reconstruction.h @@ -59,9 +59,6 @@ class Reconstruction { public: Reconstruction(); - // [TEST] Check if all camera pointers are correctly set - bool Check() const; - // Get number of objects. inline size_t NumCameras() const; inline size_t NumImages() const; diff --git a/src/colmap/scene/reconstruction_test.cc b/src/colmap/scene/reconstruction_test.cc index 3198b06712..292ac3a8af 100644 --- a/src/colmap/scene/reconstruction_test.cc +++ b/src/colmap/scene/reconstruction_test.cc @@ -39,6 +39,16 @@ namespace colmap { namespace { +// Check if all camera pointers are correctly set +bool CheckReconstruction(const Reconstruction& reconstruction) { + for (const auto& image : reconstruction.images_) { + if (!image.second.HasCameraPtr()) return false; + auto& camera = reconstruction.Camera(image.second.CameraId()); + if (image.second.CameraPtr() != &camera) return false; + } + return true; +} + void GenerateReconstruction(const image_t num_images, Reconstruction* reconstruction) { const size_t kNumPoints2D = 10; @@ -101,7 +111,7 @@ TEST(Reconstruction, AddImage) { EXPECT_EQ(reconstruction.NumImages(), 1); EXPECT_EQ(reconstruction.NumRegImages(), 0); EXPECT_EQ(reconstruction.NumPoints3D(), 0); - EXPECT_TRUE(reconstruction.Check()); + EXPECT_TRUE(CheckReconstruction(reconstruction)); } TEST(Reconstruction, AddPoint3D) { @@ -485,7 +495,7 @@ TEST(Reconstruction, DeleteAllPoints2DAndPoints3D) { SynthesizeDataset(synthetic_dataset_options, &reconstruction); reconstruction.DeleteAllPoints2DAndPoints3D(); EXPECT_EQ(reconstruction.NumPoints3D(), 0); - EXPECT_TRUE(reconstruction.Check()); + EXPECT_TRUE(CheckReconstruction(reconstruction)); } } // namespace From b0a58a896bfa89f3fd8a967bd986308defa847de Mon Sep 17 00:00:00 2001 From: B1ueber2y Date: Wed, 11 Sep 2024 22:32:04 +0200 Subject: [PATCH 5/5] fix. --- src/colmap/scene/reconstruction_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/colmap/scene/reconstruction_test.cc b/src/colmap/scene/reconstruction_test.cc index 292ac3a8af..14d090c3fb 100644 --- a/src/colmap/scene/reconstruction_test.cc +++ b/src/colmap/scene/reconstruction_test.cc @@ -41,7 +41,7 @@ namespace { // Check if all camera pointers are correctly set bool CheckReconstruction(const Reconstruction& reconstruction) { - for (const auto& image : reconstruction.images_) { + for (const auto& image : reconstruction.Images()) { if (!image.second.HasCameraPtr()) return false; auto& camera = reconstruction.Camera(image.second.CameraId()); if (image.second.CameraPtr() != &camera) return false;