Skip to content

Commit f805197

Browse files
Fabian Schenkmeta-codesync[bot]
authored andcommitted
Add missing return in Backward distortion functions for near-zero radius guard
Summary: All 6 `Backward` methods in camera distortion structs (Disto2, Disto24, Disto2468, DistoBrown, Disto62, DistoDualFisheye) have an early-exit guard for near-zero distorted radius: when `rd < epsilon`, the code sets `undistorted = point` (identity undistortion). However, the guard was missing a `return` statement, so execution always fell through to the Newton-Raphson iterative solver. This makes the guard completely ineffective. For points very near the optical center, the Newton-Raphson solver divides near-zero values by near-zero distortion factors, potentially producing NaN or wildly incorrect undistorted coordinates. This diff adds `return;` after the identity assignment in all 6 Backward methods, making the early-exit guard take effect. ___ overriding_review_checks_triggers_an_audit_and_retroactive_review Oncall Short Name: mrservice_triage Differential Revision: D100590112 fbshipit-source-id: 40839c830f2424126e1727906324f635d5c5423a
1 parent 8acdab7 commit f805197

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

opensfm/src/geometry/camera_distortions_functions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct Disto2 : Functor<2, 1, 2> {
5454
if (rd < T(std::numeric_limits<double>::epsilon())) {
5555
undistorted[0] = point[0];
5656
undistorted[1] = point[1];
57+
return;
5758
}
5859

5960
// Compute undistorted radius
@@ -152,6 +153,7 @@ struct Disto24 : Functor<2, 2, 2> {
152153
if (rd < T(std::numeric_limits<double>::epsilon())) {
153154
undistorted[0] = point[0];
154155
undistorted[1] = point[1];
156+
return;
155157
}
156158

157159
// Compute undistorted radius
@@ -268,6 +270,7 @@ struct Disto2468 : Functor<2, 4, 2> {
268270
if (rd < T(std::numeric_limits<double>::epsilon())) {
269271
undistorted[0] = point[0];
270272
undistorted[1] = point[1];
273+
return;
271274
}
272275

273276
// Compute undistorted radius
@@ -421,6 +424,7 @@ struct Disto62 : Functor<2, 8, 2> {
421424
if (rd < T(std::numeric_limits<double>::epsilon())) {
422425
undistorted[0] = point[0];
423426
undistorted[1] = point[1];
427+
return;
424428
}
425429
Eigen::Map<const Vec2<T>> mapped_point(point);
426430
// Compute undistorted radius
@@ -627,6 +631,7 @@ struct Disto624 : Functor<2, 12, 2> {
627631
if (rd < T(std::numeric_limits<double>::epsilon())) {
628632
undistorted[0] = point[0];
629633
undistorted[1] = point[1];
634+
return;
630635
}
631636
Eigen::Map<const Vec2<T>> mapped_point(point);
632637
// Compute undistorted radius
@@ -774,6 +779,7 @@ struct DistoBrown : Functor<2, 5, 2> {
774779
if (rd < T(std::numeric_limits<double>::epsilon())) {
775780
undistorted[0] = point[0];
776781
undistorted[1] = point[1];
782+
return;
777783
}
778784

779785
Eigen::Map<const Vec2<T>> mapped_point(point);

0 commit comments

Comments
 (0)