From ae9061baead42966ad4e55082f5f9beda2efbb67 Mon Sep 17 00:00:00 2001 From: MotivaCG Date: Fri, 25 Apr 2025 10:09:51 +0200 Subject: [PATCH 1/8] Fix comment in ExistsFile --- src/colmap/util/file.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/colmap/util/file.h b/src/colmap/util/file.h index 71a7db6293..c93041b5ea 100644 --- a/src/colmap/util/file.h +++ b/src/colmap/util/file.h @@ -82,7 +82,7 @@ void FileCopy(const std::string& src_path, const std::string& dst_path, CopyType type = CopyType::COPY); -// Check if the path points to an existing directory. +// Check if the path points to an existing file. bool ExistsFile(const std::string& path); // Check if the path points to an existing directory. From b9e08bd84ff51f3afddd66f882a97eadac72efa9 Mon Sep 17 00:00:00 2001 From: MotivaCG Date: Fri, 25 Apr 2025 10:10:25 +0200 Subject: [PATCH 2/8] Allow .png masks without double extension (keeping old behaviour as default) --- src/colmap/controllers/image_reader.cc | 19 +++++++++++++++---- src/colmap/mvs/fusion.cc | 10 +++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/colmap/controllers/image_reader.cc b/src/colmap/controllers/image_reader.cc index 3ce3c396ea..5c416c0e2d 100644 --- a/src/colmap/controllers/image_reader.cc +++ b/src/colmap/controllers/image_reader.cc @@ -146,11 +146,22 @@ ImageReader::Status ImageReader::Next(Camera* camera, ////////////////////////////////////////////////////////////////////////////// if (mask && !options_.mask_path.empty()) { - const std::string mask_path = + std::string mask_path = JoinPaths(options_.mask_path, image->Name() + ".png"); - if (!ExistsFile(mask_path)) { - LOG(ERROR) << "Mask at " << mask_path << " does not exist."; - return Status::MASK_ERROR; + if (!ExistsFile(mask_path)) { + bool exists_mask = false; + if (HasFileExtension(image->Name(), ".png")){ + std::string alt_mask_path = + JoinPaths(options_.mask_path, image->Name()); + if (ExistsFile(alt_mask_path)) { + mask_path = alt_mask_path; + exists_mask = true; + } + } + if (!exists_mask) { + LOG(ERROR) << "Mask at " << mask_path << " does not exist."; + return Status::MASK_ERROR; + } } if (!mask->Read(mask_path, false)) { LOG(ERROR) << "Failed to read invalid mask file at: " << mask_path; diff --git a/src/colmap/mvs/fusion.cc b/src/colmap/mvs/fusion.cc index 60f169d939..521598d807 100644 --- a/src/colmap/mvs/fusion.cc +++ b/src/colmap/mvs/fusion.cc @@ -339,9 +339,13 @@ void StereoFusion::InitFusedPixelMask(int image_idx, size_t height) { Bitmap mask; Mat& fused_pixel_mask = fused_pixel_masks_.at(image_idx); - const std::string mask_path = - JoinPaths(options_.mask_path, - workspace_->GetModel().GetImageName(image_idx) + ".png"); + const std::string mask_image_name = + workspace_->GetModel().GetImageName(image_idx); + std::string mask_path = + JoinPaths(options_.mask_path, mask_image_name + ".png"); + if (!ExistsFile(mask_path) && HasFileExtension(mask_image_name, ".png")) { + mask_path = JoinPaths(options_.mask_path, mask_image_name); + } fused_pixel_mask = Mat(width, height, 1); if (!options_.mask_path.empty() && ExistsFile(mask_path) && mask.Read(mask_path, false)) { From 519dfc35a04f05ae099aed4e4d97cc5e3206367b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 28 May 2025 16:52:00 +0200 Subject: [PATCH 3/8] Update src/colmap/controllers/image_reader.cc --- src/colmap/controllers/image_reader.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/colmap/controllers/image_reader.cc b/src/colmap/controllers/image_reader.cc index 21062d1d95..d4df1f1126 100644 --- a/src/colmap/controllers/image_reader.cc +++ b/src/colmap/controllers/image_reader.cc @@ -164,7 +164,7 @@ ImageReader::Status ImageReader::Next(Rig* rig, std::string alt_mask_path = JoinPaths(options_.mask_path, image->Name()); if (ExistsFile(alt_mask_path)) { - mask_path = alt_mask_path; + mask_path = std::move(alt_mask_path); exists_mask = true; } } From 78a1fce5d7ff9dfa73fd787880e264f1f97b685b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 28 May 2025 16:52:45 +0200 Subject: [PATCH 4/8] Update src/colmap/mvs/fusion.cc --- src/colmap/mvs/fusion.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/colmap/mvs/fusion.cc b/src/colmap/mvs/fusion.cc index 521598d807..e4cec63364 100644 --- a/src/colmap/mvs/fusion.cc +++ b/src/colmap/mvs/fusion.cc @@ -341,7 +341,7 @@ void StereoFusion::InitFusedPixelMask(int image_idx, Mat& fused_pixel_mask = fused_pixel_masks_.at(image_idx); const std::string mask_image_name = workspace_->GetModel().GetImageName(image_idx); - std::string mask_path = + const std::string mask_path = JoinPaths(options_.mask_path, mask_image_name + ".png"); if (!ExistsFile(mask_path) && HasFileExtension(mask_image_name, ".png")) { mask_path = JoinPaths(options_.mask_path, mask_image_name); From 4ef52fdcb5344872327c6399454edf2d91e56038 Mon Sep 17 00:00:00 2001 From: MotivaCG Date: Mon, 2 Jun 2025 10:31:18 +0200 Subject: [PATCH 5/8] Fix: Allow mask_path reassignment --- src/colmap/mvs/fusion.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/colmap/mvs/fusion.cc b/src/colmap/mvs/fusion.cc index be625af276..fbdea97956 100644 --- a/src/colmap/mvs/fusion.cc +++ b/src/colmap/mvs/fusion.cc @@ -341,7 +341,7 @@ void StereoFusion::InitFusedPixelMask(int image_idx, Mat& fused_pixel_mask = fused_pixel_masks_.at(image_idx); const std::string mask_image_name = workspace_->GetModel().GetImageName(image_idx); - const std::string mask_path = + std::string mask_path = JoinPaths(options_.mask_path, mask_image_name + ".png"); if (!ExistsFile(mask_path) && HasFileExtension(mask_image_name, ".png")) { mask_path = JoinPaths(options_.mask_path, mask_image_name); From 3da424543dac5b53d09afd2dc172fea4c1448ce0 Mon Sep 17 00:00:00 2001 From: MotivaCG Date: Mon, 2 Jun 2025 16:24:22 +0200 Subject: [PATCH 6/8] Code format: remove extra spaces --- src/colmap/mvs/fusion.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/colmap/mvs/fusion.cc b/src/colmap/mvs/fusion.cc index fbdea97956..d82e010333 100644 --- a/src/colmap/mvs/fusion.cc +++ b/src/colmap/mvs/fusion.cc @@ -342,9 +342,9 @@ void StereoFusion::InitFusedPixelMask(int image_idx, const std::string mask_image_name = workspace_->GetModel().GetImageName(image_idx); std::string mask_path = - JoinPaths(options_.mask_path, mask_image_name + ".png"); + JoinPaths(options_.mask_path, mask_image_name + ".png"); if (!ExistsFile(mask_path) && HasFileExtension(mask_image_name, ".png")) { - mask_path = JoinPaths(options_.mask_path, mask_image_name); + mask_path = JoinPaths(options_.mask_path, mask_image_name); } fused_pixel_mask = Mat(width, height, 1); if (!options_.mask_path.empty() && ExistsFile(mask_path) && From 4bb10c9eeeb1eaf7488db8468978adb222289606 Mon Sep 17 00:00:00 2001 From: MotivaCG Date: Thu, 5 Jun 2025 09:17:14 +0200 Subject: [PATCH 7/8] More code formating --- src/colmap/controllers/image_reader.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/colmap/controllers/image_reader.cc b/src/colmap/controllers/image_reader.cc index d4df1f1126..aa9ae6a7ef 100644 --- a/src/colmap/controllers/image_reader.cc +++ b/src/colmap/controllers/image_reader.cc @@ -158,15 +158,15 @@ ImageReader::Status ImageReader::Next(Rig* rig, if (mask && !options_.mask_path.empty()) { std::string mask_path = JoinPaths(options_.mask_path, image->Name() + ".png"); - if (!ExistsFile(mask_path)) { + if (!ExistsFile(mask_path)) { bool exists_mask = false; - if (HasFileExtension(image->Name(), ".png")){ + if (HasFileExtension(image->Name(), ".png")) { std::string alt_mask_path = JoinPaths(options_.mask_path, image->Name()); if (ExistsFile(alt_mask_path)) { mask_path = std::move(alt_mask_path); exists_mask = true; - } + } } if (!exists_mask) { LOG(ERROR) << "Mask at " << mask_path << " does not exist."; From a5ae7d65394225a3eb01f1cf840ee2a02b8a577f Mon Sep 17 00:00:00 2001 From: MotivaCG Date: Mon, 9 Jun 2025 09:57:44 +0200 Subject: [PATCH 8/8] Fix clang check issues --- src/colmap/controllers/image_reader.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/colmap/controllers/image_reader.cc b/src/colmap/controllers/image_reader.cc index aa9ae6a7ef..832d1d5277 100644 --- a/src/colmap/controllers/image_reader.cc +++ b/src/colmap/controllers/image_reader.cc @@ -168,7 +168,7 @@ ImageReader::Status ImageReader::Next(Rig* rig, exists_mask = true; } } - if (!exists_mask) { + if (!exists_mask) { LOG(ERROR) << "Mask at " << mask_path << " does not exist."; return Status::MASK_ERROR; }