Debian Codegraph @

src/pycolmap/estimators/bundle_adjustment_test.py

raw
1 import pycolmap
2
3
4 def test_bundle_adjustment_termination_type_enum():
5 assert {
6 k: int(v)
7 for k, v in pycolmap.BundleAdjustmentTerminationType.__members__.items()
8 } == {
9 "CONVERGENCE": 0,
10 "NO_CONVERGENCE": 1,
11 "FAILURE": 2,
12 "USER_SUCCESS": 3,
13 "USER_FAILURE": 4,
14 }
15
16
17 def test_bundle_adjustment_gauge_enum():
18 assert {
19 k: int(v) for k, v in pycolmap.BundleAdjustmentGauge.__members__.items()
20 } == {
21 "UNSPECIFIED": -1,
22 "TWO_CAMS_FROM_WORLD": 0,
23 "THREE_POINTS": 1,
24 }
25
26
27 def test_bundle_adjustment_backend_enum():
28 assert {
29 k: int(v)
30 for k, v in pycolmap.BundleAdjustmentBackend.__members__.items()
31 } == {
32 "CERES": 0,
33 "CASPAR": 1,
34 }
35 assert (
36 pycolmap.BundleAdjustmentBackend("CASPAR")
37 == pycolmap.BundleAdjustmentBackend.CASPAR
38 )
39
40
41 def test_loss_function_type_enum():
42 assert {
43 k: int(v) for k, v in pycolmap.LossFunctionType.__members__.items()
44 } == {
45 "TRIVIAL": 0,
46 "SOFT_L1": 1,
47 "CAUCHY": 2,
48 "HUBER": 3,
49 }
50
51
52 def test_bundle_adjustment_summary_default_init():
53 summary = pycolmap.BundleAdjustmentSummary()
54 assert summary is not None
55
56
57 def test_bundle_adjustment_summary_num_residuals_readwrite():
58 summary = pycolmap.BundleAdjustmentSummary()
59 summary.num_residuals = 100
60 assert summary.num_residuals == 100
61
62
63 def test_bundle_adjustment_summary_termination_type_readwrite():
64 summary = pycolmap.BundleAdjustmentSummary()
65 summary.termination_type = (
66 pycolmap.BundleAdjustmentTerminationType.CONVERGENCE
67 )
68 assert (
69 summary.termination_type
70 == pycolmap.BundleAdjustmentTerminationType.CONVERGENCE
71 )
72
73
74 def test_bundle_adjustment_summary_is_solution_usable():
75 summary = pycolmap.BundleAdjustmentSummary()
76 result = summary.is_solution_usable()
77 assert isinstance(result, bool)
78
79
80 def test_bundle_adjustment_summary_brief_report():
81 summary = pycolmap.BundleAdjustmentSummary()
82 report = summary.brief_report()
83 assert isinstance(report, str)
84
85
86 def test_ceres_bundle_adjustment_summary_default_init():
87 summary = pycolmap.CeresBundleAdjustmentSummary()
88 assert summary is not None
89
90
91 def test_ceres_bundle_adjustment_summary_inherits():
92 summary = pycolmap.CeresBundleAdjustmentSummary()
93 assert isinstance(summary, pycolmap.BundleAdjustmentSummary)
94
95
96 def test_bundle_adjustment_config_default_init():
97 config = pycolmap.BundleAdjustmentConfig()
98 assert config is not None
99
100
101 def test_bundle_adjustment_config_images_property():
102 config = pycolmap.BundleAdjustmentConfig()
103 images = config.images
104 assert len(images) == 0
105
106
107 def test_ceres_ba_options_default_init():
108 options = pycolmap.CeresBundleAdjustmentOptions()
109 assert options is not None
110
111
112 def test_ceres_ba_options_check():
113 options = pycolmap.CeresBundleAdjustmentOptions()
114 result = options.check()
115 assert isinstance(result, bool)
116
117
118 def test_caspar_ba_options_default_init():
119 options = pycolmap.CasparBundleAdjustmentOptions()
120 assert options is not None
121
122
123 def test_caspar_ba_options_readwrite():
124 options = pycolmap.CasparBundleAdjustmentOptions()
125 options.solver_iter_max = 17
126 options.pcg_iter_max = 11
127 options.diag_init = 2.0
128 options.gpu_index = "0"
129 assert options.solver_iter_max == 17
130 assert options.pcg_iter_max == 11
131 assert options.diag_init == 2.0
132 assert options.gpu_index == "0"
133
134
135 def test_ba_options_default_init():
136 options = pycolmap.BundleAdjustmentOptions()
137 assert options is not None
138
139
140 def test_ba_options_refine_focal_length_readwrite():
141 options = pycolmap.BundleAdjustmentOptions()
142 original = options.refine_focal_length
143 assert isinstance(original, bool)
144 options.refine_focal_length = not original
145 assert options.refine_focal_length == (not original)
146
147
148 def test_ba_options_refine_principal_point_readwrite():
149 options = pycolmap.BundleAdjustmentOptions()
150 original = options.refine_principal_point
151 assert isinstance(original, bool)
152 options.refine_principal_point = not original
153 assert options.refine_principal_point == (not original)
154
155
156 def test_ba_options_refine_extra_params_readwrite():
157 options = pycolmap.BundleAdjustmentOptions()
158 original = options.refine_extra_params
159 assert isinstance(original, bool)
160 options.refine_extra_params = not original
161 assert options.refine_extra_params == (not original)
162
163
164 def test_ba_options_refine_points3d_readwrite():
165 options = pycolmap.BundleAdjustmentOptions()
166 original = options.refine_points3D
167 assert isinstance(original, bool)
168 options.refine_points3D = not original
169 assert options.refine_points3D == (not original)
170
171
172 def test_ba_options_min_track_length_readwrite():
173 options = pycolmap.BundleAdjustmentOptions()
174 assert isinstance(options.min_track_length, int)
175 options.min_track_length = 5
176 assert options.min_track_length == 5
177
178
179 def test_ba_options_print_summary_readwrite():
180 options = pycolmap.BundleAdjustmentOptions()
181 original = options.print_summary
182 assert isinstance(original, bool)
183 options.print_summary = not original
184 assert options.print_summary == (not original)
185
186
187 def test_ba_options_backend_readwrite():
188 options = pycolmap.BundleAdjustmentOptions()
189 options.backend = pycolmap.BundleAdjustmentBackend.CERES
190 assert options.backend == pycolmap.BundleAdjustmentBackend.CERES
191 options.backend = pycolmap.BundleAdjustmentBackend.CASPAR
192 assert options.backend == pycolmap.BundleAdjustmentBackend.CASPAR
193
194
195 def test_ba_options_ceres_property():
196 options = pycolmap.BundleAdjustmentOptions()
197 ceres = options.ceres
198 assert isinstance(ceres, pycolmap.CeresBundleAdjustmentOptions)
199
200
201 def test_ba_options_caspar_property():
202 options = pycolmap.BundleAdjustmentOptions()
203 caspar = options.caspar
204 assert isinstance(caspar, pycolmap.CasparBundleAdjustmentOptions)
205
206
207 def test_ba_options_check():
208 options = pycolmap.BundleAdjustmentOptions()
209 result = options.check()
210 assert isinstance(result, bool)
211
212
213 def test_pose_prior_ba_options_default_init():
214 options = pycolmap.PosePriorBundleAdjustmentOptions()
215 assert options is not None
216
217
218 def test_pose_prior_ba_options_prior_position_fallback_stddev_readwrite():
219 options = pycolmap.PosePriorBundleAdjustmentOptions()
220 assert isinstance(options.prior_position_fallback_stddev, float)
221 options.prior_position_fallback_stddev = 5.0
222 assert options.prior_position_fallback_stddev == 5.0
223
224
225 def test_ceres_pose_prior_ba_options_default_init():
226 options = pycolmap.CeresPosePriorBundleAdjustmentOptions()
227 assert options is not None
228
229
230 def test_ceres_pose_prior_ba_options_check():
231 options = pycolmap.CeresPosePriorBundleAdjustmentOptions()
232 result = options.check()
233 assert isinstance(result, bool)
234
235
236 def test_create_default_bundle_adjuster(synthetic_reconstruction):
237 options = pycolmap.BundleAdjustmentOptions()
238 config = pycolmap.BundleAdjustmentConfig()
239 adjuster = pycolmap.create_default_bundle_adjuster(
240 options, config, synthetic_reconstruction
241 )
242 assert adjuster is not None
243
244
245 def test_create_default_ceres_bundle_adjuster(synthetic_reconstruction):
246 options = pycolmap.BundleAdjustmentOptions()
247 config = pycolmap.BundleAdjustmentConfig()
248 adjuster = pycolmap.create_default_ceres_bundle_adjuster(
249 options, config, synthetic_reconstruction
250 )
251 assert adjuster is not None
252
253
254 def test_bundle_adjustment_pipeline(synthetic_reconstruction):
255 reconstruction = pycolmap.Reconstruction(synthetic_reconstruction)
256 options = pycolmap.BundleAdjustmentOptions()
257 options.print_summary = False
258 pycolmap.bundle_adjustment(reconstruction, options)