Skip to content

Commit

Permalink
Merge pull request #25 from originlake/fix_nan_feature
Browse files Browse the repository at this point in the history
fix features zero division causing nan value
  • Loading branch information
pierotofy committed Sep 7, 2023
2 parents fea7f89 + ab90022 commit 2fc680b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions opensfm/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,10 @@ def root_feature(desc: np.ndarray, l2_normalization: bool = False) -> np.ndarray
if l2_normalization:
s2 = np.linalg.norm(desc, axis=1)
desc = (desc.T / s2).T
desc[s2 == 0] = 0
s = np.sum(desc, 1)
desc = np.sqrt(desc.T / s).T
desc[s==0] = 0
return desc


Expand All @@ -298,6 +300,7 @@ def root_feature_surf(
if l2_normalization:
s2 = np.linalg.norm(desc, axis=1)
desc = (desc.T / s2).T
desc[s2 == 0] = 0
if partial:
ii = np.array([i for i in range(64) if (i % 4 == 2 or i % 4 == 3)])
else:
Expand All @@ -307,6 +310,7 @@ def root_feature_surf(
# s_sub = np.sum(desc_sub, 1) # This partial normalization gives slightly better results for AKAZE surf
s_sub = np.sum(np.abs(desc), 1)
desc_sub = np.sqrt(desc_sub.T / s_sub).T
desc_sub[s_sub == 0] = 0
desc[:, ii] = desc_sub * desc_sub_sign
return desc

Expand Down

0 comments on commit 2fc680b

Please sign in to comment.