| 1 |
#include "colmap/controllers/hierarchical_pipeline.h" |
| 2 |
#include "colmap/scene/database.h" |
| 3 |
#include "colmap/scene/reconstruction_manager.h" |
| 4 |
#include "colmap/scene/scene_clustering.h" |
| 5 |
|
| 6 |
#include "pycolmap/helpers.h" |
| 7 |
#include "pycolmap/pybind11_extension.h" |
| 8 |
|
| 9 |
#include <memory> |
| 10 |
|
| 11 |
#include <pybind11/pybind11.h> |
| 12 |
#include <pybind11/stl.h> |
| 13 |
|
| 14 |
using namespace colmap; |
| 15 |
using namespace pybind11::literals; |
| 16 |
namespace py = pybind11; |
| 17 |
|
| 18 |
void BindHierarchicalMapper(py::module& m) { |
| 19 |
{ |
| 20 |
using Opts = SceneClustering::Options; |
| 21 |
auto PyOpts = py::classh<Opts>(m, "SceneClusteringOptions"); |
| 22 |
PyOpts.def(py::init<>()) |
| 23 |
.def_readwrite("is_hierarchical", |
| 24 |
&Opts::is_hierarchical, |
| 25 |
"Flag for hierarchical vs. flat clustering.") |
| 26 |
.def_readwrite("branching", |
| 27 |
&Opts::branching, |
| 28 |
"The branching factor of the hierarchical clustering.") |
| 29 |
.def_readwrite( |
| 30 |
"image_overlap", |
| 31 |
&Opts::image_overlap, |
| 32 |
"The number of overlapping images between child clusters.") |
| 33 |
.def_readwrite( |
| 34 |
"num_image_matches", |
| 35 |
&Opts::num_image_matches, |
| 36 |
"The max related images matches to look for in a flat cluster.") |
| 37 |
.def_readwrite( |
| 38 |
"leaf_max_num_images", |
| 39 |
&Opts::leaf_max_num_images, |
| 40 |
"The maximum number of images in a leaf node cluster, otherwise " |
| 41 |
"the cluster is further partitioned using the given branching " |
| 42 |
"factor. Note that a cluster leaf node will have at most " |
| 43 |
"`leaf_max_num_images + image_overlap` images to satisfy the " |
| 44 |
"overlap constraint.") |
| 45 |
.def("check", &Opts::Check); |
| 46 |
MakeDataclass(PyOpts); |
| 47 |
} |
| 48 |
|
| 49 |
{ |
| 50 |
using Opts = HierarchicalPipelineOptions; |
| 51 |
auto PyOpts = py::classh<Opts>(m, "HierarchicalPipelineOptions"); |
| 52 |
PyOpts.def(py::init<>()) |
| 53 |
.def_readwrite( |
| 54 |
"image_path", |
| 55 |
&Opts::image_path, |
| 56 |
"The image path at which to find the images to extract point " |
| 57 |
"colors. If not specified, all point colors will be black.") |
| 58 |
.def_readwrite("init_num_trials", |
| 59 |
&Opts::init_num_trials, |
| 60 |
"The maximum number of trials to initialize a cluster.") |
| 61 |
.def_readwrite( |
| 62 |
"num_threads", |
| 63 |
&Opts::num_threads, |
| 64 |
"The total number of threads for the hierarchical pipeline. This " |
| 65 |
"budget is divided across workers to avoid thread " |
| 66 |
"oversubscription. Note that incremental_options.num_threads is " |
| 67 |
"ignored in favor of this option.") |
| 68 |
.def_readwrite( |
| 69 |
"num_workers", |
| 70 |
&Opts::num_workers, |
| 71 |
"The number of workers used to reconstruct clusters in parallel.") |
| 72 |
.def_readwrite("clustering_options", |
| 73 |
&Opts::clustering_options, |
| 74 |
"Options for clustering the scene graph.") |
| 75 |
.def_readwrite("incremental_options", |
| 76 |
&Opts::incremental_options, |
| 77 |
"Options used to reconstruct each cluster individually.") |
| 78 |
.def("check", &Opts::Check); |
| 79 |
MakeDataclass(PyOpts); |
| 80 |
} |
| 81 |
|
| 82 |
py::classh<HierarchicalPipeline>( |
| 83 |
m, |
| 84 |
"HierarchicalPipeline", |
| 85 |
"Class that controls the hierarchical mapping procedure by first " |
| 86 |
"partitioning the scene into multiple overlapping clusters, then " |
| 87 |
"reconstructing them separately using incremental mapping, and finally " |
| 88 |
"merging them all into a globally consistent reconstruction. This is " |
| 89 |
"especially useful for larger-scale scenes, since incremental mapping " |
| 90 |
"becomes slow with an increasing number of images.") |
| 91 |
.def(py::init<const HierarchicalPipelineOptions&, |
| 92 |
std::shared_ptr<Database>, |
| 93 |
std::shared_ptr<ReconstructionManager>>(), |
| 94 |
"options"_a, |
| 95 |
"database"_a, |
| 96 |
"reconstruction_manager"_a, |
| 97 |
py::call_guard<py::gil_scoped_release>()) |
| 98 |
.def("run", |
| 99 |
&HierarchicalPipeline::Run, |
| 100 |
py::call_guard<py::gil_scoped_release>(), |
| 101 |
"Run the full hierarchical mapping pipeline."); |
| 102 |
} |