Skip to content

Commit

Permalink
Return nan when underdetermined DLT
Browse files Browse the repository at this point in the history
Co-authored-by: Talmo Pereira <[email protected]>
  • Loading branch information
roomrys and talmo authored Jan 21, 2025
1 parent 584bbf6 commit f6661d4
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions sleap_io/model/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,16 @@ def triangulate_dlt_vectorized(
# Remove rows with NaNs before SVD which may result in a ragged A (hence for loop)
points_3d = []
for a_slice in a:
nan_mask = np.isnan(a_slice)
if np.all(nan_mask):
# If all rows are NaN, set point to NaN
point_3d = np.full(3, np.nan)
# TODO: Also filter out if ony 2 rows (a single point) is non-nan
else:
# Check that we have at least 2 views worth of non-nan points.
nan_mask = np.isnan(a_slice) # 2M x 4
has_enough_matches = np.all(~nan_mask, axis=1).sum(axis=1) >= 4

point_3d = np.full(3, np.nan)
if has_enough_matches:
a_no_nan = a_slice[~nan_mask].reshape(-1, 4, order="C")

_, _, vh = np.linalg.svd(a_no_nan)

point_3d = vh[-1, :-1] / vh[-1, -1]

points_3d.append(point_3d)

points_3d = np.array(points_3d)
Expand Down

0 comments on commit f6661d4

Please sign in to comment.