ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
structure_from_motion.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 #include "pipelines/sfm.h"
11 #include "pybind/docstring.h"
13 
14 namespace cloudViewer {
15 namespace reconstruction {
16 namespace sfm {
17 
18 // Reconstruction structure from motion functions have similar arguments,
19 // sharing arg docstrings
20 static const std::unordered_map<std::string, std::string>
22  {"database_path",
23  "Path to database in which to store the extracted data"},
24  {"workspace_path",
25  "The path to the workspace folder in which all results are "
26  "stored."},
27  {"image_path",
28  "The path to the image folder which are used as input."},
29  {"mask_path",
30  "The path to the mask folder which are used as input."},
31  {"vocab_tree_path",
32  "The path to the vocabulary tree for feature matching."},
33  {"data_type",
34  "Supported data types are {individual, video, internet}."},
35  {"quality",
36  "Supported quality types are {low, medium, high, extreme}."},
37  {"camera_model", "Which camera model to use for images."},
38  {"single_camera", "Whether to use shared intrinsics or not."},
39  {"sparse", "Whether to perform sparse mapping."},
40  {"dense", "Whether to perform dense mapping."},
41  {"mesher",
42  "Supported meshing algorithm types are {poisson, delaunay}."},
43  {"num_threads", "The number of threads to use in all stages."},
44  {"use_gpu",
45  "Whether to use the GPU in feature extraction and matching."},
46  {"gpu_index",
47  "Index of the GPU used for GPU stages. For multi-GPU "
48  "computation, you should separate multiple GPU indices by "
49  "comma, e.g., ``0,1,2,3``. By default, all GPUs will be used "
50  "in all stages."},
51  {"input_path",
52  "The input path containing cameras.bin/txt, images.bin/txt "
53  "and points3D.bin/txt."},
54  {"output_path",
55  "The output path containing target cameras.bin/txt, "
56  "images.bin/txt and points3D.bin/txt."},
57  {"image_list_path",
58  "A text file path containing image file path."},
59  {"num_workers",
60  "The number of workers used to reconstruct clusters in "
61  "parallel."},
62  {"image_overlap",
63  "The number of overlapping images between child clusters."},
64  {"leaf_max_num_images",
65  "The maximum number of images in a leaf node cluster, "
66  "otherwise the cluster is further partitioned using the given "
67  "branching factor. "
68  "Note that a cluster leaf node will have at most "
69  "`leaf_max_num_images + overlap` images to satisfy the "
70  "overlap constraint."},
71  {"min_track_len", "The minimum track length."},
72  {"max_reproj_error", "The maximum re-projection error."},
73  {"min_tri_angle", "The minimum tri angle."},
74  {"clear_points",
75  "Whether to clear all existing points and observations."},
76  {"rig_config_path", "The rig config path."},
77  {"estimate_rig_relative_poses",
78  "Whether to estimate rig relative poses."},
79  {"refine_relative_poses",
80  "Whether to optimize the relative poses of the camera "
81  "rigs."}};
82 
83 void pybind_sfm_methods(py::module &m) {
84  m.def("auto_reconstruction", &AutomaticReconstruct,
85  py::call_guard<py::gil_scoped_release>(),
86  "Function for the automatic reconstruction", "workspace_path"_a,
87  "image_path"_a, "mask_path"_a = "", "vocab_tree_path"_a = "",
88  "data_type"_a = "individual", "quality"_a = "high",
89  "mesher"_a = "poisson", "camera_model"_a = "SIMPLE_RADIAL",
90  "single_camera"_a = false, "sparse"_a = true, "dense"_a = true,
91  "num_threads"_a = -1, "use_gpu"_a = true, "gpu_index"_a = "-1");
92  docstring::FunctionDocInject(m, "auto_reconstruction",
94 
95  m.def("bundle_adjustment", &BundleAdjustment,
96  py::call_guard<py::gil_scoped_release>(),
97  "Function for the bundle adjustment", "input_path"_a, "output_path"_a,
98  "bundle_adjustment_options"_a = colmap::BundleAdjustmentOptions());
99  docstring::FunctionDocInject(m, "bundle_adjustment",
101 
102  m.def("extract_color", &ExtractColor,
103  py::call_guard<py::gil_scoped_release>(),
104  "Function for the extraction of images color", "image_path"_a,
105  "input_path"_a, "output_path"_a);
106  docstring::FunctionDocInject(m, "extract_color",
108 
109  m.def("normal_mapper", &NormalMapper,
110  py::call_guard<py::gil_scoped_release>(),
111  "Function for the normal mapper", "database_path"_a, "image_path"_a,
112  "input_path"_a, "output_path"_a, "image_list_path"_a = "",
113  "incremental_mapper_options"_a = colmap::IncrementalMapperOptions());
114  docstring::FunctionDocInject(m, "normal_mapper",
116 
117  m.def("hierarchical_mapper", &HierarchicalMapper,
118  py::call_guard<py::gil_scoped_release>(),
119  "Function for the hierarchical mapper", "database_path"_a,
120  "image_path"_a, "output_path"_a, "num_workers"_a = -1,
121  "image_overlap"_a = 50, "leaf_max_num_images"_a = 500,
122  "incremental_mapper_options"_a = colmap::IncrementalMapperOptions());
123  docstring::FunctionDocInject(m, "hierarchical_mapper",
125 
126  m.def("filter_points", &FilterPoints,
127  py::call_guard<py::gil_scoped_release>(),
128  "Function for the filtering of points", "input_path"_a,
129  "output_path"_a, "min_track_len"_a = 2, "max_reproj_error"_a = 4.0,
130  "min_tri_angle"_a = 1.5);
131  docstring::FunctionDocInject(m, "filter_points",
133 
134  m.def("triangulate_points", &TriangulatePoints,
135  py::call_guard<py::gil_scoped_release>(),
136  "Function for the triangulation of points", "database_path"_a,
137  "image_path"_a, "input_path"_a, "output_path"_a,
138  "clear_points"_a = false,
139  "incremental_mapper_options"_a = colmap::IncrementalMapperOptions());
140  docstring::FunctionDocInject(m, "triangulate_points",
142 
143  m.def("rig_bundle_adjustment", &RigBundleAdjust,
144  py::call_guard<py::gil_scoped_release>(),
145  "Function for the rig bundle adjustment", "input_path"_a,
146  "output_path"_a, "rig_config_path"_a,
147  "estimate_rig_relative_poses"_a = true,
148  "refine_relative_poses"_a = true,
149  "bundle_adjustment_options"_a = colmap::BundleAdjustmentOptions());
150  docstring::FunctionDocInject(m, "rig_bundle_adjustment",
152 }
153 
154 void pybind_structure_from_motion(py::module &m) {
155  py::module m_submodule =
156  m.def_submodule("sfm", "Reconstruction structure from motion.");
157  pybind_sfm_methods(m_submodule);
158 }
159 
160 } // namespace sfm
161 } // namespace reconstruction
162 } // namespace cloudViewer
void FunctionDocInject(py::module &pybind_module, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
Definition: docstring.cpp:76
static const std::unordered_map< std::string, std::string > map_shared_argument_docstrings
Generic file read and write utility for python interface.
colmap::IncrementalMapperOptions IncrementalMapperOptions