Debian Codegraph @

src/pycolmap/sfm/observation_manager.cc

raw
1 #include "colmap/sfm/observation_manager.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
11 using namespace colmap;
12 using namespace pybind11::literals;
13 namespace py = pybind11;
14
15 void BindObservationManager(py::module& m) {
16 using ImagePairStat = ObservationManager::ImagePairStat;
17 py::classh_ext<ImagePairStat>(m, "ImagePairStat")
18 .def(py::init<>())
19 .def_readwrite("num_tri_corrs", &ImagePairStat::num_tri_corrs)
20 .def_readwrite("num_total_corrs", &ImagePairStat::num_total_corrs);
21
22 auto PyReprojectionErrorType =
23 py::enum_<ReprojectionErrorType>(m, "ReprojectionErrorType")
24 .value("PIXEL", ReprojectionErrorType::PIXEL)
25 .value("NORMALIZED", ReprojectionErrorType::NORMALIZED)
26 .value("ANGULAR", ReprojectionErrorType::ANGULAR);
27 AddStringToEnumConstructor(PyReprojectionErrorType);
28
29 py::classh<ObservationManager>(m, "ObservationManager")
30 .def(py::init<Reconstruction&,
31 std::shared_ptr<const CorrespondenceGraph>>(),
32 "reconstruction"_a,
33 "correspondence_graph"_a = py::none(),
34 py::keep_alive<1, 2>())
35 .def_property_readonly("image_pairs", &ObservationManager::ImagePairs)
36 .def("add_image",
37 &ObservationManager::AddImage,
38 "image_id"_a,
39 "Incrementally add an image for streaming/online SfM.")
40 .def("add_point3D",
41 &ObservationManager::AddPoint3D,
42 "xyz"_a,
43 "track"_a,
44 "color"_a = Eigen::Vector3ub::Zero(),
45 "Add new 3D object, and return its unique ID.")
46 .def("add_observation",
47 &ObservationManager::AddObservation,
48 "point3D_id"_a,
49 "track_element"_a,
50 "Add observation to existing 3D point.")
51 .def("delete_point3D",
52 &ObservationManager::DeletePoint3D,
53 "point3D_id"_a,
54 "Delete a 3D point, and all its references in the observed images.")
55 .def("delete_observation",
56 &ObservationManager::DeleteObservation,
57 "image_id"_a,
58 "point2D_idx"_a,
59 "Delete one observation from an image and the corresponding 3D "
60 "point. Note that this deletes the entire 3D point, if the track has"
61 " two elements prior to calling this method.")
62 .def(
63 "merge_points3D",
64 &ObservationManager::MergePoints3D,
65 "point3D_id1"_a,
66 "point3D_id2"_a,
67 "Merge two 3D points and return new identifier of new 3D point."
68 "The location of the merged 3D point is a weighted average of the "
69 "two original 3D point's locations according to their track lengths.")
70 .def("filter_points3D",
71 &ObservationManager::FilterPoints3D,
72 "max_reproj_error"_a,
73 "min_tri_angle"_a,
74 "point3D_ids"_a,
75 "Filter 3D points with large reprojection error, negative depth, or"
76 "insufficient triangulation angle. Return the number of filtered "
77 "observations.")
78 .def("filter_points3D_in_images",
79 &ObservationManager::FilterPoints3DInImages,
80 "max_reproj_error"_a,
81 "min_tri_angle"_a,
82 "image_ids"_a,
83 "Filter 3D points with large reprojection error, negative depth, or"
84 "insufficient triangulation angle. Return the number of filtered "
85 "observations.")
86 .def("filter_all_points3D",
87 &ObservationManager::FilterAllPoints3D,
88 "max_reproj_error"_a,
89 "min_tri_angle"_a,
90 "Filter 3D points with large reprojection error, negative depth, or"
91 "insufficient triangulation angle. Return the number of filtered "
92 "observations.")
93 .def("filter_points3D_with_short_tracks",
94 &ObservationManager::FilterPoints3DWithShortTracks,
95 "min_track_length"_a,
96 "Filter points with track length below threshold. Return the number "
97 "of filtered observations.")
98 .def("filter_observations_with_negative_depth",
99 &ObservationManager::FilterObservationsWithNegativeDepth,
100 "Filter observations that have negative depth. Return the number of "
101 "filtered observations.")
102 .def("filter_points3D_with_large_reprojection_error",
103 &ObservationManager::FilterPoints3DWithLargeReprojectionError,
104 "max_error"_a,
105 "point3D_ids"_a,
106 "error_type"_a = ReprojectionErrorType::PIXEL,
107 "Filter observations with large reprojection error. For PIXEL and "
108 "NORMALIZED, max_error is the reprojection error; for ANGULAR, it "
109 "is the angular error in degrees. Return the number of filtered "
110 "observations.")
111 .def("filter_points3D_with_small_triangulation_angle",
112 &ObservationManager::FilterPoints3DWithSmallTriangulationAngle,
113 "min_tri_angle"_a,
114 "point3D_ids"_a,
115 "Filter 3D points with insufficient triangulation angle in degrees. "
116 "Return the number of filtered observations.")
117 .def("filter_frames",
118 &ObservationManager::FindFramesToFilter,
119 "min_focal_length_ratio"_a,
120 "max_focal_length_ratio"_a,
121 "max_extra_param"_a,
122 "min_num_observations"_a,
123 "Find frames that should be filtered due to having no observations "
124 "or bogus camera parameters, without de-registering them. Pass them "
125 "to DeRegisterFrame to reset their pose."
126 "Return the identifiers of the frames to filter.")
127 .def("register_frame",
128 &ObservationManager::RegisterFrame,
129 "frame_id"_a,
130 "Register an existing frame, and all its references..")
131 .def("deregister_frame",
132 &ObservationManager::DeRegisterFrame,
133 "frame_id"_a,
134 "De-register an existing frame, and all its references.")
135 .def("num_observations",
136 &ObservationManager::NumObservations,
137 "image_id"_a,
138 "Number of observations, i.e. the number of image points that"
139 "have at least one correspondence to another image.")
140 .def("num_correspondences",
141 &ObservationManager::NumCorrespondences,
142 "image_id"_a,
143 "Number of correspondences for all image points.")
144 .def("num_visible_correspondences",
145 &ObservationManager::NumVisibleCorrespondences,
146 "image_id"_a,
147 "Number of visible correspondences for all image points.")
148 .def("num_visible_points3D",
149 &ObservationManager::NumVisiblePoints3D,
150 "image_id"_a,
151 "Get the number of observations that see a triangulated point, i.e. "
152 "the number of image points that have at least one correspondence to"
153 "a triangulated point in another image.")
154 .def("point3D_visibility_score",
155 &ObservationManager::Point3DVisibilityScore,
156 "image_id"_a,
157 "Get the score of triangulated observations. In contrast to"
158 "`NumVisiblePoints3D`, this score also captures the distribution"
159 "of triangulated observations in the image. This is useful to "
160 "select the next best image in incremental reconstruction, because a"
161 "more uniform distribution of observations results in more robust "
162 "registration.")
163 .def("increment_correspondence_has_point3D",
164 &ObservationManager::IncrementCorrespondenceHasPoint3D,
165 "image_id"_a,
166 "point2D_idx"_a,
167 "Indicate that another image has a point that is triangulated and "
168 "has a correspondence to this image point.")
169 .def("decrement_correspondence_has_point3D",
170 &ObservationManager::DecrementCorrespondenceHasPoint3D,
171 "image_id"_a,
172 "point2D_idx"_a,
173 "Indicate that another image has a point that is not triangulated "
174 "any more and has a correspondence to this image point. This assumes"
175 "that `IncrementCorrespondenceHasPoint3D` was called for the same"
176 "image point and correspondence before.")
177 .def("__repr__", &CreateRepresentation<ObservationManager>);
178 }