8000 Allow custom config and missing dependencies for patch-match by anmatako · Pull Request #1142 · colmap/colmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow custom config and missing dependencies for patch-match #1142

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 1 commit into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/exe/colmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ int RunPatchMatchStereo(int argc, char** argv) {
std::string workspace_path;
std::string workspace_format = "COLMAP";
std::string pmvs_option_name = "option-all";
std::string config_path;

OptionManager options;
options.AddRequiredOption(
Expand All @@ -434,6 +435,7 @@ int RunPatchMatchStereo(int argc, char** argv) {
options.AddDefaultOption("workspace_format", &workspace_format,
"{COLMAP, PMVS}");
options.AddDefaultOption("pmvs_option_name", &pmvs_option_name);
options.AddDefaultOption("config_path", &config_path);
options.AddPatchMatchStereoOptions();
options.Parse(argc, argv);

Expand All @@ -447,7 +449,7 @@ int RunPatchMatchStereo(int argc, char** argv) {

mvs::PatchMatchController controller(*options.patch_match_stereo,
workspace_path, workspace_format,
pmvs_option_name);
pmvs_option_name, config_path);

controller.Start();
controller.Wait();
Expand Down
48 changes: 41 additions & 7 deletions src/mvs/patch_match.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void PatchMatchOptions::Print() const {
PrintOption(filter_min_num_consistent);
PrintOption(filter_geom_consistency_max_cost);
PrintOption(write_consistency_graph);
PrintOption(allow_missing_files);
}

void PatchMatch::Problem::Print() const {
Expand Down Expand Up @@ -183,11 +184,13 @@ ConsistencyGraph PatchMatch::GetConsistencyGraph() const {
PatchMatchController::PatchMatchController(const PatchMatchOptions& options,
const std::string& workspace_path,
const std::string& workspace_format,
const std::string& pmvs_option_name)
const std::string& pmvs_option_name,
const std::string& config_path)
: options_(options),
workspace_path_(workspace_path),
workspace_format_(workspace_format),
pmvs_option_name_(pmvs_option_name) {
pmvs_option_name_(pmvs_option_name),
config_path_(config_path) {
std::vector<int> gpu_indices = CSVToVector<int>(options_.gpu_index);
}

Expand Down Expand Up @@ -262,9 +265,12 @@ void PatchMatchController::ReadProblems() {

const auto& model = workspace_->GetModel();

std::vector<std::string> config = ReadTextFileLines(
JoinPaths(workspace_path_, workspace_->GetOptions().stereo_folder,
"patch-match.cfg"));
const std::string config_path =
config_path_.empty()
? JoinPaths(workspace_path_, workspace_->GetOptions().stereo_folder,
"patch-match.cfg")
: config_path_;
std::vector<std::string> config = ReadTextFileLines(config_path);

std::vector<std::map<int, int>> shared_num_points;
std::vector<std::map<int, float>> triangulation_angles;
Expand Down Expand Up @@ -432,8 +438,8 @@ void PatchMatchController::ProcessProblem(const PatchMatchOptions& options,
return;
}

PrintHeading1(StringPrintf("Processing view %d / %d", problem_idx + 1,
problems_.size()));
PrintHeading1(StringPrintf("Processing view %d / %d for %s", problem_idx + 1,
problems_.size(), image_name.c_str()));

auto patch_match_options = options;

Expand Down Expand Up @@ -481,13 +487,41 @@ void PatchMatchController::ProcessProblem(const PatchMatchOptions& options,
std::unique_lock<std::mutex> lock(workspace_mutex_);

std::cout << "Reading inputs..." << std::endl;
std::vector<int> src_image_idxs;
for (const auto image_idx : used_image_idxs) {
std::string image_path = workspace_->GetBitmapPath(image_idx);
std::string depth_path = workspace_->GetDepthMapPath(image_idx);
std::string normal_path = workspace_->GetNormalMapPath(image_idx);

if (!ExistsFile(image_path) ||
(options.geom_consistency && !ExistsFile(depth_path)) ||
(options.geom_consistency && !ExistsFile(normal_path))) {
if (options.allow_missing_files) {
std::cout << StringPrintf(
"WARN: Skipping source image %d: %s for missing "
"image or depth/normal map",
image_idx, model.GetImageName(image_idx).c_str())
<< std::endl;
continue;
} else {
std::cout
<< StringPrintf(
"ERROR: Missing image or map dependency for image %d: %s",
image_idx, model.GetImageName(image_idx).c_str())
<< std::endl;
}
}

if (image_idx != problem.ref_image_idx) {
src_image_idxs.push_back(image_idx);
}
images.at(image_idx).SetBitmap(workspace_->GetBitmap(image_idx));
if (options.geom_consistency) {
depth_maps.at(image_idx) = workspace_->GetDepthMap(image_idx);
normal_maps.at(image_idx) = workspace_->GetNormalMap(image_idx);
}
}
problem.src_image_idxs = src_image_idxs;
}

problem.Print();
Expand Down
7 changes: 6 additions & 1 deletion src/mvs/patch_match.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ struct PatchMatchOptions {
// 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;

Expand Down Expand Up @@ -250,7 +253,8 @@ class PatchMatchController : public Thread {
PatchMatchController(const PatchMatchOptions& options,
const std::string& workspace_path,
const std::string& workspace_format,
const std::string& pmvs_option_name);
const std::string& pmvs_option_name,
const std::string& config_path = "");

private:
void Run();
Expand All @@ -264,6 +268,7 @@ class PatchMatchController : public Thread {
const std::string workspace_path_;
const std::string workspace_format_;
const std::string pmvs_option_name_;
const std::string config_path_;

std::unique_ptr<ThreadPool> thread_pool_;
std::mutex workspace_mutex_;
Expand Down
2 changes: 2 additions & 0 deletions src/util/option_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ void OptionManager::AddPatchMatchStereoOptions() {
&patch_match_stereo->filter_geom_consistency_max_cost);
AddAndRegisterDefaultOption("PatchMatchStereo.cache_size",
&patch_match_stereo->cache_size);
AddAndRegisterDefaultOption("PatchMatchStereo.allow_missing_files",
&patch_match_stereo->allow_missing_files);
AddAndRegisterDefaultOption("PatchMatchStereo.write_consistency_graph",
&patch_match_stereo->write_consistency_graph);
}
Expand Down
0