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

Slow LightGlue at 1,7s #151

Open
ghost opened this issue Jan 29, 2025 · 0 comments
Open

Slow LightGlue at 1,7s #151

ghost opened this issue Jan 29, 2025 · 0 comments

Comments

@ghost
Copy link

ghost commented Jan 29, 2025

"So, I'm working with large images (5472x3648), and my code is taking around 1.7 seconds. Can someone help? LightGlue is supposed to operate in milliseconds."

from pathlib import Path
from lightglue import LightGlue, SuperPoint
from lightglue.utils import load_image, rbd
import torch
import cv2
import numpy as np
import time

torch.set_grad_enabled(False)
images = Path("C:\Users\irh\Documents\img_alinhamento\1\")

device = torch.device("cuda") # 'mps', 'cpu'

extractor = SuperPoint(max_num_keypoints=2048).eval().to(device) # load the extractor
matcher = LightGlue(features="superpoint").eval().to(device)
a= time.time()
image0 = load_image(images / "cabo_fan_dir_ok(2).jpg")
image1 = load_image(images / "bateria_nok(2).jpg")
img1 = cv2.imread('C:\Users\irh\Documents\img_alinhamento\1\cabo_fan_dir_ok(2).jpg')
with torch.no_grad():
feats0 = extractor.extract(image0.to(device))
feats1 = extractor.extract(image1.to(device))
matches01 = matcher({"image0": feats0, "image1": feats1})
feats0, feats1, matches01 = [
rbd(x) for x in [feats0, feats1, matches01]
] # remove batch dimension

kpts0, kpts1, matches = feats0["keypoints"], feats1["keypoints"], matches01["matches"]
m_kpts0, m_kpts1 = kpts0[matches[..., 0]], kpts1[matches[..., 1]]
m_kpts0, m_kpts1 = m_kpts0.cpu().numpy(), m_kpts1.cpu().numpy()
b= time.time()
c = b- a
print(c)
M, status = cv2.estimateAffinePartial2D(np.float32(m_kpts0),
np.float32(m_kpts1), cv2.RANSAC)
result = cv2.warpAffine(img1, M, (img1.shape[1], img1.shape[0]),cv2.INTER_NEAREST_EXACT)
cv2.imwrite('C:\Users\irh\Documents\img_alinhamento\1\alinhada.jpg',result)

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

0 participants