Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

root_feature generates nan value with zero division #23

Closed
originlake opened this issue Aug 29, 2023 · 1 comment
Closed

root_feature generates nan value with zero division #23

originlake opened this issue Aug 29, 2023 · 1 comment

Comments

@originlake
Copy link

originlake commented Aug 29, 2023

I encountered an error that happened during Flann feature matching. The reason is one of the feature descriptors for one specific image has all nan values. After further investigation, the problem is caused by the raw feature descriptor being all zeros, based on how root_feature is calculated, there will be a zero division and cause nan value.

OpenSfM/opensfm/features.py

Lines 282 to 288 in 2211a49

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
s = np.sum(desc, 1)
desc = np.sqrt(desc.T / s).T
return desc

This happens rarely and mostly probably due to a feature point having all 0 intensity pixels around it, here is an example dumped in the middle of the feature extraction (the problematic feature point is at the under-exposed dark area at the left side). It can be reproduced by reading the raw gray image and using the below function call to reproduce

from opensfm import features
import cv2
image = cv2.imread("path_to_image", 0) # read gray image 
features.extract_features_sift(image, {'sift_edge_threshold':10.0, 'sift_peak_threshold':0.066, 'feature_root':True}, 16000)

sample

I guess the solution is adding an epsilon value or checking if s is zero. But I'm not sure if keeping all-zero features is reasonable, maybe discarding them is better.

@pierotofy
Copy link
Member

Fixed by #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants