| 1 |
#include "colmap/sfm/incremental_triangulator.h" |
| 2 |
|
| 3 |
#include "pycolmap/helpers.h" |
| 4 |
#include "pycolmap/pybind11_extension.h" |
| 5 |
|
| 6 |
#include <memory> |
| 7 |
|
| 8 |
#include <pybind11/eigen.h> |
| 9 |
#include <pybind11/pybind11.h> |
| 10 |
#include <pybind11/stl.h> |
| 11 |
#include <pybind11/stl_bind.h> |
| 12 |
|
| 13 |
using namespace colmap; |
| 14 |
using namespace pybind11::literals; |
| 15 |
namespace py = pybind11; |
| 16 |
|
| 17 |
void BindIncrementalTriangulator(py::module& m) { |
| 18 |
using Opts = IncrementalTriangulator::Options; |
| 19 |
auto PyOpts = py::classh<Opts>(m, "IncrementalTriangulatorOptions"); |
| 20 |
PyOpts.def(py::init<>()) |
| 21 |
.def_readwrite("max_transitivity", |
| 22 |
&Opts::max_transitivity, |
| 23 |
"Maximum transitivity to search for correspondences.") |
| 24 |
.def_readwrite("create_max_angle_error", |
| 25 |
&Opts::create_max_angle_error, |
| 26 |
"Maximum angular error to create new triangulations.") |
| 27 |
.def_readwrite( |
| 28 |
"continue_max_angle_error", |
| 29 |
&Opts::continue_max_angle_error, |
| 30 |
"Maximum angular error to continue existing triangulations.") |
| 31 |
.def_readwrite( |
| 32 |
"merge_max_reproj_error", |
| 33 |
&Opts::merge_max_reproj_error, |
| 34 |
"Maximum reprojection error in pixels to merge triangulations.") |
| 35 |
.def_readwrite( |
| 36 |
"complete_max_reproj_error", |
| 37 |
&Opts::complete_max_reproj_error, |
| 38 |
"Maximum reprojection error to complete an existing triangulation.") |
| 39 |
.def_readwrite("complete_max_transitivity", |
| 40 |
&Opts::complete_max_transitivity, |
| 41 |
"Maximum transitivity for track completion.") |
| 42 |
.def_readwrite("re_max_angle_error", |
| 43 |
&Opts::re_max_angle_error, |
| 44 |
"Maximum angular error to re-triangulate " |
| 45 |
"under-reconstructed image pairs.") |
| 46 |
.def_readwrite("re_min_ratio", |
| 47 |
&Opts::re_min_ratio, |
| 48 |
"Minimum ratio of common triangulations between an image " |
| 49 |
"pair over the number of correspondences between that " |
| 50 |
"image pair to be considered as under-reconstructed.") |
| 51 |
.def_readwrite( |
| 52 |
"re_max_trials", |
| 53 |
&Opts::re_max_trials, |
| 54 |
"Maximum number of trials to re-triangulate an image pair.") |
| 55 |
.def_readwrite( |
| 56 |
"min_angle", |
| 57 |
&Opts::min_angle, |
| 58 |
"Minimum pairwise triangulation angle for a stable triangulation.") |
| 59 |
.def_readwrite("ignore_two_view_tracks", |
| 60 |
&Opts::ignore_two_view_tracks, |
| 61 |
"Whether to ignore two-view tracks.") |
| 62 |
.def_readwrite("min_focal_length_ratio", |
| 63 |
&Opts::min_focal_length_ratio, |
| 64 |
"The threshold used to filter and ignore images with " |
| 65 |
"degenerate intrinsics.") |
| 66 |
.def_readwrite("max_focal_length_ratio", |
| 67 |
&Opts::max_focal_length_ratio, |
| 68 |
"The threshold used to filter and ignore images with " |
| 69 |
"degenerate intrinsics.") |
| 70 |
.def_readwrite("max_extra_param", |
| 71 |
&Opts::max_extra_param, |
| 72 |
"The threshold used to filter and ignore images with " |
| 73 |
"degenerate intrinsics.") |
| 74 |
.def_readwrite( |
| 75 |
"random_seed", |
| 76 |
&Opts::random_seed, |
| 77 |
"PRNG seed for all stochastic methods during triangulation.") |
| 78 |
.def("check", &Opts::Check); |
| 79 |
MakeDataclass(PyOpts); |
| 80 |
|
| 81 |
py::classh<IncrementalTriangulator>( |
| 82 |
m, |
| 83 |
"IncrementalTriangulator", |
| 84 |
"Class that triangulates points during the incremental reconstruction. " |
| 85 |
"It holds the state and provides all functionality for triangulation.") |
| 86 |
.def(py::init<std::shared_ptr<const CorrespondenceGraph>, |
| 87 |
Reconstruction&, |
| 88 |
std::shared_ptr<ObservationManager>>(), |
| 89 |
"correspondence_graph"_a, |
| 90 |
"reconstruction"_a, |
| 91 |
"observation_manager"_a = py::none(), |
| 92 |
py::keep_alive<1, 3>(), |
| 93 |
"Create new incremental triangulator. Note that both the " |
| 94 |
"correspondence graph and the reconstruction objects must live " |
| 95 |
"as long as the triangulator.") |
| 96 |
.def("triangulate_image", |
| 97 |
&IncrementalTriangulator::TriangulateImage, |
| 98 |
"options"_a, |
| 99 |
"image_id"_a, |
| 100 |
"Triangulate observations of image. Triangulation includes " |
| 101 |
"creation of new points, continuation of existing points, and " |
| 102 |
"merging of separate points if given image bridges tracks. Note " |
| 103 |
"that the given image must be registered and its pose must be set " |
| 104 |
"in the associated reconstruction.") |
| 105 |
.def("complete_image", |
| 106 |
&IncrementalTriangulator::CompleteImage, |
| 107 |
"options"_a, |
| 108 |
"image_id"_a, |
| 109 |
"Complete triangulations for image. Tries to create new tracks " |
| 110 |
"for not yet triangulated observations and tries to complete " |
| 111 |
"existing tracks. Returns the number of completed observations.") |
| 112 |
.def("complete_all_tracks", |
| 113 |
&IncrementalTriangulator::CompleteAllTracks, |
| 114 |
"options"_a, |
| 115 |
"Complete tracks of all 3D points. Returns the number of " |
| 116 |
"completed observations.") |
| 117 |
.def("merge_all_tracks", |
| 118 |
&IncrementalTriangulator::MergeAllTracks, |
| 119 |
"options"_a, |
| 120 |
"Merge tracks of all 3D points. Returns the number of merged " |
| 121 |
"observations.") |
| 122 |
.def("retriangulate", |
| 123 |
&IncrementalTriangulator::Retriangulate, |
| 124 |
"options"_a, |
| 125 |
"Perform retriangulation for under-reconstructed image pairs. " |
| 126 |
"Under-reconstruction usually occurs in the case of a drifting " |
| 127 |
"reconstruction.") |
| 128 |
.def("add_modified_point3D", |
| 129 |
&IncrementalTriangulator::AddModifiedPoint3D, |
| 130 |
"point3D_id"_a, |
| 131 |
"Indicate that a 3D point has been modified.") |
| 132 |
.def("clear_modified_points3D", |
| 133 |
&IncrementalTriangulator::ClearModifiedPoints3D, |
| 134 |
"Clear the collection of changed 3D points.") |
| 135 |
.def("get_modified_points3D", |
| 136 |
&IncrementalTriangulator::GetModifiedPoints3D, |
| 137 |
"Get changed 3D points, since the last call to " |
| 138 |
"clear_modified_points3D.") |
| 139 |
.def("merge_tracks", |
| 140 |
&IncrementalTriangulator::MergeTracks, |
| 141 |
"options"_a, |
| 142 |
"point3D_ids"_a, |
| 143 |
"Merge tracks for specific 3D points. Returns the number of " |
| 144 |
"merged observations.") |
| 145 |
.def("complete_tracks", |
| 146 |
&IncrementalTriangulator::CompleteTracks, |
| 147 |
"options"_a, |
| 148 |
"point3D_ids"_a, |
| 149 |
"Complete tracks for specific 3D points. Completion tries to " |
| 150 |
"recursively add observations to a track that might have failed " |
| 151 |
"to triangulate before due to inaccurate poses, etc. Returns " |
| 152 |
"the number of completed observations.") |
| 153 |
.def("__copy__", |
| 154 |
[](const IncrementalTriangulator& self) { |
| 155 |
return IncrementalTriangulator(self); |
| 156 |
}) |
| 157 |
.def("__deepcopy__", |
| 158 |
[](const IncrementalTriangulator& self, const py::dict&) { |
| 159 |
return IncrementalTriangulator(self); |
| 160 |
}) |
| 161 |
.def("__repr__", &CreateRepresentation<IncrementalTriangulator>); |
| 162 |
} |