Debian Codegraph @

src/pycolmap/estimators/alignment.cc

raw
1 #include "colmap/estimators/alignment.h"
2
3 #include "colmap/exe/model.h"
4 #include "colmap/geometry/sim3.h"
5 #include "colmap/optim/ransac.h"
6 #include "colmap/scene/reconstruction.h"
7 #include "colmap/util/logging.h"
8
9 #include "pycolmap/pybind11_extension.h"
10 #include "pycolmap/scene/types.h"
11
12 #include <pybind11/eigen.h>
13 #include <pybind11/pybind11.h>
14 #include <pybind11/stl.h>
15 #include <pybind11/stl_bind.h>
16
17 using namespace colmap;
18 using namespace pybind11::literals;
19 namespace py = pybind11;
20
21 void BindAlignmentEstimator(py::module& m) {
22 py::classh<ImageAlignmentError>(m, "ImageAlignmentError")
23 .def(py::init<>())
24 .def_readwrite("image_name", &ImageAlignmentError::image_name)
25 .def_readwrite("rotation_error_deg",
26 &ImageAlignmentError::rotation_error_deg)
27 .def_readwrite("proj_center_error",
28 &ImageAlignmentError::proj_center_error);
29
30 m.def(
31 "align_reconstructions_via_reprojections",
32 [](const Reconstruction& src_reconstruction,
33 const Reconstruction& tgt_reconstruction,
34 const double min_inlier_observations,
35 const double max_reproj_error) -> py::typing::Optional<Sim3d> {
36 Sim3d tgt_from_src;
37 if (!AlignReconstructionsViaReprojections(src_reconstruction,
38 tgt_reconstruction,
39 min_inlier_observations,
40 max_reproj_error,
41 &tgt_from_src)) {
42 return py::none();
43 }
44 return py::cast(tgt_from_src);
45 },
46 "src_reconstruction"_a,
47 "tgt_reconstruction"_a,
48 "min_inlier_observations"_a = 0.3,
49 "max_reproj_error"_a = 8.0);
50
51 m.def(
52 "align_reconstructions_via_proj_centers",
53 [](const Reconstruction& src_reconstruction,
54 const Reconstruction& tgt_reconstruction,
55 const double max_proj_center_error) -> py::typing::Optional<Sim3d> {
56 Sim3d tgt_from_src;
57 if (!AlignReconstructionsViaProjCenters(src_reconstruction,
58 tgt_reconstruction,
59 max_proj_center_error,
60 &tgt_from_src)) {
61 return py::none();
62 }
63 return py::cast(tgt_from_src);
64 },
65 "src_reconstruction"_a,
66 "tgt_reconstruction"_a,
67 "max_proj_center_error"_a);
68
69 m.def(
70 "align_reconstructions_via_points",
71 [](const Reconstruction& src_reconstruction,
72 const Reconstruction& tgt_reconstruction,
73 const size_t min_common_observations,
74 const double max_error,
75 const double min_inlier_ratio) -> py::typing::Optional<Sim3d> {
76 Sim3d tgt_from_src;
77 if (!AlignReconstructionsViaPoints(src_reconstruction,
78 tgt_reconstruction,
79 min_common_observations,
80 max_error,
81 min_inlier_ratio,
82 &tgt_from_src)) {
83 return py::none();
84 }
85 return py::cast(tgt_from_src);
86 },
87 "src_reconstruction"_a,
88 "tgt_reconstruction"_a,
89 "min_common_observations"_a = 3,
90 "max_error"_a = 0.005,
91 "min_inlier_ratio"_a = 0.9);
92
93 m.def(
94 "align_reconstruction_to_locations",
95 [](const Reconstruction& src,
96 const std::vector<std::string>& tgt_image_names,
97 const std::vector<Eigen::Vector3d>& tgt_locations,
98 const int min_common_images,
99 const RANSACOptions& ransac_options) -> py::typing::Optional<Sim3d> {
100 Sim3d locations_from_src;
101 if (!AlignReconstructionToLocations(src,
102 tgt_image_names,
103 tgt_locations,
104 min_common_images,
105 ransac_options,
106 &locations_from_src)) {
107 return py::none();
108 }
109 return py::cast(locations_from_src);
110 },
111 "src"_a,
112 "tgt_image_names"_a,
113 "tgt_locations"_a,
114 "min_common_images"_a,
115 "ransac_options"_a);
116
117 m.def(
118 "compare_reconstructions",
119 [](const Reconstruction& reconstruction1,
120 const Reconstruction& reconstruction2,
121 const std::string& alignment_error,
122 double min_inlier_observations,
123 double max_reproj_error,
124 double max_proj_center_error) -> py::typing::Optional<py::dict> {
125 std::vector<ImageAlignmentError> errors;
126 Sim3d rec2_from_rec1;
127 if (!CompareModels(reconstruction1,
128 reconstruction2,
129 alignment_error,
130 min_inlier_observations,
131 max_reproj_error,
132 max_proj_center_error,
133 errors,
134 rec2_from_rec1)) {
135 return py::none();
136 }
137 return py::dict("rec2_from_rec1"_a = rec2_from_rec1,
138 "errors"_a = errors);
139 },
140 "reconstruction1"_a,
141 "reconstruction2"_a,
142 "alignment_error"_a = "reprojection",
143 "min_inlier_observations"_a = 0.3,
144 "max_reproj_error"_a = 8.0,
145 "max_proj_center_error"_a = 0.1);
146
147 m.def("align_reconstruction_to_orig_rig_scales",
148 &AlignReconstructionToOrigRigScales,
149 "orig_rigs"_a,
150 "reconstruction"_a);
151 }