Debian Codegraph @

src/pycolmap/estimators/cost_functions.cc

raw
1 #include "colmap/estimators/cost_functions/alignment.h"
2 #include "colmap/estimators/cost_functions/pose_prior.h"
3 #include "colmap/estimators/cost_functions/reprojection_error.h"
4 #include "colmap/estimators/cost_functions/sampson_error.h"
5 #include "colmap/estimators/cost_functions/utils.h"
6 #include "colmap/geometry/rigid3.h"
7
8 #include "pycolmap/helpers.h"
9
10 #include <pybind11/eigen.h>
11 #include <pybind11/pybind11.h>
12
13 using namespace colmap;
14 using namespace pybind11::literals;
15 namespace py = pybind11;
16
17 template <typename CameraModel>
18 using CovarianceWeightedReprojErrorCostFunctor =
19 CovarianceWeightedCostFunctor<ReprojErrorCostFunctor<CameraModel>>;
20
21 template <typename CameraModel>
22 using CovarianceWeightedReprojErrorConstantPoseCostFunctor =
23 CovarianceWeightedCostFunctor<
24 ReprojErrorConstantPoseCostFunctor<CameraModel>>;
25
26 template <typename CameraModel>
27 using CovarianceWeightedReprojErrorConstantPoint3DCostFunctor =
28 CovarianceWeightedCostFunctor<
29 ReprojErrorConstantPoint3DCostFunctor<CameraModel>>;
30
31 template <typename CameraModel>
32 using CovarianceWeightedRigReprojErrorCostFunctor =
33 CovarianceWeightedCostFunctor<RigReprojErrorCostFunctor<CameraModel>>;
34
35 template <typename CameraModel>
36 using CovarianceWeightedRigReprojErrorConstantRigCostFunctor =
37 CovarianceWeightedCostFunctor<
38 RigReprojErrorConstantRigCostFunctor<CameraModel>>;
39
40 void BindCostFunctions(py::module& m_parent) {
41 py::module_ m = m_parent.def_submodule("cost_functions");
42 IsPyceresAvailable(); // Try to import pyceres to populate the docstrings.
43
44 m.def(
45 "ReprojErrorCost",
46 &CreateCameraCostFunction<ReprojErrorCostFunctor, const Eigen::Vector2d&>,
47 "camera_model_id"_a,
48 "point2D"_a,
49 "Reprojection error.");
50 m.def("ReprojErrorCost",
51 &CreateCameraCostFunction<CovarianceWeightedReprojErrorCostFunctor,
52 const Eigen::Matrix2d&,
53 const Eigen::Vector2d&>,
54 "camera_model_id"_a,
55 "point2D_cov"_a,
56 "point2D"_a,
57 "Reprojection error with 2D detection noise.");
58
59 m.def("ReprojErrorCost",
60 &CreateCameraCostFunction<ReprojErrorConstantPoseCostFunctor,
61 const Eigen::Vector2d&,
62 const Rigid3d&>,
63 "camera_model_id"_a,
64 "point2D"_a,
65 "cam_from_world"_a,
66 "Reprojection error with constant camera pose.");
67 m.def("ReprojErrorCost",
68 &CreateCameraCostFunction<
69 CovarianceWeightedReprojErrorConstantPoseCostFunctor,
70 const Eigen::Matrix2d&,
71 const Eigen::Vector2d&,
72 const Rigid3d&>,
73 "camera_model_id"_a,
74 "point2D_cov"_a,
75 "point2D"_a,
76 "cam_from_world"_a,
77 "Reprojection error with constant camera pose and 2D detection noise.");
78
79 m.def("ReprojErrorCost",
80 &CreateCameraCostFunction<ReprojErrorConstantPoint3DCostFunctor,
81 const Eigen::Vector2d&,
82 const Eigen::Vector3d&>,
83 "camera_model_id"_a,
84 "point2D"_a,
85 "point3D"_a,
86 "Reprojection error with constant 3D point.");
87 m.def("ReprojErrorCost",
88 &CreateCameraCostFunction<
89 CovarianceWeightedReprojErrorConstantPoint3DCostFunctor,
90 const Eigen::Matrix2d&,
91 const Eigen::Vector2d&,
92 const Eigen::Vector3d&>,
93 "camera_model_id"_a,
94 "point2D_cov"_a,
95 "point2D"_a,
96 "point3D"_a,
97 "Reprojection error with constant 3D point and 2D detection noise.");
98
99 m.def("RigReprojErrorCost",
100 &CreateCameraCostFunction<RigReprojErrorCostFunctor,
101 const Eigen::Vector2d&>,
102 "camera_model_id"_a,
103 "point2D"_a,
104 "Reprojection error for camera rig.");
105 m.def("RigReprojErrorCost",
106 &CreateCameraCostFunction<CovarianceWeightedRigReprojErrorCostFunctor,
107 const Eigen::Matrix2d&,
108 const Eigen::Vector2d&>,
109 "camera_model_id"_a,
110 "point2D_cov"_a,
111 "point2D"_a,
112 "Reprojection error for camera rig with 2D detection noise.");
113
114 m.def("RigReprojErrorCost",
115 &CreateCameraCostFunction<RigReprojErrorConstantRigCostFunctor,
116 const Eigen::Vector2d&,
117 const Rigid3d&>,
118 "camera_model_id"_a,
119 "point2D"_a,
120 "cam_from_rig"_a,
121 "Reprojection error for camera rig with constant cam-from-rig pose.");
122 m.def("RigReprojErrorCost",
123 &CreateCameraCostFunction<
124 CovarianceWeightedRigReprojErrorConstantRigCostFunctor,
125 const Eigen::Matrix2d&,
126 const Eigen::Vector2d&,
127 const Rigid3d&>,
128 "camera_model_id"_a,
129 "point2D_cov"_a,
130 "point2D"_a,
131 "cam_from_rig"_a,
132 "Reprojection error for camera rig with constant cam-from-rig pose and "
133 "2D detection noise.");
134
135 m.def("SampsonErrorCost",
136 &SampsonErrorCostFunctor::Create<const Eigen::Vector2d&,
137 const Eigen::Vector2d&>,
138 "point1"_a,
139 "point2"_a,
140 "Sampson error for two-view geometry on image-plane points.");
141
142 m.def("AbsolutePosePriorCost",
143 &AbsolutePosePriorCostFunctor::Create<const Rigid3d&>,
144 "cam_from_world_prior"_a,
145 "6-DoF error on the absolute camera pose.");
146 m.def("AbsolutePosePriorCost",
147 &CovarianceWeightedCostFunctor<AbsolutePosePriorCostFunctor>::Create<
148 const Rigid3d&>,
149 "cam_cov_from_world_prior"_a,
150 "cam_from_world_prior"_a,
151 "6-DoF error on the absolute camera pose with prior covariance.");
152
153 m.def("AbsolutePosePositionPriorCost",
154 &AbsolutePosePositionPriorCostFunctor::Create<const Eigen::Vector3d&>,
155 "position_in_world_prior"_a,
156 "3-DoF error on the absolute camera pose's position.");
157 m.def(
158 "AbsolutePosePositionPriorCost",
159 &CovarianceWeightedCostFunctor<
160 AbsolutePosePositionPriorCostFunctor>::Create<const Eigen::Vector3d&>,
161 "position_cov_in_world_prior"_a,
162 "position_in_world_prior"_a,
163 "3-DoF error on the absolute camera pose's position with prior "
164 "covariance.");
165
166 m.def("RelativePosePriorCost",
167 &RelativePosePriorCostFunctor::Create<const Rigid3d&>,
168 "i_from_j_prior"_a,
169 "6-DoF error between two absolute camera poses based on a prior "
170 "relative pose.");
171 m.def("RelativePosePriorCost",
172 &CovarianceWeightedCostFunctor<RelativePosePriorCostFunctor>::Create<
173 const Rigid3d&>,
174 "i_cov_from_j_prior"_a,
175 "i_from_j_prior"_a,
176 "6-DoF error between two absolute camera poses based on a prior "
177 "relative pose with prior covariance.");
178
179 m.def("Point3DAlignmentCost",
180 &Point3DAlignmentCostFunctor::Create<const Eigen::Vector3d&, bool>,
181 "point_in_b_prior"_a,
182 "use_log_scale"_a = true,
183 "Error between 3D points transformed by a 3D similarity transform.");
184 m.def("Point3DAlignmentCost",
185 &CovarianceWeightedCostFunctor<
186 Point3DAlignmentCostFunctor>::Create<const Eigen::Vector3d&, bool>,
187 "point_cov_in_b_prior"_a,
188 "point_in_b_prior"_a,
189 "use_log_scale"_a = true,
190 "Error between 3D points transformed by a 3D similarity transform. "
191 "with prior covariance");
192 }