stpete2 commited on
Commit
780cd73
·
verified ·
1 Parent(s): c66a1b9

Update h5_to_db.py

Browse files
Files changed (1) hide show
  1. h5_to_db.py +34 -18
h5_to_db.py CHANGED
@@ -112,30 +112,46 @@ def add_keypoints(db, h5_path, image_path, img_ext, camera_model, single_camera
112
 
113
 
114
  def add_matches(db, h5_path, fname_to_id):
 
 
 
115
  match_file = h5py.File(os.path.join(h5_path, 'matches.h5'), 'r')
116
 
117
  added = set()
118
  n_keys = len(match_file.keys())
119
- n_total = (n_keys * (n_keys - 1)) // 2
120
-
121
- with tqdm(total=n_total) as pbar:
122
- for key_1 in match_file.keys():
123
- group = match_file[key_1]
124
- for key_2 in group.keys():
125
- id_1 = fname_to_id[key_1]
126
- id_2 = fname_to_id[key_2]
127
-
128
- pair_id = image_ids_to_pair_id(id_1, id_2)
129
- if pair_id in added:
130
- warnings.warn(f'Pair {pair_id} ({id_1}, {id_2}) already added!')
131
- continue
132
 
133
- matches = group[key_2][()]
134
- db.add_matches(id_1, id_2, matches)
135
-
136
- added.add(pair_id)
137
-
 
 
 
 
 
 
 
 
 
 
 
138
  pbar.update(1)
 
 
 
 
 
 
 
 
 
139
 
140
  def import_into_colmap(img_dir,
141
  feature_dir ='.featureout',
 
112
 
113
 
114
  def add_matches(db, h5_path, fname_to_id):
115
+ """
116
+ matches.h5から直接マッチを追加
117
+ """
118
  match_file = h5py.File(os.path.join(h5_path, 'matches.h5'), 'r')
119
 
120
  added = set()
121
  n_keys = len(match_file.keys())
122
+
123
+ with tqdm(total=n_keys, desc="Adding matches") as pbar:
124
+ for pair_key in match_file.keys():
125
+ # pair_key = "image_000_image_001" の形式を分割
126
+ # "image_000_image_001" ["image_000", "image_001"]
127
+ parts = pair_key.split('_')
 
 
 
 
 
 
 
128
 
129
+ # "image" + "000" + "image" + "001" → "image_000" と "image_001"
130
+ # 中央で分割(前半と後半に分ける)
131
+ mid = len(parts) // 2
132
+ key_1 = '_'.join(parts[:mid])
133
+ key_2 = '_'.join(parts[mid:])
134
+
135
+ if key_1 not in fname_to_id or key_2 not in fname_to_id:
136
+ print(f"Warning: {key_1} or {key_2} not found in fname_to_id")
137
+ pbar.update(1)
138
+ continue
139
+
140
+ id_1 = fname_to_id[key_1]
141
+ id_2 = fname_to_id[key_2]
142
+ pair_id = image_ids_to_pair_id(id_1, id_2)
143
+
144
+ if pair_id in added:
145
  pbar.update(1)
146
+ continue
147
+
148
+ matches = match_file[pair_key][()]
149
+ db.add_matches(id_1, id_2, matches)
150
+ added.add(pair_id)
151
+ pbar.update(1)
152
+
153
+ match_file.close()
154
+
155
 
156
  def import_into_colmap(img_dir,
157
  feature_dir ='.featureout',