-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrunning.py
54 lines (41 loc) · 1.41 KB
/
running.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import cv2 as cv
import tensorflow as tf
import h5py
import os
import matplotlib.cm as cm
from src.loftr.utils.plotting_TF import make_matching_figure
from src.configs.getConfig import giveConfig
from src.loftr.LoFTR_TF import LoFTR
try:
os.chdir("LoFTR-in-Tensorflow")
except:
print("Directory is fine")
print(tf.__version__)
print(tf.keras.__version__)
config,_config = giveConfig()
#Creating the matcher
matcher=LoFTR(config=_config['loftr'])
matcher.load_weights("./weights/megadepth/cp_Megadepth.ckpt")
#loading in the images for the current batch
img0_pth = "./other/capitolTest1.jpg"#"./src/training/datasets/unused/Scenes/scene3/Images/628.jpg"
img1_pth = "./other/capitolTest2.jpg"
img0_raw = cv.imread(img0_pth, cv.IMREAD_GRAYSCALE)
img1_raw = cv.imread(img1_pth, cv.IMREAD_GRAYSCALE)
img0_raw = cv.resize(img0_raw, (640, 480))
img1_raw = cv.resize(img1_raw, (640, 480))
img0 = tf.convert_to_tensor(img0_raw)[None][None]/255
img1 = tf.convert_to_tensor(img1_raw)[None][None]/255
data = {'image0': img0, 'image1': img1}
#Calling the matcher on the current batch
updata = matcher(data)
#Extracting matches
mkpts0 = updata['mkpts0_f'].numpy()
mkpts1 = updata['mkpts1_f'].numpy()
mconf = updata['mconf'].numpy()
color = cm.jet(mconf)
text = [
'LoFTR',
'Matches: {}'.format(len(mkpts0)),
]
make_matching_figure(img0_raw, img1_raw, mkpts0, mkpts1, color, text=text, path='./outputs/figs/matches.jpg')
print("DONE")