8000 Make it possible to build the MVS doc even when CUDA is not installed by sarlinpe · Pull Request #3078 · colmap/colmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make it possible to build the MVS doc even when CUDA is not installed #3078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to 8000 load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/colmap/mvs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ COLMAP_ADD_LIBRARY(
meshing.h meshing.cc
model.h model.cc
normal_map.h normal_map.cc
patch_match_options.h patch_match_options.cc
workspace.h workspace.cc
PUBLIC_LINK_LIBS
colmap_util
Expand Down
31 changes: 1 addition & 30 deletions src/colmap/mvs/patch_match.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,9 @@ PatchMatch::PatchMatch(const PatchMatchOptions& options, const Problem& problem)

PatchMatch::~PatchMatch() {}

void PatchMatchOptions::Print() const {
PrintHeading2("PatchMatchOptions");
PrintOption(max_image_size);
PrintOption(gpu_index);
PrintOption(depth_min);
PrintOption(depth_max);
PrintOption(window_radius);
PrintOption(window_step);
PrintOption(sigma_spatial);
PrintOption(sigma_color);
PrintOption(num_samples);
PrintOption(ncc_sigma);
PrintOption(min_triangulation_angle);
PrintOption(incident_angle_sigma);
PrintOption(num_iterations);
PrintOption(geom_consistency);
PrintOption(geom_consistency_regularizer);
PrintOption(geom_consistency_max_cost);
PrintOption(filter);
PrintOption(filter_min_ncc);
PrintOption(filter_min_triangulation_angle);
PrintOption(filter_min_num_consistent);
PrintOption(filter_geom_consistency_max_cost);
PrintOption(write_consistency_graph);
PrintOption(allow_missing_files);
}

