Skip to content

Commit 380ca9a

Browse files
authored
Add files via upload
1 parent 03ebe2e commit 380ca9a

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

reconstruction_Colmap.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from pathlib import Path
2+
from hloc import extract_features, match_features, reconstruction, visualization, pairs_from_retrieval
3+
import os
4+
import shutil as shutil
5+
6+
7+
def ReconstructionFromImages(pathstring, num_matched=5):
8+
pathstring += "/"
9+
imagesstring = pathstring + 'images'
10+
images = Path(imagesstring)
11+
pathoutputsstring = pathstring + 'output/'
12+
outputs = Path(pathoutputsstring)
13+
sfm_pairs = outputs / 'pairs-netvlad.txt'
14+
pathsfm_dirstring = pathoutputsstring + 'sparse'
15+
sfm_dir = outputs / 'sparse'
16+
17+
retrieval_conf = extract_features.confs['netvlad']
18+
feature_conf = extract_features.confs['superpoint_max']
19+
matcher_conf = match_features.confs['superglue']
20+
21+
retrieval_path = extract_features.main(retrieval_conf, images, outputs)
22+
pairs_from_retrieval.main(retrieval_path, sfm_pairs, num_matched=num_matched) # 5 xujx update
23+
24+
feature_path = extract_features.main(feature_conf, images, outputs)
25+
26+
match_path = match_features.main(matcher_conf, sfm_pairs, feature_conf['output'], outputs)
27+
28+
reconstruction.main(sfm_dir, images, sfm_pairs, feature_path, match_path) #min_match_score=0.7
29+
30+
dense_path = pathoutputsstring + "dense"
31+
dense_mask_path = pathoutputsstring + "dense_mask"
32+
converter = "colmap image_undistorter --image_path " + imagesstring + " --output_path " + dense_path + " --input_path " + pathsfm_dirstring
33+
converter = converter + "\n"
34+
35+
imagesstring_mask = pathstring + 'images-mask'
36+
converter = converter + "colmap image_undistorter --image_path " + imagesstring_mask + " --output_path " + dense_mask_path + " --input_path " + pathsfm_dirstring
37+
converter = converter + "\n"
38+
39+
converter = converter + "colmap patch_match_stereo --workspace_path " + dense_path
40+
converter = converter + "\n"
41+
42+
converter = converter + "colmap stereo_fusion --workspace_path " + dense_path + " --output_path " + dense_path + "/fused-rgb.ply"
43+
converter = converter + "\n"
44+
os.system(converter)
45+
46+
shutil.move(dense_path + '/images', dense_path + '/images-rgb')
47+
shutil.copytree(dense_mask_path + '/images', dense_path + '/images')
48+
49+
converter = "colmap stereo_fusion --workspace_path " + dense_path + " --output_path " + dense_path + "/fused-mask.ply"
50+
51+
shutil.rmtree(dense_mask_path)
52+
53+
os.system(converter)
54+
55+
return 0
56+
57+

reconstruction_OpenMVS.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# data_folder_Structure
2+
# ├── mask
3+
# │ ├── 0000000000.png
4+
# │ ├── 0000000001.png
5+
# │ ├── ...
6+
# ├── other
7+
# │ ├── 0000000000.png
8+
# │ ├── 0000000001.png
9+
# │ ├── ...
10+
# ├── output
11+
12+
from pathlib import Path
13+
import os
14+
import tkinter as tk
15+
from tkinter import filedialog
16+
from datetime import datetime
17+
import calculate_zoom as calz
18+
import noiseReduction as nr
19+
20+
def reconstrucionFromImages(pathstring):
21+
# pathstring = "/media/xujx/MyPassport/sfm-pro/20221028-1-T154-0/"
22+
23+
pathstring += "/"
24+
mask_dir_string = os.path.join(pathstring, 'mask')
25+
other_dir_string = os.path.join(pathstring, 'other')
26+
path_outputs_string = os.path.join(pathstring, 'output/')
27+
28+
# openMVS
29+
converter = "cd /usr/local/bin/OpenMVS"
30+
converter = converter + "\n"
31+
32+
converter = converter + "./InterfaceCOLMAP -i "
33+
converter = converter + path_outputs_string
34+
converter = converter + " -o "
35+
converter = converter + path_outputs_string + "scene_panicle.mvs"
36+
converter = converter + " --image-folder "
37+
converter = converter + mask_dir_string
38+
converter = converter + "\n"
39+
40+
converter = converter + "./DensifyPointCloud -w "
41+
converter = converter + path_outputs_string
42+
converter = converter + " -i scene_panicle.mvs -o panicle.mvs --remove-dmaps 1"
43+
converter = converter + "\n"
44+
45+
converter = converter + "./InterfaceCOLMAP -i "
46+
converter = converter + path_outputs_string
47+
converter = converter + " -o "
48+
converter = converter + path_outputs_string + "scene_other.mvs"
49+
converter = converter + " --image-folder "
50+
converter = converter + other_dir_string
51+
converter = converter + "\n"
52+
53+
converter = converter + "./DensifyPointCloud -w "
54+
converter = converter + path_outputs_string
55+
converter = converter + " -i scene_other.mvs -o other.mvs --remove-dmaps 1"
56+
converter = converter + "\n"
57+
58+
os.system(converter)
59+
60+
return 0
61+
62+
def process_folders(root_path, folder):
63+
folder_path = os.path.join(root_path, folder)
64+
video_folder_path = folder_path
65+
images_output_path = os.path.join(folder_path, 'images')
66+
67+
if os.path.exists(video_folder_path) and os.path.isdir(video_folder_path):
68+
# 创建images文件夹,如果不存在
69+
if not os.path.exists(images_output_path):
70+
os.makedirs(images_output_path)
71+
for video_name in os.listdir(video_folder_path):
72+
video_file_path = os.path.join(video_folder_path, video_name)
73+
video_to_frames(video_file_path, images_output_path)
74+
75+
def check_dense_scene_ply(folder_path):
76+
ply_file_path = os.path.join(folder_path, 'output', 'dense_scene.ply')
77+
return os.path.exists(ply_file_path)
78+
79+
def traverse_folders(root_path):
80+
folders_to_exclude = []
81+
# check
82+
for folder_name in os.listdir(root_path):
83+
folder_path = os.path.join(root_path, folder_name)
84+
if os.path.isdir(folder_path) and check_dense_scene_ply(folder_path):
85+
print(f"Excluding folder name: {folder_name}")
86+
folders_to_exclude.append(folder_name)
87+
88+
filtered_folders = [folder_name for folder_name in os.listdir(root_path) if folder_name not in folders_to_exclude]
89+
return filtered_folders
90+
91+
if __name__ == '__main__':
92+
93+
path = '/your/path'
94+
reconstrucionFromImages(path)
95+

0 commit comments

Comments
 (0)