| 1 |
#include "colmap/sfm/global_mapper.h" |
| 2 |
|
| 3 |
#include "colmap/controllers/global_pipeline.h" |
| 4 |
#include "colmap/scene/database.h" |
| 5 |
#include "colmap/scene/reconstruction_manager.h" |
| 6 |
|
| 7 |
#include "pycolmap/helpers.h" |
| 8 |
#include "pycolmap/pybind11_extension.h" |
| 9 |
|
| 10 |
#include <memory> |
| 11 |
|
| 12 |
#include <pybind11/functional.h> |
| 13 |
#include <pybind11/pybind11.h> |
| 14 |
#include <pybind11/stl.h> |
| 15 |
|
| 16 |
using namespace colmap; |
| 17 |
using namespace pybind11::literals; |
| 18 |
namespace py = pybind11; |
| 19 |
|
| 20 |
void BindGlobalMapper(py::module& m) { |
| 21 |
{ |
| 22 |
using Opts = GlobalMapperOptions; |
| 23 |
auto PyOpts = py::classh<Opts>(m, "GlobalMapperOptions"); |
| 24 |
PyOpts.def(py::init<>()) |
| 25 |
.def_readwrite("num_threads", &Opts::num_threads) |
| 26 |
.def_readwrite("random_seed", &Opts::random_seed) |
| 27 |
.def_readwrite( |
| 28 |
"image_path", |
| 29 |
&Opts::image_path, |
| 30 |
"The image path at which to find the images to extract point " |
| 31 |
"colors.") |
| 32 |
.def_readwrite("refine_sensor_from_rig", |
| 33 |
&Opts::refine_sensor_from_rig, |
| 34 |
"When False, treat each non-ref sensor's " |
| 35 |
"cam_from_rig as a pre-calibrated constant across " |
| 36 |
"rotation averaging, global positioning and " |
| 37 |
"bundle adjustment.") |
| 38 |
.def_readwrite("rotation_averaging", &Opts::rotation_averaging) |
| 39 |
.def_readwrite("global_positioning", &Opts::global_positioning) |
| 40 |
.def_readwrite("bundle_adjustment", &Opts::bundle_adjustment) |
| 41 |
.def_readwrite("retriangulation", &Opts::retriangulation) |
| 42 |
.def_readwrite("track_intra_image_consistency_threshold", |
| 43 |
&Opts::track_intra_image_consistency_threshold) |
| 44 |
.def_readwrite("track_required_tracks_per_view", |
| 45 |
&Opts::track_required_tracks_per_view) |
| 46 |
.def_readwrite("track_min_num_views_per_track", |
| 47 |
&Opts::track_min_num_views_per_track) |
| 48 |
.def_readwrite("keep_max_num_tracks", &Opts::keep_max_num_tracks) |
| 49 |
.def_readwrite("max_angular_reproj_error_deg", |
| 50 |
&Opts::max_angular_reproj_error_deg) |
| 51 |
.def_readwrite("max_normalized_reproj_error", |
| 52 |
&Opts::max_normalized_reproj_error) |
| 53 |
.def_readwrite("min_tri_angle_deg", &Opts::min_tri_angle_deg) |
| 54 |
.def_readwrite("ba_gpu_index", &Opts::ba_gpu_index) |
| 55 |
.def_readwrite("ba_num_iterations", &Opts::ba_num_iterations) |
| 56 |
.def_readwrite("ba_skip_fixed_rotation_stage", |
| 57 |
&Opts::ba_skip_fixed_rotation_stage) |
| 58 |
.def_readwrite("ba_skip_joint_optimization_stage", |
| 59 |
&Opts::ba_skip_joint_optimization_stage) |
| 60 |
.def_readwrite("skip_rotation_averaging", |
| 61 |
&Opts::skip_rotation_averaging) |
| 62 |
.def_readwrite("skip_track_establishment", |
| 63 |
&Opts::skip_track_establishment) |
| 64 |
.def_readwrite("skip_global_positioning", |
| 65 |
&Opts::skip_global_positioning) |
| 66 |
.def_readwrite("skip_bundle_adjustment", &Opts::skip_bundle_adjustment) |
| 67 |
.def_readwrite("skip_retriangulation", &Opts::skip_retriangulation) |
| 68 |
.def("get_rotation_averaging", |
| 69 |
&Opts::RotationAveraging, |
| 70 |
"Get rotation averaging options with shared settings applied.") |
| 71 |
.def("get_global_positioning", |
| 72 |
&Opts::GlobalPositioning, |
| 73 |
"Get global positioning options with shared settings applied.") |
| 74 |
.def("get_bundle_adjustment", |
| 75 |
&Opts::BundleAdjustment, |
| 76 |
"Get bundle adjustment options with shared settings applied.") |
| 77 |
.def("get_retriangulation", |
| 78 |
&Opts::Retriangulation, |
| 79 |
"Get retriangulation options with shared settings applied."); |
| 80 |
MakeDataclass(PyOpts); |
| 81 |
} |
| 82 |
|
| 83 |
{ |
| 84 |
using Opts = GlobalPipelineOptions; |
| 85 |
auto PyOpts = py::classh<Opts>(m, "GlobalPipelineOptions"); |
| 86 |
PyOpts.def(py::init<>()) |
| 87 |
.def_readwrite("min_num_matches", &Opts::min_num_matches) |
| 88 |
.def_readwrite("ignore_watermarks", &Opts::ignore_watermarks) |
| 89 |
.def_readwrite("image_names", &Opts::image_names) |
| 90 |
.def_readwrite( |
| 91 |
"image_path", |
| 92 |
&Opts::image_path, |
| 93 |
"The image path at which to find the images to extract point " |
| 94 |
"colors.") |
| 95 |
.def_readwrite("num_threads", &Opts::num_threads) |
| 96 |
.def_readwrite("random_seed", &Opts::random_seed) |
| 97 |
.def_readwrite("decompose_relative_pose", |
| 98 |
&Opts::decompose_relative_pose) |
| 99 |
.def_readwrite("multiple_models", &Opts::multiple_models) |
| 100 |
.def_readwrite("min_model_size", &Opts::min_model_size) |
| 101 |
.def_readwrite("mapper", &Opts::mapper); |
| 102 |
MakeDataclass(PyOpts); |
| 103 |
} |
| 104 |
|
| 105 |
using CallbackType = GlobalPipeline::CallbackType; |
| 106 |
auto PyCallbackType = |
| 107 |
py::enum_<CallbackType>(m, "GlobalPipelineCallback") |
| 108 |
.value("MODEL_UPDATE_CALLBACK", CallbackType::MODEL_UPDATE_CALLBACK); |
| 109 |
AddStringToEnumConstructor(PyCallbackType); |
| 110 |
|
| 111 |
py::classh<GlobalPipeline>( |
| 112 |
m, |
| 113 |
"GlobalPipeline", |
| 114 |
"Class that controls the global mapping procedure (GLOMAP) by jointly " |
| 115 |
"estimating all camera poses from the view graph using rotation " |
| 116 |
"averaging and global positioning, followed by bundle adjustment and " |
| 117 |
"retriangulation.") |
| 118 |
.def(py::init<GlobalPipelineOptions, |
| 119 |
std::shared_ptr<Database>, |
| 120 |
std::shared_ptr<ReconstructionManager>>(), |
| 121 |
"options"_a, |
| 122 |
"database"_a, |
| 123 |
"reconstruction_manager"_a, |
| 124 |
py::call_guard<py::gil_scoped_release>()) |
| 125 |
.def("add_callback", |
| 126 |
&GlobalPipeline::AddCallback, |
| 127 |
"id"_a, |
| 128 |
"func"_a, |
| 129 |
"Add a callback function for the given callback type.") |
| 130 |
.def("callback", |
| 131 |
&GlobalPipeline::Callback, |
| 132 |
"id"_a, |
| 133 |
"Invoke the callback for the given callback type.") |
| 134 |
.def("run", |
| 135 |
&GlobalPipeline::Run, |
| 136 |
py::call_guard<py::gil_scoped_release>(), |
| 137 |
"Run the full global mapping pipeline."); |
| 138 |
} |