Reconstruction#
database.py#
1# ----------------------------------------------------------------------------
2# - CloudViewer: www.cloudViewer.org -
3# ----------------------------------------------------------------------------
4# Copyright (c) 2018-2024 www.cloudViewer.org
5# SPDX-License-Identifier: MIT
6# ----------------------------------------------------------------------------
7
8# examples/Python/reconstruction/feature.py
9
10import numpy as np
11import cloudViewer as cv3d
12
13
14def merge_database(database_path1, database_path2, out_database_path):
15 return cv3d.reconstruction.database.merge_database(database_path1,
16 database_path2,
17 out_database_path)
18
19
20def clean_database(database_path, clean_type):
21 # supported type {all, images, features, matches}
22 return cv3d.reconstruction.database.clean_database(database_path,
23 clean_type)
24
25
26def create_database(database_path):
27 return cv3d.reconstruction.database.create_database(database_path)
28
29
30if __name__ == "__main__":
31 np.random.seed(42)
32 cv3d.utility.set_verbosity_level(cv3d.utility.Debug)
33
34 DATABASE_PATH = "/media/asher/data/datasets/out/sql.db"
35 TYPE = "all"
36
37 flag = clean_database(DATABASE_PATH, TYPE)
38 if flag != 0:
39 print("clean_database failed!")
40
41 flag = create_database(DATABASE_PATH)
42 if flag != 0:
43 print("create_database failed!")
44
45 # DATABASE_PATH2 = ""
46 # OUT_DATABASE_PATH = ""
47 # flag = merge_database(DATABASE_PATH, DATABASE_PATH2, OUT_DATABASE_PATH)
48 # if flag != 0:
49 # print("clean_database failed!")
feature.py#
1# ----------------------------------------------------------------------------
2# - CloudViewer: www.cloudViewer.org -
3# ----------------------------------------------------------------------------
4# Copyright (c) 2018-2024 www.cloudViewer.org
5# SPDX-License-Identifier: MIT
6# ----------------------------------------------------------------------------
7
8# examples/Python/reconstruction/feature.py
9
10import time
11import numpy as np
12import cloudViewer as cv3d
13
14
15def import_feature(database_path,
16 image_path,
17 import_path,
18 image_list_path="",
19 camera_mode=0):
20 image_reader_options = cv3d.reconstruction.options.ImageReaderOptions()
21 if not image_reader_options.check():
22 return 1
23 sift_extraction_options = cv3d.reconstruction.options.SiftExtractionOptions(
24 )
25 if not sift_extraction_options.check():
26 return 1
27 return cv3d.reconstruction.feature.import_feature(
28 database_path=database_path,
29 image_path=image_path,
30 import_path=import_path,
31 image_list_path=image_list_path,
32 camera_mode=camera_mode,
33 image_reader_options=image_reader_options,
34 sift_extraction_options=sift_extraction_options)
35
36
37def import_matches(database_path, match_list_path="", match_type="pairs"):
38 sift_matching_options = cv3d.reconstruction.options.SiftMatchingOptions()
39 if not sift_matching_options.check():
40 return 1
41 return cv3d.reconstruction.feature.import_matches(
42 database_path=database_path,
43 match_list_path=match_list_path,
44 match_type=match_type,
45 sift_matching_options=sift_matching_options)
46
47
48def extract_features(database_path,
49 image_path,
50 image_list_path="",
51 camera_mode=0):
52 image_reader_options = cv3d.reconstruction.options.ImageReaderOptions()
53 if not image_reader_options.check():
54 return 1
55 sift_extraction_options = cv3d.reconstruction.options.SiftExtractionOptions(
56 )
57 if not sift_extraction_options.check():
58 return 1
59
60 return cv3d.reconstruction.feature.extract_feature(
61 database_path=database_path,
62 image_path=image_path,
63 image_list_path=image_list_path,
64 camera_mode=camera_mode,
65 image_reader_options=image_reader_options,
66 sift_extraction_options=sift_extraction_options)
67
68
69def exhaustive_match(database_path):
70 sift_matching_options = cv3d.reconstruction.options.SiftMatchingOptions()
71 if not sift_matching_options.check():
72 return 1
73 exhaustive_matching_options = cv3d.reconstruction.options.ExhaustiveMatchingOptions(
74 )
75 if not exhaustive_matching_options.check():
76 return 1
77 return cv3d.reconstruction.feature.exhaustive_match(
78 database_path=database_path,
79 sift_matching_options=sift_matching_options,
80 exhaustive_matching_options=exhaustive_matching_options)
81
82
83def sequential_match(database_path):
84 sift_matching_options = cv3d.reconstruction.options.SiftMatchingOptions()
85 if not sift_matching_options.check():
86 return 1
87 sequential_matching_options = cv3d.reconstruction.options.SequentialMatchingOptions(
88 )
89 if not sequential_matching_options.check():
90 return 1
91 return cv3d.reconstruction.feature.sequential_match(
92 database_path=database_path,
93 sift_matching_options=sift_matching_options,
94 sequential_matching_options=sequential_matching_options)
95
96
97def spatial_match(database_path):
98 sift_matching_options = cv3d.reconstruction.options.SiftMatchingOptions()
99 if not sift_matching_options.check():
100 return 1
101 spatial_matching_options = cv3d.reconstruction.options.SpatialMatchingOptions(
102 )
103 if not spatial_matching_options.check():
104 return 1
105 return cv3d.reconstruction.feature.spatial_match(
106 database_path=database_path,
107 sift_matching_options=sift_matching_options,
108 spatial_matching_options=spatial_matching_options)
109
110
111def transitive_match(database_path):
112 sift_matching_options = cv3d.reconstruction.options.SiftMatchingOptions()
113 if not sift_matching_options.check():
114 return 1
115 transitive_matching_options = cv3d.reconstruction.options.TransitiveMatchingOptions(
116 )
117 if not transitive_matching_options.check():
118 return 1
119 return cv3d.reconstruction.feature.transitive_match(
120 database_path=database_path,
121 sift_matching_options=sift_matching_options,
122 transitive_matching_options=transitive_matching_options)
123
124
125def vocab_tree_match(database_path, vocab_tree_path):
126 sift_matching_options = cv3d.reconstruction.options.SiftMatchingOptions()
127 if not sift_matching_options.check():
128 return 1
129 vocab_tree_matching_options = cv3d.reconstruction.options.VocabTreeMatchingOptions(
130 )
131 vocab_tree_matching_options.vocab_tree_path = vocab_tree_path
132 if not vocab_tree_matching_options.check():
133 return 1
134 return cv3d.reconstruction.feature.vocab_tree_match(
135 database_path=database_path,
136 sift_matching_options=sift_matching_options,
137 vocab_tree_matching_options=vocab_tree_matching_options)
138
139
140if __name__ == "__main__":
141 np.random.seed(42)
142 cv3d.utility.set_verbosity_level(cv3d.utility.Debug)
143
144 DATABASE_PATH = "/media/asher/data/datasets/out/sql.db"
145 IMAGE_PATH = "/media/asher/data/datasets/dataset_monstree/mini6"
146 VOCAB_TREE_PATH = "/media/asher/data/datasets/vocab_tree/vocab_tree_flickr100K_words32K.bin"
147 IMPORT_PATH = ""
148 IMAGE_LIST_PATH = ""
149 MATCH_LIST_PATH = ""
150 MATCH_TYPE = "pairs"
151 CAMERA_MODE = 0
152
153 # flag = import_feature(DATABASE_PATH, IMAGE_PATH, IMPORT_PATH, IMAGE_LIST_PATH, CAMERA_MODE)
154 # if flag != 0:
155 # print("import_feature failed!")
156
157 # flag = import_matches(DATABASE_PATH, MATCH_LIST_PATH, MATCH_TYPE)
158 # if flag != 0:
159 # print("import_feature failed!")
160
161 flag = extract_features(DATABASE_PATH, IMAGE_PATH, IMAGE_LIST_PATH,
162 CAMERA_MODE)
163 if flag != 0:
164 print("extract_feature failed!")
165
166 flag = exhaustive_match(DATABASE_PATH)
167 if flag != 0:
168 print("exhaustive_match failed!")
169
170 flag = sequential_match(DATABASE_PATH)
171 if flag != 0:
172 print("sequential_match failed!")
173
174 flag = spatial_match(DATABASE_PATH)
175 if flag != 0:
176 print("spatial_match failed!")
177
178 flag = transitive_match(DATABASE_PATH)
179 if flag != 0:
180 print("transitive_match failed!")
181
182 flag = vocab_tree_match(DATABASE_PATH, VOCAB_TREE_PATH)
183 if flag != 0:
184 print("vocab_tree_match failed!")
gui.py#
1# ----------------------------------------------------------------------------
2# - CloudViewer: www.cloudViewer.org -
3# ----------------------------------------------------------------------------
4# Copyright (c) 2018-2024 www.cloudViewer.org
5# SPDX-License-Identifier: MIT
6# ----------------------------------------------------------------------------
7
8# examples/Python/reconstruction/feature.py
9
10import os
11import numpy as np
12import cloudViewer as cv3d
13
14
15def generate_project(output_path, quality):
16 return cv3d.reconstruction.gui.generate_project(output_path=output_path,
17 quality=quality)
18
19
20def gui(database_path="", image_path="", import_path=""):
21 return cv3d.reconstruction.gui.run_graphical_gui(
22 database_path=database_path,
23 image_path=image_path,
24 import_path=import_path)
25
26
27if __name__ == "__main__":
28 np.random.seed(42)
29 cv3d.utility.set_verbosity_level(cv3d.utility.Debug)
30 # ROOT_PATH = "/home/asher/develop/data/reconstruction"
31 # DATABASE_PATH = os.path.join(ROOT_PATH, "database.db")
32 # IMAGE_PATH = os.path.join(ROOT_PATH, "dataset_monstree/mini6")
33 # IMPORT_PATH = os.path.join(ROOT_PATH, "sparse/0")
34 # OUTPUT_PATH = os.path.join(ROOT_PATH, "pro.ini")
35 # QUALITY = "medium" # {low, medium, high, extreme}
36
37 # flag = generate_project(OUTPUT_PATH, QUALITY)
38 # if flag != 0:
39 # print("generate_project failed!")
40
41 # flag = gui(DATABASE_PATH, IMAGE_PATH, IMPORT_PATH)
42 # if flag != 0:
43 # print("gui failed!")
44
45 flag = gui()
46 if flag != 0:
47 print("gui failed!")
image.py#
1# ----------------------------------------------------------------------------
2# - CloudViewer: www.cloudViewer.org -
3# ----------------------------------------------------------------------------
4# Copyright (c) 2018-2024 www.cloudViewer.org
5# SPDX-License-Identifier: MIT
6# ----------------------------------------------------------------------------
7
8import numpy as np
9import cloudViewer as cv3d
10
11
12def delete_image(input_path,
13 output_path,
14 image_ids_path='',
15 image_names_path=''):
16 """
17 delete_image(input_path, output_path, image_ids_path='', image_names_path='')
18 Function for the deletion of images
19
20 Args:
21 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
22 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
23 image_ids_path (str, optional, default=''): Path to text file containing one image_id to delete per line.
24 image_names_path (str, optional, default=''): Path to text file containing one image name to delete per line.
25
26 Returns:
27 int
28 """
29 return cv3d.reconstruction.image.delete_image(
30 input_path=input_path,
31 output_path=output_path,
32 image_ids_path=image_ids_path,
33 image_names_path=image_names_path)
34
35
36def filter_image(input_path,
37 output_path,
38 min_focal_length_ratio=0.1,
39 max_focal_length_ratio=10.0,
40 max_extra_param=100.0,
41 min_num_observations=10):
42 """
43 filter_image(input_path, output_path, min_focal_length_ratio=0.1,
44 max_focal_length_ratio=10.0, max_extra_param=100.0, min_num_observations=10)
45 Function for the filtering of images
46
47 Args:
48 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
49 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
50 min_focal_length_ratio (float, optional, default=0.1): Minimum ratio of focal length over minimum sensor dimension.
51 max_focal_length_ratio (float, optional, default=10.0): Maximum ratio of focal length over maximum sensor dimension.
52 max_extra_param (float, optional, default=100.0): Maximum magnitude of each extra parameter.
53 min_num_observations (int, optional, default=10): The maximum number of observations.
54
55 Returns:
56 int
57 """
58 return filter_image(input_path=input_path,
59 output_path=output_path,
60 min_focal_length_ratio=min_focal_length_ratio,
61 max_focal_length_ratio=max_focal_length_ratio,
62 max_extra_param=max_extra_param,
63 min_num_observations=min_num_observations)
64
65
66def rectify_image(image_path,
67 input_path,
68 output_path,
69 stereo_pairs_list,
70 blank_pixels=0.0,
71 min_scale=0.2,
72 max_scale=2.0,
73 max_image_size=-1):
74 """
75 rectify_image(image_path, input_path, output_path, stereo_pairs_list, blank_pixels=0.0,
76 min_scale=0.2, max_scale=2.0, max_image_size=-1)
77 Function for the rectification of images
78
79 Args:
80 image_path (str)
81 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
82 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
83 stereo_pairs_list (str): A text file path containing stereo image pair names from.
84 The text file is expected to have one image pair per line, e.g.:
85 image_name1.jpg image_name2.jpg
86 image_name3.jpg image_name4.jpg
87 image_name5.jpg image_name6.jpg
88 blank_pixels (float, optional, default=0.0): The amount of blank pixels in the undistorted image in the range [0, 1].
89 min_scale (float, optional, default=0.2): Minimum scale change of camera used to satisfy the blank pixel constraint.
90 max_scale (float, optional, default=2.0): Maximum scale change of camera used to satisfy the blank pixel constraint.
91 max_image_size (int, optional, default=-1): Maximum image size in terms of width or height of the undistorted camera.
92
93 Returns:
94 int
95 """
96 return rectify_image(image_path=image_path,
97 input_path=input_path,
98 output_path=output_path,
99 stereo_pairs_list=stereo_pairs_list,
100 blank_pixels=blank_pixels,
101 min_scale=min_scale,
102 max_scale=max_scale,
103 max_image_size=max_image_size)
104
105
106def register_image(database_path, input_path, output_path):
107 """
108 register_image(database_path, input_path, output_path,
109 incremental_mapper_options=<cloudViewer.cuda.pybind.reconstruction.options.IncrementalMapperOptions object at 0x7f82ad55e810>)
110 Function for the registeration of images
111
112 Args:
113 database_path (str)
114 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
115 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
116 incremental_mapper_options (cloudViewer.reconstruction.options.IncrementalMapperOptions, optional,
117 default=<cloudViewer.cuda.pybind.reconstruction.options.IncrementalMapperOptions object at 0x7f82ad55e810>)
118
119 Returns:
120 int
121 """
122 incremental_mapper_options = cv3d.reconstruction.options.IncrementalMapperOptions(
123 )
124 return cv3d.reconstruction.image.register_image(
125 database_path=database_path,
126 input_path=input_path,
127 output_path=output_path,
128 incremental_mapper_options=incremental_mapper_options)
129
130
131def undistort_image(image_path,
132 input_path,
133 output_path,
134 image_list_path='',
135 output_type='COLMAP',
136 copy_policy='copy',
137 num_patch_match_src_images=20,
138 blank_pixels=0.0,
139 min_scale=0.2,
140 max_scale=2.0,
141 max_image_size=-1,
142 roi_min_x=0.0,
143 roi_min_y=0.0,
144 roi_max_x=1.0,
145 roi_max_y=1.0):
146 """
147 undistort_image(image_path, input_path, output_path, image_list_path='', output_type='COLMAP', copy_policy='copy',
148 num_patch_match_src_images=20.0, blank_pixels=0.0, min_scale=0.2, max_scale=2.0,
149 max_image_size=-1, roi_min_x=0.0, roi_min_y=0.0, roi_max_x=1.0, roi_max_y=1.0)
150 Function for the undistortion of images
151
152 Args:
153 image_path (str)
154 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
155 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
156 image_list_path (str, optional, default=''): A text file path containing image file path.
157 output_type (str, optional, default='COLMAP'): Output file format: supported values are {'COLMAP', 'PMVS', 'CMP-MVS'}.
158 copy_policy (str, optional, default='copy'): Supported copy policy are {copy, soft-link, hard-link}.
159 num_patch_match_src_images (int, optional, default=20.0): The number of patch match source images.
160 blank_pixels (float, optional, default=0.0): The amount of blank pixels in the undistorted image in the range [0, 1].
161 min_scale (float, optional, default=0.2): Minimum scale change of camera used to satisfy the blank pixel constraint.
162 max_scale (float, optional, default=2.0): Maximum scale change of camera used to satisfy the blank pixel constraint.
163 max_image_size (int, optional, default=-1): Maximum image size in terms of width or height of the undistorted camera.
164 roi_min_x (float, optional, default=0.0): The value in the range [0, 1] that define the ROI (region of interest) minimum x in original image.
165 roi_min_y (float, optional, default=0.0): The value in the range [0, 1] that define the ROI (region of interest) minimum y in original image.
166 roi_max_x (float, optional, default=1.0): The value in the range [0, 1] that define the ROI (region of interest) maximum x in original image.
167 roi_max_y (float, optional, default=1.0): The value in the range [0, 1] that define the ROI (region of interest) maximum y in original image.
168
169 Returns:
170 int
171 """
172 return cv3d.reconstruction.image.undistort_image(
173 image_path=image_path,
174 input_path=input_path,
175 output_path=output_path,
176 image_list_path=image_list_path,
177 output_type=output_type,
178 copy_policy=copy_policy,
179 num_patch_match_src_images=num_patch_match_src_images,
180 blank_pixels=blank_pixels,
181 min_scale=min_scale,
182 max_scale=max_scale,
183 max_image_size=max_image_size,
184 roi_min_x=roi_min_x,
185 roi_min_y=roi_min_y,
186 roi_max_x=roi_max_x,
187 roi_max_y=roi_max_y)
188
189
190def undistort_image_standalone(image_path,
191 input_path,
192 output_path,
193 blank_pixels=0.0,
194 min_scale=0.2,
195 max_scale=2.0,
196 max_image_size=-1,
197 roi_min_x=0.0,
198 roi_min_y=0.0,
199 roi_max_x=1.0,
200 roi_max_y=1.0):
201 """
202 undistort_image_standalone(image_path, input_path, output_path, blank_pixels=0.0, min_scale=0.2, max_scale=2.0,
203 max_image_size=-1, roi_min_x=0.0, roi_min_y=0.0, roi_max_x=1.0, roi_max_y=1.0)
204 Function for the standalone undistortion of images
205
206 Args:
207 image_path (str)
208 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
209 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
210 blank_pixels (float, optional, default=0.0): The amount of blank pixels in the undistorted image in the range [0, 1].
211 min_scale (float, optional, default=0.2): Minimum scale change of camera used to satisfy the blank pixel constraint.
212 max_scale (float, optional, default=2.0): Maximum scale change of camera used to satisfy the blank pixel constraint.
213 max_image_size (int, optional, default=-1): Maximum image size in terms of width or height of the undistorted camera.
214 roi_min_x (float, optional, default=0.0): The value in the range [0, 1] that define the ROI (region of interest) minimum x in original image.
215 roi_min_y (float, optional, default=0.0): The value in the range [0, 1] that define the ROI (region of interest) minimum y in original image.
216 roi_max_x (float, optional, default=1.0): The value in the range [0, 1] that define the ROI (region of interest) maximum x in original image.
217 roi_max_y (float, optional, default=1.0): The value in the range [0, 1] that define the ROI (region of interest) maximum y in original image.
218
219 Returns:
220 int
221 """
222 return cv3d.reconstruction.image.undistort_image_standalone(
223 image_path=image_path,
224 input_path=input_path,
225 output_path=output_path,
226 blank_pixels=blank_pixels,
227 min_scale=min_scale,
228 max_scale=max_scale,
229 max_image_size=max_image_size,
230 roi_min_x=roi_min_x,
231 roi_min_y=roi_min_y,
232 roi_max_x=roi_max_x,
233 roi_max_y=roi_max_y)
234
235
236if __name__ == '__main__':
237 np.random.seed(42)
238 cv3d.utility.set_verbosity_level(cv3d.utility.Debug)
239
240 DATABASE_PATH = "/media/asher/data/datasets/gui_test/database.db"
241 IMAGE_PATH = "/media/asher/data/datasets/dataset_monstree/mini6"
242 INPUT_PATH = "/media/asher/data/datasets/gui_test/sparse/0"
243
244 INPUT_FILE = "/media/asher/data/datasets/gui_test/input_file.txt"
245 OUTPUT_PATH = "/media/asher/data/datasets/gui_test/undistorted"
246 STANDALONE_OUTPUT_PATH = "/media/asher/data/datasets/gui_test/undistorted/standalone"
247
248 flag = undistort_image(image_path=IMAGE_PATH,
249 input_path=INPUT_PATH,
250 output_path=OUTPUT_PATH,
251 image_list_path="",
252 output_type='COLMAP')
253 if flag != 0:
254 print("undistort_image failed!")
255
256 flag = undistort_image_standalone(image_path=IMAGE_PATH,
257 input_path=INPUT_FILE,
258 output_path=STANDALONE_OUTPUT_PATH)
259 if flag != 0:
260 print("undistort_image_standalone failed!")
model.py#
1# ----------------------------------------------------------------------------
2# - CloudViewer: www.cloudViewer.org -
3# ----------------------------------------------------------------------------
4# Copyright (c) 2018-2024 www.cloudViewer.org
5# SPDX-License-Identifier: MIT
6# ----------------------------------------------------------------------------
7
8import numpy as np
9import cloudViewer as cv3d
10
11
12def align_model(input_path,
13 output_path,
14 database_path='',
15 ref_images_path='',
16 transform_path='',
17 alignment_type='plane',
18 max_error=0.0,
19 min_common_images=3,
20 robust_alignment=True,
21 estimate_scale=True):
22 """
23 align_model(input_path, output_path, database_path='', ref_images_path='', transform_path='',
24 alignment_type='plane', max_error=0.0, min_common_images=3, robust_alignment=True, estimate_scale=True)
25 Function for the alignment of model
26
27 Args:
28 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
29 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
30 database_path (str, optional, default=''): Path to database in which to store the extracted data.
31 ref_images_path (str, optional, default=''): Path to text file containing reference images per line.
32 transform_path (str, optional, default=''): The alignment transformation matrix saving path.
33 alignment_type (str, optional, default='plane'): Alignment type: supported values are {plane,
34 ecef, enu, enu-unscaled, custom}.
35 max_error (float, optional, default=0.0): Maximum error for a sample to be considered as an inlier.
36 Note that the residual of an estimator corresponds to a squared error.
37 min_common_images (int, optional, default=3): Minimum common images.
38 robust_alignment (bool, optional, default=True): Whether align robustly or not.
39 estimate_scale (bool, optional, default=True): Whether estimate scale or not.
40
41 Returns:
42 int
43 """
44 return cv3d.reconstruction.model.align_model(
45 input_path=input_path,
46 output_path=output_path,
47 database_path=database_path,
48 ref_images_path=ref_images_path,
49 transform_path=transform_path,
50 alignment_type=alignment_type,
51 max_error=max_error,
52 min_common_images=min_common_images,
53 robust_alignment=robust_alignment,
54 estimate_scale=estimate_scale)
55
56
57def align_model_orientation(image_path,
58 input_path,
59 output_path,
60 method='MANHATTAN-WORLD',
61 max_image_size=1024):
62 """
63 align_model_orientation(image_path, input_path, output_path, method='MANHATTAN-WORLD', max_image_size=1024)
64 Function for the orientation alignment of model
65
66 Args:
67 image_path (str)
68 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
69 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
70 method (str, optional, default='MANHATTAN-WORLD'):
71 The supported Model Orientation Alignment values are {MANHATTAN-WORLD, IMAGE-ORIENTATION}.
72 max_image_size (int, optional, default=1024): The maximum image size for line detection.
73
74 Returns:
75 int
76 """
77 return cv3d.reconstruction.model.align_model_orientation(
78 image_path=image_path,
79 input_path=input_path,
80 output_path=output_path,
81 method=method,
82 max_image_size=max_image_size)
83
84
85def analyze_model(input_path):
86 """
87 analyze_model(input_path)
88 Function for the analyse of model
89
90 Args:
91 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
92
93 Returns:
94 int
95 """
96 return cv3d.reconstruction.model.analyze_model(input_path=input_path)
97
98
99def compare_model(input_path1,
100 input_path2,
101 output_path='',
102 min_inlier_observations=0.3,
103 max_reproj_error=8.0):
104 """
105 compare_model(input_path1, input_path2, output_path='', min_inlier_observations=0.3, max_reproj_error=8.0)
106 Function for the comparison of model
107
108 Args:
109 input_path1 (str)
110 input_path2 (str)
111 output_path (str, optional, default=''): The output path containing target cameras.bin/txt,
112 images.bin/txt and points3D.bin/txt.
113 min_inlier_observations (float, optional, default=0.3): The threshold determines how many
114 observations in a common image must reproject within the given threshold..
115 max_reproj_error (float, optional, default=8.0): The Maximum re-projection error.
116
117 Returns:
118 int
119 """
120 return cv3d.reconstruction.model.compare_model(
121 input_path1=input_path1,
122 input_path2=input_path2,
123 output_path=output_path,
124 min_inlier_observations=min_inlier_observations,
125 max_reproj_error=max_reproj_error)
126
127
128def convert_model(input_path, output_path, output_type, skip_distortion=False):
129 """
130 convert_model(input_path, output_path, output_type, skip_distortion=False)
131 Function for the convertion of model
132
133 Args:
134 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
135 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
136 output_type (str): The supported output type values are {BIN, TXT, NVM, Bundler, VRML, PLY, R3D, CAM}.
137 skip_distortion (bool, optional, default=False): Whether skip distortion or no.
138 When skip_distortion == true it supports all camera models with the caveat that it's using the mean focal
139 length which will be inaccurate for camera models with two focal lengths and distortion.
140
141 Returns:
142 int
143 """
144 return cv3d.reconstruction.model.convert_model(
145 input_path=input_path,
146 output_path=output_path,
147 output_type=output_type,
148 skip_distortion=skip_distortion)
149
150
151def crop_model(input_path, output_path, boundary, gps_transform_path=''):
152 """
153 crop_model(input_path, output_path, boundary, gps_transform_path='')
154 Function for the cropping of model
155
156 Args:
157 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
158 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
159 boundary (str): The cropping boundary coordinates.
160 gps_transform_path (str, optional, default=''): The gps transformation parameters file path.
161
162 Returns:
163 int
164 """
165 return cv3d.reconstruction.model.crop_model(
166 input_path=input_path,
167 output_path=output_path,
168 boundary=boundary,
169 gps_transform_path=gps_transform_path)
170
171
172def merge_model(input_path1, input_path2, output_path, max_reproj_error=64.0):
173 """
174 merge_model(input_path1, input_path2, output_path, max_reproj_error=64.0)
175 Function for the merging of model
176
177 Args:
178 input_path1 (str)
179 input_path2 (str)
180 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
181 max_reproj_error (float, optional, default=64.0): The Maximum re-projection error.
182
183 Returns:
184 int
185 """
186 return cv3d.reconstruction.model.merge_model(
187 input_path1=input_path1,
188 input_path2=input_path2,
189 output_path=output_path,
190 max_reproj_error=max_reproj_error)
191
192
193def split_model(input_path,
194 output_path,
195 split_type,
196 split_params,
197 gps_transform_path='',
198 min_reg_images=10,
199 min_num_points=100,
200 overlap_ratio=0.0,
201 min_area_ratio=0.0,
202 num_threads=-1):
203 """
204 split_model(input_path, output_path, split_type, split_params, gps_transform_path='', min_reg_images=10,
205 min_num_points=100, overlap_ratio=0.0, min_area_ratio=0.0, num_threads=-1)
206 Function for the splitting of model
207
208 Args:
209 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
210 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
211 split_type (str): The supported split type values are {tiles, extent, parts}.
212 split_params (str): The split parameters file path.
213 gps_transform_path (str, optional, default=''): The gps transformation parameters file path.
214 min_reg_images (int, optional, default=10): The minimum number of reg images.
215 min_num_points (int, optional, default=100): The minimum number of points.
216 overlap_ratio (float, optional, default=0.0): The overlapped ratio.
217 min_area_ratio (float, optional, default=0.0): The minimum area ratio.
218 num_threads (int, optional, default=-1): The number of cpu thread.
219
220 Returns:
221 int
222 """
223 return cv3d.reconstruction.model.split_model(
224 input_path=input_path,
225 output_path=output_path,
226 split_type=split_type,
227 split_params=split_params,
228 gps_transform_path=gps_transform_path,
229 min_reg_images=min_reg_images,
230 min_num_points=min_num_points,
231 overlap_ratio=overlap_ratio,
232 min_area_ratio=min_area_ratio,
233 num_threads=num_threads)
234
235
236def transform_model(input_path, output_path, transform_path, is_inverse=False):
237 """
238 transform_model(input_path, output_path, transform_path, is_inverse=False)
239 Function for the transformation of model
240
241 Args:
242 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
243 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
244 transform_path (str): The alignment transformation matrix saving path.
245 is_inverse (bool, optional, default=False): Whether inverse or not.
246
247 Returns:
248 int
249 """
250 return cv3d.reconstruction.model.transform_model(
251 input_path=input_path,
252 output_path=output_path,
253 transform_path=transform_path,
254 is_inverse=is_inverse)
255
256
257if __name__ == '__main__':
258 np.random.seed(42)
259 cv3d.utility.set_verbosity_level(cv3d.utility.Debug)
260
261 DATABASE_PATH = "/media/asher/data/datasets/gui_test/sql.db"
262 INPUT_PATH = "/media/asher/data/datasets/gui_test/sparse/0"
263 OUTPUT_PATH = "/media/asher/data/datasets/gui_test/model_out"
264
265 flag = analyze_model(input_path=INPUT_PATH)
266 if flag != 0:
267 print("analyze_model failed!")
268
269 flag = align_model(input_path=INPUT_PATH,
270 output_path=OUTPUT_PATH,
271 database_path=DATABASE_PATH,
272 max_error=0.8,
273 alignment_type='plane')
274 if flag != 0:
275 print("align_model failed!")
mvs.py#
1# ----------------------------------------------------------------------------
2# - CloudViewer: www.cloudViewer.org -
3# ----------------------------------------------------------------------------
4# Copyright (c) 2018-2024 www.cloudViewer.org
5# SPDX-License-Identifier: MIT
6# ----------------------------------------------------------------------------
7
8import numpy as np
9import cloudViewer as cv3d
10
11
12def mesh_delaunay(input_path, output_path, input_type='dense'):
13 """
14 mesh_delaunay(input_path, output_path, input_type='dense', delaunay_meshing_options=<cloudViewer.cuda
15 .pybind.reconstruction.options.DelaunayMeshingOptions object at 0x7f82ad55e960>)
16 Function for the delaunay of mesh
17
18 Args:
19 input_path (str): Path to either the dense workspace folder or the sparse reconstruction.
20 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
21 input_type (str, optional, default='dense'): Supported input type values are {dense, sparse}.
22 delaunay_meshing_options (cloudViewer.reconstruction.options.DelaunayMeshingOptions, optional,
23 default=<cloudViewer.cuda.pybind.reconstruction.options.DelaunayMeshingOptions object at 0x7f82ad55e960>)
24
25 Returns:
26 int
27 """
28 delaunay_meshing_options = cv3d.reconstruction.options.DelaunayMeshingOptions(
29 )
30 return cv3d.reconstruction.mvs.mesh_delaunay(
31 input_path=input_path,
32 output_path=output_path,
33 input_type=input_type,
34 delaunay_meshing_options=delaunay_meshing_options)
35
36
37def poisson_mesh(input_path, output_path):
38 """
39 poisson_mesh(input_path, output_path, poisson_meshing_options=<cloudViewer.cuda.pybind.reconstruction.
40 options.PoissonMeshingOptions object at 0x7f82ad55ea40>)
41 Function for the poisson of mesh
42
43 Args:
44 input_path (str): Path to either the dense workspace folder or the sparse reconstruction.
45 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
46 poisson_meshing_options (cloudViewer.reconstruction.options.PoissonMeshingOptions, optional,
47 default=<cloudViewer.cuda.pybind.reconstruction.options.PoissonMeshingOptions object at 0x7f82ad55ea40>)
48
49 Returns:
50 int
51 """
52 poisson_meshing_options = cv3d.reconstruction.options.PoissonMeshingOptions(
53 )
54 return cv3d.reconstruction.mvs.poisson_mesh(
55 input_path=input_path,
56 output_path=output_path,
57 poisson_meshing_options=poisson_meshing_options)
58
59
60def stereo_fuse(workspace_path,
61 output_path,
62 bbox_path='',
63 stereo_input_type='geometric',
64 output_type='PLY',
65 workspace_format='COLMAP',
66 pmvs_option_name='option-all'):
67 """
68 stereo_fuse(workspace_path, output_path, bbox_path='', stereo_input_type='geometric', output_type='PLY',
69 workspace_format='COLMAP', pmvs_option_name='option-all',
70 stereo_fusion_options=<cloudViewer.cuda.pybind.reconstruction.options.StereoFusionOptions object at 0x7f82ad55ea78>)
71 Function for the stereo path-match of mesh
72
73 Args:
74 workspace_path (str): Path to the folder containing the undistorted images.
75 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
76 bbox_path (str, optional, default=''): The bounds file path.
77 stereo_input_type (str, optional, default='geometric'): Supported stereo input type values are {photometric, geometric}.
78 output_type (str, optional, default='PLY'): Supported output type values are {BIN, TXT, PLY}.
79 workspace_format (str, optional, default='COLMAP'): Supported workspace format values are {COLMAP, PMVS}.
80 pmvs_option_name (str, optional, default='option-all'): The pmvs option name.
81 stereo_fusion_options (cloudViewer.reconstruction.options.StereoFusionOptions, optional,
82 default=<cloudViewer.cuda.pybind.reconstruction.options.StereoFusionOptions object at 0x7f82ad55ea78>)
83
84 Returns:
85 int
86 """
87
88 stereo_fusion_options = cv3d.reconstruction.options.StereoFusionOptions()
89 return cv3d.reconstruction.mvs.stereo_fuse(
90 workspace_path=workspace_path,
91 output_path=output_path,
92 bbox_path=bbox_path,
93 stereo_input_type=stereo_input_type,
94 output_type=output_type,
95 workspace_format=workspace_format,
96 pmvs_option_name=pmvs_option_name,
97 stereo_fusion_options=stereo_fusion_options)
98
99
100def stereo_patch_match(workspace_path,
101 config_path='',
102 workspace_format='COLMAP',
103 pmvs_option_name='option-all'):
104 """
105 stereo_patch_match(workspace_path, config_path='', workspace_format='COLMAP', pmvs_option_name='option-all',
106 patch_match_options=<cloudViewer.cuda.pybind.reconstruction.options.PatchMatchOptions object at 0x7f82ad55e9d0>)
107 Function for the stereo path-match of mesh
108
109 Args:
110 workspace_path (str): Path to the folder containing the undistorted images.
111 config_path (str, optional, default=''): The config path.
112 workspace_format (str, optional, default='COLMAP'): Supported workspace format values are {COLMAP, PMVS}.
113 pmvs_option_name (str, optional, default='option-all'): The pmvs option name.
114 patch_match_options (cloudViewer.reconstruction.options.PatchMatchOptions, optional,
115 default=<cloudViewer.cuda.pybind.reconstruction.options.PatchMatchOptions object at 0x7f82ad55e9d0>)
116
117 Returns:
118 int
119 """
120 patch_match_options = cv3d.reconstruction.options.PatchMatchOptions()
121 return cv3d.reconstruction.mvs.stereo_patch_match(
122 workspace_path=workspace_path,
123 config_path=config_path,
124 workspace_format=workspace_format,
125 pmvs_option_name=pmvs_option_name,
126 patch_match_options=patch_match_options)
127
128
129if __name__ == '__main__':
130 np.random.seed(42)
131 cv3d.utility.set_verbosity_level(cv3d.utility.Debug)
132
133 DELAUNAY_INPUT_PATH = "/media/asher/data/datasets/gui_test/dense/0"
134 DELAUNAY_OUTPUT_PATH = "/media/asher/data/datasets/gui_test/meshes/delaunay_meshed.ply"
135
136 POISSON_INPUT_PATH = "/media/asher/data/datasets/gui_test/dense/0/fused.ply"
137 POISSON_OUTPUT_PATH = "/media/asher/data/datasets/gui_test/meshes/poisson_meshed.ply"
138
139 flag = mesh_delaunay(input_path=DELAUNAY_INPUT_PATH,
140 output_path=DELAUNAY_OUTPUT_PATH,
141 input_type='dense')
142 if flag != 0:
143 print("mesh_delaunay failed!")
144 else:
145 print("mesh_delaunay successfully!")
146
147 flag = poisson_mesh(input_path=POISSON_INPUT_PATH,
148 output_path=POISSON_OUTPUT_PATH)
149 if flag != 0:
150 print("poisson_mesh failed!")
151 else:
152 print("poisson_mesh successfully!")
sfm.py#
1# ----------------------------------------------------------------------------
2# - CloudViewer: www.cloudViewer.org -
3# ----------------------------------------------------------------------------
4# Copyright (c) 2018-2024 www.cloudViewer.org
5# SPDX-License-Identifier: MIT
6# ----------------------------------------------------------------------------
7
8import numpy as np
9import cloudViewer as cv3d
10
11
12def auto_reconstruction(workspace_path,
13 image_path,
14 mask_path='',
15 vocab_tree_path='',
16 data_type='individual',
17 quality='high',
18 mesher='poisson',
19 camera_model='SIMPLE_RADIAL',
20 single_camera=False,
21 sparse=True,
22 dense=True,
23 num_threads=-1,
24 use_gpu=True,
25 gpu_index='-1'):
26 """
27 auto_reconstruction(workspace_path, image_path, mask_path='', vocab_tree_path='', data_type='individual',
28 quality='high', mesher='poisson', camera_model='SIMPLE_RADIAL', single_camera=False,
29 sparse=True, dense=True, num_threads=-1, use_gpu=True, gpu_index='-1')
30 Function for the automatic reconstruction
31
32 Args:
33 workspace_path (str): The path to the workspace folder in which all results are stored.
34 image_path (str): The path to the image folder which are used as input.
35 mask_path (str, optional, default=''): The path to the mask folder which are used as input.
36 vocab_tree_path (str, optional, default=''): The path to the vocabulary tree for feature matching.
37 data_type (str, optional, default='individual'): Supported data types are {individual, video, internet}.
38 quality (str, optional, default='high'): Supported quality types are {low, medium, high, extreme}.
39 mesher (str, optional, default='poisson'): Supported meshing algorithm types are {poisson, delaunay}.
40 camera_model (str, optional, default='SIMPLE_RADIAL'): Which camera model to use for images.
41 single_camera (bool, optional, default=False): Whether to use shared intrinsics or not.
42 sparse (bool, optional, default=True): Whether to perform sparse mapping.
43 dense (bool, optional, default=True): Whether to perform dense mapping.
44 num_threads (int, optional, default=-1): The number of threads to use in all stages.
45 use_gpu (bool, optional, default=True): Whether to use the GPU in feature extraction and matching.
46 gpu_index (str, optional, default='-1'): Index of the GPU used for GPU stages. For multi-GPU computation,
47 you should separate multiple GPU indices by comma, e.g., ``0,1,2,3``. By default, all GPUs will be used in all stages.
48
49 Returns:
50 int
51 """
52 return cv3d.reconstruction.sfm.auto_reconstruction(
53 workspace_path=workspace_path,
54 image_path=image_path,
55 mask_path=mask_path,
56 vocab_tree_path=vocab_tree_path,
57 data_type=data_type,
58 quality=quality,
59 mesher=mesher,
60 camera_model=camera_model,
61 single_camera=single_camera,
62 sparse=sparse,
63 dense=dense,
64 num_threads=num_threads,
65 use_gpu=use_gpu,
66 gpu_index=gpu_index)
67
68
69def bundle_adjustment(input_path, output_path):
70 """
71 bundle_adjustment(input_path, output_path, bundle_adjustment_options=<cloudViewer.cuda.pybind.
72 reconstruction.options.BundleAdjustmentOptions object at 0x7f82ad55ec38>)
73 Function for the bundle adjustment
74
75 Args:
76 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
77 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
78 bundle_adjustment_options (cloudViewer.reconstruction.options.BundleAdjustmentOptions, optional,
79 default=<cloudViewer.cuda.pybind.reconstruction.options.BundleAdjustmentOptions object at 0x7f82ad55ec38>)
80
81 Returns:
82 int
83 """
84 bundle_adjustment_options = cv3d.reconstruction.options.BundleAdjustmentOptions(
85 )
86 return cv3d.reconstruction.sfm.bundle_adjustment(
87 input_path=input_path,
88 output_path=output_path,
89 bundle_adjustment_options=bundle_adjustment_options)
90
91
92def extract_color(image_path, input_path, output_path):
93 """
94 extract_color(image_path, input_path, output_path)
95 Function for the extraction of images color
96
97 Args:
98 image_path (str): The path to the image folder which are used as input.
99 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
100 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
101
102 Returns:
103 int
104 """
105 return cv3d.reconstruction.sfm.extract_color(image_path=image_path,
106 input_path=input_path,
107 output_path=output_path)
108
109
110def filter_points(input_path,
111 output_path,
112 min_track_len=2,
113 max_reproj_error=4.0,
114 min_tri_angle=1.5):
115 """
116 filter_points(input_path, output_path, min_track_len=2, max_reproj_error=4.0, min_tri_angle=1.5)
117 Function for the filtering of points
118
119 Args:
120 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
121 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
122 min_track_len (int, optional, default=2): The minimum track length.
123 max_reproj_error (float, optional, default=4.0): The maximum re-projection error.
124 min_tri_angle (float, optional, default=1.5): The minimum tri angle.
125
126 Returns:
127 int
128 """
129 return cv3d.reconstruction.sfm.filter_points(
130 input_path=input_path,
131 output_path=output_path,
132 min_track_len=min_track_len,
133 max_reproj_error=max_reproj_error,
134 min_tri_angle=min_tri_angle)
135
136
137def hierarchical_mapper(database_path,
138 image_path,
139 output_path,
140 num_workers=-1,
141 image_overlap=50,
142 leaf_max_num_images=500):
143 """
144 hierarchical_mapper(database_path, image_path, output_path, num_workers=-1, image_overlap=50,
145 leaf_max_num_images=500, incremental_mapper_options=<cloudViewer.cuda.pybind.
146 reconstruction.options.IncrementalMapperOptions object at 0x7f82ad55eca8>)
147 Function for the hierarchical mapper
148
149 Args:
150 database_path (str): Path to database in which to store the extracted data
151 image_path (str): The path to the image folder which are used as input.
152 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
153 num_workers (int, optional, default=-1): The number of workers used to reconstruct clusters in parallel.
154 image_overlap (int, optional, default=50): The number of overlapping images between child clusters.
155 leaf_max_num_images (int, optional, default=500): The maximum number of images in a leaf node cluster,
156 otherwise the cluster is further partitioned using the given branching factor.
157 Note that a cluster leaf node will have at most `leaf_max_num_images + overlap`
158 images to satisfy the overlap constraint.
159 incremental_mapper_options (cloudViewer.reconstruction.options.IncrementalMapperOptions, optional,
160 default=<cloudViewer.cuda.pybind.reconstruction.options.IncrementalMapperOptions object at 0x7f82ad55eca8>)
161
162 Returns:
163 int
164 """
165 incremental_mapper_options = cv3d.reconstruction.options.IncrementalMapperOptions(
166 )
167 return cv3d.reconstruction.sfm.hierarchical_mapper(
168 database_path=database_path,
169 image_path=image_path,
170 output_path=output_path,
171 num_workers=num_workers,
172 image_overlap=image_overlap,
173 leaf_max_num_images=leaf_max_num_images,
174 incremental_mapper_options=incremental_mapper_options)
175
176
177def normal_mapper(database_path,
178 image_path,
179 input_path,
180 output_path,
181 image_list_path=''):
182 """
183 normal_mapper(database_path, image_path, input_path, output_path, image_list_path='',
184 incremental_mapper_options=<cloudViewer.cuda.pybind.reconstruction.options.IncrementalMapperOptions object at 0x7f82ad55ec70>)
185 Function for the normal mapper
186
187 Args:
188 database_path (str): Path to database in which to store the extracted data
189 image_path (str): The path to the image folder which are used as input.
190 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
191 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
192 image_list_path (str, optional, default=''): A text file path containing image file path.
193 incremental_mapper_options (cloudViewer.reconstruction.options.IncrementalMapperOptions, optional,
194 default=<cloudViewer.cuda.pybind.reconstruction.options.IncrementalMapperOptions object at 0x7f82ad55ec70>)
195
196 Returns:
197 int
198 """
199 incremental_mapper_options = cv3d.reconstruction.options.IncrementalMapperOptions(
200 )
201 return cv3d.reconstruction.sfm.normal_mapper(
202 database_path=database_path,
203 image_path=image_path,
204 input_path=input_path,
205 output_path=output_path,
206 image_list_path=image_list_path,
207 incremental_mapper_options=incremental_mapper_options)
208
209
210def rig_bundle_adjustment(input_path,
211 output_path,
212 rig_config_path,
213 estimate_rig_relative_poses=True,
214 refine_relative_poses=True):
215 """
216 rig_bundle_adjustment(input_path, output_path, rig_config_path, estimate_rig_relative_poses=True,
217 refine_relative_poses=True, bundle_adjustment_options=<cloudViewer.cuda.
218 pybind.reconstruction.options.BundleAdjustmentOptions object at 0x7f82ad55ed18>)
219 Function for the rig bundle adjustment
220
221 Args:
222 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
223 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
224 rig_config_path (str): The rig config path.
225 estimate_rig_relative_poses (bool, optional, default=True): Whether to estimate rig relative poses.
226 refine_relative_poses (bool, optional, default=True): Whether to optimize the relative poses of the camera rigs.
227 bundle_adjustment_options (cloudViewer.reconstruction.options.BundleAdjustmentOptions, optional,
228 default=<cloudViewer.cuda.pybind.reconstruction.options.BundleAdjustmentOptions object at 0x7f82ad55ed18>)
229
230 Returns:
231 int
232 """
233 bundle_adjustment_options = cv3d.reconstruction.options.BundleAdjustmentOptions(
234 )
235 return cv3d.reconstruction.sfm.rig_bundle_adjustment(
236 input_path=input_path,
237 output_path=output_path,
238 rig_config_path=rig_config_path,
239 estimate_rig_relative_poses=estimate_rig_relative_poses,
240 refine_relative_poses=refine_relative_poses,
241 bundle_adjustment_options=bundle_adjustment_options)
242
243
244def triangulate_points(database_path,
245 image_path,
246 input_path,
247 output_path,
248 clear_points=False):
249 """
250 triangulate_points(database_path, image_path, input_path, output_path, clear_points=False,
251 incremental_mapper_options=<cloudViewer.cuda.pybind.reconstruction.options.IncrementalMapperOptions object at 0x7f82ad55ece0>)
252 Function for the triangulation of points
253
254 Args:
255 database_path (str): Path to database in which to store the extracted data
256 image_path (str): The path to the image folder which are used as input.
257 input_path (str): The input path containing cameras.bin/txt, images.bin/txt and points3D.bin/txt.
258 output_path (str): The output path containing target cameras.bin/txt, images.bin/txt and points3D.bin/txt.
259 clear_points (bool, optional, default=False): Whether to clear all existing points and observations.
260 incremental_mapper_options (cloudViewer.reconstruction.options.IncrementalMapperOptions, optional,
261 default=<cloudViewer.cuda.pybind.reconstruction.options.IncrementalMapperOptions object at 0x7f82ad55ece0>)
262
263 Returns:
264 int
265 """
266 incremental_mapper_options = cv3d.reconstruction.options.IncrementalMapperOptions(
267 )
268 return cv3d.reconstruction.sfm.triangulate_points(
269 database_path=database_path,
270 image_path=image_path,
271 input_path=input_path,
272 output_path=output_path,
273 clear_points=clear_points,
274 incremental_mapper_options=incremental_mapper_options)
275
276
277if __name__ == "__main__":
278 np.random.seed(42)
279 cv3d.utility.set_verbosity_level(cv3d.utility.Debug)
280
281 WORSPACE_PATH = "/media/asher/data/datasets/test"
282 IMAGE_PATH = "/media/asher/data/datasets/dataset_monstree/mini6"
283 VOCAB_TREE_PATH = "/media/asher/data/datasets/vocab_tree/vocab_tree_flickr100K_words32K.bin"
284
285 flag = auto_reconstruction(WORSPACE_PATH, IMAGE_PATH, VOCAB_TREE_PATH)
286 if flag != 0:
287 print("clean_database failed!")
vocab_tree.py#
1# ----------------------------------------------------------------------------
2# - CloudViewer: www.cloudViewer.org -
3# ----------------------------------------------------------------------------
4# Copyright (c) 2018-2024 www.cloudViewer.org
5# SPDX-License-Identifier: MIT
6# ----------------------------------------------------------------------------
7
8import numpy as np
9import cloudViewer as cv3d
10
11
12def build_vocab_tree(database_path,
13 vocab_tree_path,
14 num_visual_words=65536,
15 num_checks=256,
16 branching=256,
17 num_iterations=11,
18 max_num_images=-1):
19 """
20 build_vocab_tree(database_path, vocab_tree_path, num_visual_words=65536, num_checks=256,
21 branching=256, num_iterations=11, max_num_images=-1, num_threads=-1)
22 Function for the building of vocabulary tree
23
24 Args:
25 database_path (str): Path to database in which to store the extracted data
26 vocab_tree_path (str): The vocabulary tree path.
27 num_visual_words (int, optional, default=65536): The desired number of visual words,
28 i.e. the number of leaf node clusters. Note that the actual number of visual words might be less.
29 num_checks (int, optional, default=256): The number of checks in the nearest neighbor search.
30 branching (int, optional, default=256): The branching factor of the hierarchical k-means tree.
31 num_iterations (int, optional, default=11): The number of iterations for the clustering.
32 max_num_images (int, optional, default=-1): The maximum number of images.
33
34 Returns:
35 int
36 """
37 return cv3d.reconstruction.vocab_tree.build_vocab_tree(
38 database_path=database_path,
39 vocab_tree_path=vocab_tree_path,
40 num_visual_words=num_visual_words,
41 num_checks=num_checks,
42 branching=branching,
43 num_iterations=num_iterations,
44 max_num_images=max_num_images)
45
46
47def retrieve_vocab_tree(database_path,
48 vocab_tree_path,
49 output_index_path='',
50 query_image_list_path='',
51 database_image_list_path='',
52 max_num_images=-1,
53 num_neighbors=5,
54 num_checks=256,
55 num_images_after_verification=0,
56 max_num_features=-1):
57 """
58 retrieve_vocab_tree(database_path, vocab_tree_path, output_index_path='', query_image_list_path='',
59 database_image_list_path='', max_num_images=-1, num_neighbors=5, num_checks=256,
60 num_images_after_verification=0, max_num_features=-1, num_threads=-1)
61 Function for the retrieve of vocabulary tree
62
63 Args:
64 database_path (str): Path to database in which to store the extracted data
65 vocab_tree_path (str): The vocabulary tree path.
66 output_index_path (str, optional, default=''): The output index path.
67 query_image_list_path (str, optional, default=''): The query image list path.
68 database_image_list_path (str, optional, default=''): The database image list path.
69 max_num_images (int, optional, default=-1): The maximum number of images.
70 num_neighbors (int, optional, default=5): The number of nearest neighbor visual words
71 that each feature descriptor is assigned to.
72 num_checks (int, optional, default=256): The number of checks in the nearest neighbor search.
73 num_images_after_verification (int, optional, default=0):
74 Whether to perform spatial verification after image retrieval.
75 max_num_features (int, optional, default=-1): The maximum number of features.
76
77 Returns:
78 int
79 """
80 return cv3d.reconstruction.vocab_tree.retrieve_vocab_tree(
81 database_path=database_path,
82 vocab_tree_path=vocab_tree_path,
83 output_index_path=output_index_path,
84 query_image_list_path=query_image_list_path,
85 database_image_list_path=database_image_list_path,
86 max_num_images=max_num_images,
87 num_neighbors=num_neighbors,
88 num_checks=num_checks,
89 num_images_after_verification=num_images_after_verification,
90 max_num_features=max_num_features)
91
92
93if __name__ == '__main__':
94 np.random.seed(42)
95 cv3d.utility.set_verbosity_level(cv3d.utility.Debug)
96
97 DATABASE_PATH = "/media/asher/data/datasets/gui_test/database.db"
98 OUTPUT_PATH = "/media/asher/data/datasets/gui_test/out/vocab_tree_index.bin"
99 VOCAB_TREE_PATH = "/media/asher/data/datasets/vocab_tree/vocab_tree_flickr100K_words32K.bin"
100
101 flag = build_vocab_tree(database_path=DATABASE_PATH,
102 vocab_tree_path=VOCAB_TREE_PATH)
103 if flag != 0:
104 print("build_vocab_tree failed!")
105
106 flag = retrieve_vocab_tree(database_path=DATABASE_PATH,
107 vocab_tree_path=VOCAB_TREE_PATH,
108 output_index_path=OUTPUT_PATH)
109 if flag != 0:
110 print("retrieve_vocab_tree failed!")