forked from cvg/Hierarchical-Localization
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocalization.py
68 lines (59 loc) · 2.16 KB
/
localization.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from hloc.localize_sfm import QueryLocalizer, pose_from_cluster
import pycolmap
from pathlib import Path
from hloc import (
extract_features,
match_features,
reconstruction,
visualization,
pairs_from_retrieval,
pairs_from_exhaustive,
localize_sfm,
)
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--sfm_imgs", type=Path)
parser.add_argument("--sfm_model", type=Path)
parser.add_argument("--sfm_outputs", type=Path)
parser.add_argument("--query_imgs", type=Path)
parser.add_argument("--query_list", type=Path)
parser.add_argument("--query_outputs", type=Path)
parser.add_argument("--topn", type=int, default=5)
parser.add_argument("--global_feat", type=str)
parser.add_argument("--local_feat", type=str)
parser.add_argument("--match_method", type=str)
parser.add_argument("--result_name", type=str, default="result.txt")
args = parser.parse_args()
images = args.sfm_imgs
sfm_outputs = args.sfm_outputs
query_outputs = args.query_outputs
sfm_dir = args.sfm_model
loc_pairs = query_outputs / Path(
"pairs-query-netvlad" + str(args.topn) + ".txt"
) # top n retrieved by NetVLAD
results = query_outputs / args.result_name # the result file
retrieval_conf = extract_features.confs[args.global_feat]
feature_conf = extract_features.confs[args.local_feat]
matcher_conf = match_features.confs[args.match_method]
# global feature extraction for
retrieval_path = extract_features.main(retrieval_conf, images, sfm_outputs)
# local feature extraction?-> this actually do nothing
feature_path = extract_features.main(feature_conf, images, sfm_outputs)
# query global matching
query = args.query_imgs
global_descriptors = extract_features.main(retrieval_conf, query, query_outputs)
pairs_from_retrieval.main(
global_descriptors, loc_pairs, num_matched=args.topn, db_descriptors=retrieval_path
)
# query local matching
ffile = extract_features.main(feature_conf, query, query_outputs)
mfile = match_features.main(
matcher_conf,
loc_pairs,
feature_conf["output"],
query_outputs,
features_ref=feature_path,
)
# localize query images in map
query_list = args.query_list
localize_sfm.main(sfm_dir, query_list, loc_pairs, ffile, mfile, results)