void PatchMatch::Problem::Print() const {
PrintHeading2("PatchMatch::Problem");

PrintOption(ref_image_idx);

LOG(INFO) << "ref_image_idx: " << ref_image_idx;
LOG(INFO) << "src_image_idxs: ";
if (!src_image_idxs.empty()) {
for (size_t i = 0; i < src_image_idxs.size() - 1; ++i) {
Expand Down
121 changes: 1 addition & 120 deletions src/colmap/mvs/patch_match.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "colmap/mvs/image.h"
#include "colmap/mvs/model.h"
#include "colmap/mvs/normal_map.h"
#include "colmap/mvs/patch_match_options.h"
#ifndef __CUDACC__
#include "colmap/util/base_controller.h"
#include "colmap/util/logging.h"
Expand All @@ -46,130 +47,10 @@
namespace colmap {
namespace mvs {

// Maximum possible window radius for the photometric consistency cost. This
// value is equal to THREADS_PER_BLOCK in patch_match_cuda.cu and the limit
// arises from the shared memory implementation.
const static size_t kMaxPatchMatchWindowRadius = 32;

class ConsistencyGraph;
class PatchMatchCuda;
class Workspace;

struct PatchMatchOptions {
// Maximum image size in either dimension.
int max_image_size = -1;

// Index of the GPU used for patch match. For multi-GPU usage,
// you should separate multiple GPU indices by comma, e.g., "0,1,2,3".
std::string gpu_index = "-1";

// Depth range in which to randomly sample depth hypotheses.
double depth_min = -1.0f;
double depth_max = -1.0f;

// Half window size to compute NCC photo-consistency cost.
int window_radius = 5;

// Number of pixels to skip when computing NCC. For a value of 1, every
// pixel is used to compute the NCC. For larger values, only every n-th row
// and column is used and the computation speed thereby increases roughly by
// a factor of window_step^2. Note that not all combinations of window sizes
// and steps produce nice results, especially if the step is greather than 2.
int window_step = 1;

// Parameters for bilaterally weighted NCC.
double sigma_spatial = -1;
double sigma_color = 0.2f;

// Number of random samples to draw in Monte Carlo sampling.
int num_samples = 15;

// Spread of the NCC likelihood function.
double ncc_sigma = 0.6f;

// Minimum triangulation angle in degrees.
double min_triangulation_angle = 1.0f;

// Spread of the incident angle likelihood function.
double incident_angle_sigma = 0.9f;

// Number of coordinate descent iterations. Each iteration consists
// of four sweeps from left to right, top to bottom, and vice versa.
int num_iterations = 5;

// Whether to add a regularized geometric consistency term to the cost
// function. If true, the `depth_maps` and `normal_maps` must not be null.
bool geom_consistency = true;

// The relative weight of the geometric consistency term w.r.t. to
// the photo-consistency term.
double geom_consistency_regularizer = 0.3f;

// Maximum geometric consistency cost in terms of the forward-backward
// reprojection error in pixels.
double geom_consistency_max_cost = 3.0f;

// Whether to enable filtering.
bool filter = true;

// Minimum NCC coefficient for pixel to be photo-consistent.
double filter_min_ncc = 0.1f;

// Minimum triangulation angle to be stable.
double filter_min_triangulation_angle = 3.0f;

// Minimum number of source images have to be consistent
// for pixel not to be filtered.
int filter_min_num_consistent = 2;

// Maximum forward-backward reprojection error for pixel
// to be geometrically consistent.
double filter_geom_consistency_max_cost = 1.0f;

// Cache size in gigabytes for patch match, which keeps the bitmaps, depth
// maps, and normal maps of this number of images in memory. A higher value
// leads to less disk access and faster computation, while a lower value
// leads to reduced memory usage. Note that a single image can consume a lot
// of memory, if the consistency graph is dense.
double cache_size = 32.0;

// Whether to tolerate missing images/maps in the problem setup
bool allow_missing_files = false;

// Whether to write the consistency graph.
bool write_consistency_graph = false;

void Print() const;
bool Check() const {
if (depth_min != -1.0f || depth_max != -1.0f) {
CHECK_OPTION_LE(depth_min, depth_max);
CHECK_OPTION_GE(depth_min, 0.0f);
}
CHECK_OPTION_LE(window_radius,
static_cast<int>(kMaxPatchMatchWindowRadius));
CHECK_OPTION_GT(sigma_color, 0.0f);
CHECK_OPTION_GT(window_radius, 0);
CHECK_OPTION_GT(window_step, 0);
CHECK_OPTION_LE(window_step, 2);
CHECK_OPTION_GT(num_samples, 0);
CHECK_OPTION_GT(ncc_sigma, 0.0f);
CHECK_OPTION_GE(min_triangulation_angle, 0.0f);
CHECK_OPTION_LT(min_triangulation_angle, 180.0f);
CHECK_OPTION_GT(incident_angle_sigma, 0.0f);
CHECK_OPTION_GT(num_iterations, 0);
CHECK_OPTION_GE(geom_consistency_regularizer, 0.0f);
CHECK_OPTION_GE(geom_consistency_max_cost, 0.0f);
CHECK_OPTION_GE(filter_min_ncc, -1.0f);
CHECK_OPTION_LE(filter_min_ncc, 1.0f);
CHECK_OPTION_GE(filter_min_triangulation_angle, 0.0f);
CHECK_OPTION_LE(filter_min_triangulation_angle, 180.0f);
CHECK_OPTION_GE(filter_min_num_consistent, 0);
CHECK_OPTION_GE(filter_geom_consistency_max_cost, 0.0f);
CHECK_OPTION_GT(cache_size, 0);
return true;
}
};

// This is a wrapper class around the actual PatchMatchCuda implementation. This
// class is necessary to hide Cuda code from any boost or Eigen code, since
// NVCC/MSVC cannot compile complex C++ code.
Expand Down
101 changes: 101 additions & 0 deletions src/colmap/mvs/patch_match_options.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) 2023, ETH Zurich and UNC Chapel Hill.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#include "colmap/mvs/patch_match_options.h"

#include "colmap/util/logging.h"
#include "colmap/util/misc.h"

namespace colmap {
namespace mvs {

// Maximum possible window radius for the photometric consistency cost. This
// value is equal to THREADS_PER_BLOCK in patch_match_cuda.cu and the limit
// arises from the shared memory implementation.
const static size_t kMaxPatchMatchWindowRadius = 32;

#define PrintOption(option) LOG(INFO) << #option ": " << option

void PatchMatchOptions::Print() const {
PrintHeading2("PatchMatchOptions");
PrintOption(max_image_size);
PrintOption(gpu_index);
PrintOption(depth_min);
PrintOption(depth_max);
PrintOption(window_radius);
PrintOption(window_step);
PrintOption(sigma_spatial);
PrintOption(sigma_color);
PrintOption(num_samples);
PrintOption(ncc_sigma);
PrintOption(min_triangulation_angle);
PrintOption(incident_angle_sigma);
PrintOption(num_iterations);
PrintOption(geom_consistency);
PrintOption(geom_consistency_regularizer);
PrintOption(geom_consistency_max_cost);
PrintOption(filter);
PrintOption(filter_min_ncc);
PrintOption(filter_min_triangulation_angle);
PrintOption(filter_min_num_consistent);
PrintOption(filter_geom_consistency_max_cost);
PrintOption(write_consistency_graph);
PrintOption(allow_missing_files);
}

bool PatchMatchOptions::Check() const {
if (depth_min != -1.0f || depth_max != -1.0f) {
CHECK_OPTION_LE(depth_min, depth_max);
CHECK_OPTION_GE(depth_min, 0.0f);
}
CHECK_OPTION_LE(window_radius, static_cast<int>(kMaxPatchMatchWindowRadius));
CHECK_OPTION_GT(sigma_color, 0.0f);
CHECK_OPTION_GT(window_radius, 0);
CHECK_OPTION_GT(window_step, 0);
CHECK_OPTION_LE(window_step, 2);
CHECK_OPTION_GT(num_samples, 0);
CHECK_OPTION_GT(ncc_sigma, 0.0f);
CHECK_OPTION_GE(min_triangulation_angle, 0.0f);
CHECK_OPTION_LT(min_triangulation_angle, 180.0f);
CHECK_OPTION_GT(incident_angle_sigma, 0.0f);
CHECK_OPTION_GT(num_iterations, 0);
CHECK_OPTION_GE(geom_consistency_regularizer, 0.0f);
CHECK_OPTION_GE(geom_consistency_max_cost, 0.0f);
CHECK_OPTION_GE(filter_min_ncc, -1.0f);
CHECK_OPTION_LE(filter_min_ncc, 1.0f);
CHECK_OPTION_GE(filter_min_triangulation_angle, 0.0f);
CHECK_OPTION_LE(filter_min_triangulation_angle, 180.0f);
CHECK_OPTION_GE(filter_min_num_consistent, 0);
CHECK_OPTION_GE(filter_geom_consistency_max_cost, 0.0f);
CHECK_OPTION_GT(cache_size, 0);
return true;
}

} // namespace mvs
} // namespace colmap
Loading
Loading
0