You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"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
"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)
The text was updated successfully, but these errors were encountered: