-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.py
31 lines (21 loc) · 1.03 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import cv2
import torch
from fcgnn import GNN as fcgnn
from sift import SIFT
from utils.draw import draw_matches
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
sift_matcher = SIFT()
fcgnn_refiner = fcgnn().to(device)
img1_path = './assets/img1.jpg'
img2_path = './assets/img2.jpg'
img1 = cv2.imread(img1_path, cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread(img2_path, cv2.IMREAD_GRAYSCALE)
matches = sift_matcher(img1, img2, device=device)
draw_matches(img1, img2, matches.detach().cpu().numpy(), filename='matches_before.png')
print("'./matches_before.png' has been created")
img1_ = torch.tensor(img1.astype('float32') / 255.)[None, None].to(device)
img2_ = torch.tensor(img2.astype('float32') / 255.)[None, None].to(device)
matches = matches.to(device)
matches_refined = fcgnn_refiner.optimize_matches(img1_, img2_, matches, thd=0.999, min_matches=10)[0]
draw_matches(img1, img2, matches_refined.detach().cpu().numpy(), filename='matches_after.png')
print("'./matches_after.png' has been created")