-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
executable file
·93 lines (74 loc) · 3.13 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Copyright (c) 2023, Stefan Toeberg.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#
# (http://opensource.org/licenses/BSD-3-Clause)
#
# __author__ = "Stefan Toeberg, LUH: IMR"
# __description__ = """
# sequential processing of the reconstruction routine
# using AffineMultiViewStereo objects and a PointCloud object
# """
# packages
import numpy as np
import matplotlib.pyplot as plt
import sem3d.utils.preprocessing as pp
import sem3d.classes.AffineMultiViewStereo as amvs
from sem3d.classes.PointCloud import PointCloud
from sem3d.config.config import set_config
import matplotlib
matplotlib.use('TkAgg')
def main():
# plt.ion()
print("Starting the pipeline...")
# configuration of the amvs-Pipeline -> config.py
config = set_config()
# load the images, get the stereoPairs of adjacent images and the stereo pair used for the triangulation
stereoPairs, selectedStereoPairs = pp.get_images(config)
# create two objects of type AffineMultiViewStereo
MvsSequence = amvs.AffineMultiViewStereo.general_init(stereoPairs, config)
MvsSelectedPairs = amvs.AffineMultiViewStereo(selectedStereoPairs, config)
# process the sequence to estimate the camera parameters
MvsSequence.detect_match_features()
MvsSequence.apply_motion_constraints()
MvsSequence.robust_epipolar_geometry()
MvsSequence.optimize_epipolar_geometry()
MvsSequence.measurement_matrix()
MvsSequence.factorization()
# process selected stereo pairs to compute the disparity maps
MvsSelectedPairs.detect_match_features()
MvsSelectedPairs.apply_motion_constraints()
MvsSelectedPairs.robust_epipolar_geometry()
MvsSelectedPairs.optimize_epipolar_geometry()
MvsSelectedPairs.rectify_stereo_pairs()
MvsSelectedPairs.disparity_maps()
# segment rectified images
if config['segmentation'] == True:
MvsSelectedPairs.segment_rectified_images_unet()
MvsSelectedPairs.segment_rectified_images_grabcut()
# post process disparity map
MvsSelectedPairs.post_process_disparity_maps()
# copy dense matches attribute to the sequence object
MvsSequence.denseMatches = MvsSelectedPairs.denseMatches
# compute dense point clouds
MvsSequence.compute_dense_point_clouds()
# create PointCloud object to process the point clouds
MvsPointClouds = PointCloud.from_mvs_object(MvsSequence)
if config['densityFilter'] == True:
MvsPointClouds.density_filter(
numClusters=config['numClusters'], epsilon=12.5, minPoints=25)
else:
MvsPointClouds.visualize_point_cloud()
if config['savePointCloud'] == True:
print('Save point cloud to file..')
if config['densityFilter'] == True:
np.save('reconstructed_point_cloud.npy',
MvsPointClouds.filtDenseClouds[0])
else:
np.save('reconstructed_point_cloud.npy',
MvsPointClouds.densePointClouds[0])
print('Reconstruction pipeline finished.')
if __name__ == '__main__':
main()