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

Regarding estimating Camera matrix K, R and T #26

Open
Ram-198 opened this issue Jul 12, 2023 · 4 comments
Open

Regarding estimating Camera matrix K, R and T #26

Ram-198 opened this issue Jul 12, 2023 · 4 comments

Comments

@Ram-198
Copy link

Ram-198 commented Jul 12, 2023

Hi,

Thank you and the matching results are very good. :)

Earlier i used Sift for feature extraction and cv.detail_BestOf2NearestMatcher() for matching. Then i use cv.detail_HomographyBasedEstimator() to estimate the K, R and T.

How can i achieve this using LightGlue results? Could you please help me with calculating K, R and T from lightglue results?

Thank you

@Phil26AT
Copy link
Collaborator

Hi @Ram-198

I am not very familiar with the functions you used, but you could do something similar with pycolmap:

import pycolmap
import cv2

image0 = load_image('path/to/image0.jpg')
image1 = load_image('path/to/image1.jpg')

# run lightglue to obtain m_kpts0, m_kpts1 (see demo notebook)

K0 = pycolmap.infer_camera_from_image('path/to/image0.jpg').calibration_matrix()
K1 = pycolmap.infer_camera_from_image('path/to/image1.jpg').calibration_matrix()

H, inliers = cv2.findHomography(m_kpts0, m_kpts1, cv2.USAC_MAGSAC, 0.5, 0.999, 100000)

ret = pycolmap.homography_decomposition(H, K0, K1, m_kpts0, m_kpts1)

R, t = ret['R'], ret['t']

@aelsaer
Copy link

aelsaer commented Jul 14, 2023

Thank you @Phil26AT for providing this code snippet. I think cv2.findHomography takes 4 arguments while cv2.FindFundamentalMat takes 6. And a minor comment, considering that m_kpts0, m_kpts1 are tensors, they need to be transformed to numpy thus, m_kpts0.numpy() , m_kpts1.numpy() will work. Thanks again @Phil26AT! LightGlue is outstanding.

@yayaYsmile
Copy link

yayaYsmile commented Aug 13, 2023

Thank you @Phil26AT for providing this code snippet. I think cv2.findHomography takes 4 arguments while cv2.FindFundamentalMat takes 6. And a minor comment, considering that m_kpts0, m_kpts1 are tensors, they need to be transformed to numpy thus, m_kpts0.numpy() , m_kpts1.numpy() will work. Thanks again @Phil26AT! LightGlue is outstanding.

Hi!
When calculating the camera matrix and converting the tensor m_kpts0, m_kpts1 to numpy it seems that the tensor on the GPU can't be converted directly with numpy, it has to be converted to a tensor on the CPU and then to numpy: torch.cpu().numpy(). However this seems to make the computation slow, is there any other way to solve this problem?

@aelsaer
Copy link

aelsaer commented Aug 18, 2023

Hello @yayaYsmile. As far as I'm aware, if you're working with PyTorch tensors, Kornia is a good option since it allows for operations directly on tensors. However, in terms of outlier removal, I believe Kornia primarily offers RANSAC. It's possible they may have added more methods in newer versions, so it might be worth checking their documentation or source code for any updates.

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

4 participants