-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch_features.py
More file actions
63 lines (53 loc) · 2.19 KB
/
match_features.py
File metadata and controls
63 lines (53 loc) · 2.19 KB
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
#
# Copyright (c) 2023-2024 Vladislav Tsendrovskii
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
import math
import json
import numpy as np
import vstarstack.tool.common
import vstarstack.tool.cfg
import vstarstack.library.data
from vstarstack.library.objects.features import build_clusters
def load_keypoints(files):
points = {}
for file in files:
with open(file) as f:
record = json.load(f)
name = record["name"]
points[name] = record
return points
def run(project: vstarstack.tool.cfg.Project, argv: list[str]):
if len(argv) >= 2:
points_path = argv[0]
clusters_fname = argv[1]
else:
points_path = project.config.paths.npy_fixed
clusters_fname = project.config.cluster.path
max_feature_delta = project.config.objects.features.max_feature_delta
features_percent = project.config.objects.features.features_percent / 100.0
files = vstarstack.tool.common.listfiles(points_path, ".json")
files = [filename for _, filename in files]
keypoints = load_keypoints(files)
print("Found keypoints")
points = {}
descs = {}
for name in keypoints:
points[name] = [item["keypoint"] for item in keypoints[name]["points"]]
descs[name] = np.array([np.array(item["descriptor"], dtype=np.uint8) for item in keypoints[name]["points"]])
clusters = build_clusters(points, descs,
max_feature_delta,
features_percent)
print("Builded clusters")
vstarstack.tool.common.check_dir_exists(clusters_fname)
with open(clusters_fname, "w") as f:
json.dump(clusters, f, indent=4, ensure_ascii=False)