rpautrat / SuperPoint

Efficient neural feature detector and descriptor
MIT License
1.86k stars 414 forks source link

Question about m_kp1 and m_kp2 not being generated #310

Open wangyan0913 opened 9 months ago

wangyan0913 commented 9 months ago

Hello, thank you very much for your guidance, your work has helped me a lot in my studies. When using pre-trained weights for image matching, the elements in out2[0] are all 0-valued, resulting in kp2 not being generated, why is this?

Traceback (most recent call last): File "SuperPoint-master/SuperPoint-master/superpoint/match_features_demo.py", line 186, in H, inliers = compute_homography(m_kp1, m_kp2) File "SuperPoint-master/SuperPoint-master/superpoint/match_features_demo.py", line 65, in compute_homography cv2.RANSAC)
cv2.error: OpenCV(3.4.2) /io/opencv/modules/calib3d/src/fundam.cpp:372: error: (-5:Bad argument) The input arrays should be 2D or 3D point sets in function 'findHomography'

rpautrat commented 9 months ago

Hi, maybe there are simply no keypoint detected. Did you visualize the images and the predictions of the network?

wangyan0913 commented 9 months ago

嗨,也许根本没有检测到关键点。您是否可视化了网络的图像和预测? Hello, thank you very much for your reply, I follow the absolute path and input two images, and input two identical images, img1 can successfully generate kp1,but img2's kp2 is still null... There is no error in the path, and the process is exactly the same for both images, I still can't find out the reason why kp2 is null, it's been bothering me for a long time, I hope I can get your help, I really appreciate it!

rpautrat commented 9 months ago

Did you modify anything from the code online?

wangyan0913 commented 9 months ago

Running the original code gave me the following two errors, so I made changes: 1. File "SuperPoint-master/superpoint/match_features_demo.py", line 50, in keypoints = [cv2.KeyPoint(p[1], p[0], 1) for p in keypoints] cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'KeyPoint'

Overload resolution failed:

  • Argument 'x' can not be safely parsed to 'float'

My solution: add it before the error reporting statement: keypoints=keypoints.astype(np.float32)

2. Traceback (most recent call last): File "SuperPoint-master/superpoint/match_features_demo.py", line 158, in m_kp1, m_kp2, matches = match_descriptors(kp1, desc1, kp2, desc2) File "SuperPoint-master/superpoint/match_features_demo.py",line58,in match_descriptors matches = bf.match(desc1, desc2)
cv2.error: OpenCV(4.6.0) /io/opencv/modules/core/src/batch_distance.cpp:303: error: (-215:Assertion failed) K == 1 && update == 0 && mask.empty() in function 'batchDistance'

My solution: change "bf = cv2.BFMatcher(cv2.NORM_L2,crossCheck=True)" to "bf = cv2.BFMatcher(cv2.NORM_L2)"

No other changes have been made.

rpautrat commented 8 months ago

Hi, these changes should not be a problem in theory. So I don't know why you don't get keypoints on the second image. This is indeed a very weird behavior...

You would need to debug yourself, by inspecting the data at different steps of the inference (e.g. visualize the keypoint probability map output by the network, print the number of keypoints at different stages, etc), to localize the part of the code where the keypoints are discarded (or whether the probability map is itself full of zeros).