-
Notifications
You must be signed in to change notification settings - Fork 46
/
sem3d_gen_images.py
215 lines (186 loc) · 8.54 KB
/
sem3d_gen_images.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import numpy as np
import os
import scipy.misc
from tqdm import *
# load the configuration file and define variables
print("Loading configuration file")
import argparse
import json
parser = argparse.ArgumentParser(description='Semantic3D')
parser.add_argument('--config', type=str, default="config.json", metavar='N',
help='config file')
args = parser.parse_args()
json_data=open(args.config).read()
config = json.loads(json_data)
if config["training"]:
input_dir = config["train_input_dir"]
directory = config["train_results_root_dir"]
else:
input_dir = config["test_input_dir"]
directory = config["test_results_root_dir"]
cam_number = config["cam_number"]
create_mesh = config["create_mesh"]
create_views = config["create_views"]
create_images = config["create_images"]
voxels_directory = os.path.join(directory,"voxels")
image_directory = os.path.join(directory,config["images_dir"])
voxel_size = config["voxel_size"]
imsize = config["imsize"]
# create directories if not already existing
if not os.path.exists(directory):
os.makedirs(directory)
if not os.path.exists(voxels_directory):
os.makedirs(voxels_directory)
if not os.path.exists(image_directory):
os.makedirs(image_directory)
if(config["training"]):
# training filenames
filenames = [
"bildstein_station1_xyz_intensity_rgb",
"bildstein_station3_xyz_intensity_rgb",
"bildstein_station5_xyz_intensity_rgb",
"domfountain_station1_xyz_intensity_rgb",
"domfountain_station2_xyz_intensity_rgb",
"domfountain_station3_xyz_intensity_rgb",
"neugasse_station1_xyz_intensity_rgb",
"sg27_station1_intensity_rgb",
"sg27_station2_intensity_rgb",
"sg27_station4_intensity_rgb",
"sg27_station5_intensity_rgb",
"sg27_station9_intensity_rgb",
"sg28_station4_intensity_rgb",
"untermaederbrunnen_station1_xyz_intensity_rgb",
"untermaederbrunnen_station3_xyz_intensity_rgb"
]
else: # testing filename
filenames = [
"birdfountain_station1_xyz_intensity_rgb",
"castleblatten_station1_intensity_rgb",
"castleblatten_station5_xyz_intensity_rgb",
"marketplacefeldkirch_station1_intensity_rgb",
"marketplacefeldkirch_station4_intensity_rgb",
"marketplacefeldkirch_station7_intensity_rgb",
"sg27_station10_intensity_rgb",
"sg27_station3_intensity_rgb",
"sg27_station6_intensity_rgb",
"sg27_station8_intensity_rgb",
"sg28_station2_intensity_rgb",
"sg28_station5_xyz_intensity_rgb",
"stgallencathedral_station1_intensity_rgb",
"stgallencathedral_station3_intensity_rgb",
"stgallencathedral_station6_intensity_rgb"
]
if create_mesh:
# import pointcloud_tools.lib.python.PcTools as PcTls
import semantic3D_utils.lib.python.semantic3D as Sem3D
for filename in filenames:
print(filename)
# create the mesher
# semantizer = PcTls.Semantic3D()
# semantizer.set_voxel_size(voxel_size)
#loading data and voxelization
print(" -- loading data")
if config["training"]:
# semantizer.load_Sem3D_labels(os.path.join(input_dir,filename+".txt"),
# os.path.join(input_dir,filename+".labels"))
Sem3D.semantic3d_load_from_txt_voxel_labels(os.path.join(input_dir,filename+".txt"),
os.path.join(input_dir,filename+".labels"),
os.path.join(voxels_directory, filename+"_voxels.txt"),
voxel_size
)
else:
# semantizer.load_Sem3D(os.path.join(input_dir,filename+".txt"))
Sem3D.semantic3d_load_from_txt_voxel(os.path.join(input_dir,filename+".txt"),
os.path.join(voxels_directory, filename+"_voxels.txt"),
voxel_size
)
print(" -- computing attributes data")
# attributes
Sem3D.semantic3d_estimate_attributes(os.path.join(voxels_directory, filename+"_voxels.txt"),
os.path.join(voxels_directory, filename+"_voxels_composite.txt"),
200
)
# create mesh
print(" -- computing mesh data")
Sem3D.semantic3d_create_mesh(
os.path.join(voxels_directory, filename+"_voxels.txt"),
os.path.join(voxels_directory, filename+"_voxels_composite.txt"),
os.path.join(voxels_directory, filename+"_voxels_mesh.ply"),
os.path.join(voxels_directory, filename+"_voxels_composite_mesh.ply"),
os.path.join(voxels_directory, filename+"_voxels_labels_mesh.ply"),
os.path.join(voxels_directory, filename+"_voxels_faces.txt"),
config["training"]
)
# # estimate normals
# print(" -- estimating normals")
# semantizer.estimate_normals_regression(100)
# print(" -- estimating noise")
# semantizer.estimate_noise_radius(1.)
# print(" -- estimating Z orient")
# semantizer.estimate_z_orient()
# #save points and labels
# print(" -- saving plys")
# semantizer.savePLYFile(os.path.join(voxels_directory,filename+"_points.ply"))
# semantizer.savePLYFile_composite(os.path.join(voxels_directory,filename+"_composite.ply"))
# if config["training"]:
# semantizer.savePLYFile_labels(os.path.join(voxels_directory,filename+"_labels.ply"))
# print(" -- building mesh")
# semantizer.build_mesh(False)
# semantizer.save_mesh(os.path.join(voxels_directory,filename+"_mesh.ply"))
# semantizer.save_mesh_composite(os.path.join(voxels_directory,filename+"_mesh_composite.ply"))
# if config["training"]:
# semantizer.save_mesh_labels(os.path.join(voxels_directory,filename+"_mesh_labels.ply"))
# print(" -- extracting vertices")
# vertices = semantizer.get_vertices_numpy()
# np.savez(os.path.join(voxels_directory,filename+"_vertices"), vertices)
# print(" -- extracting normals")
# normals = semantizer.get_normals_numpy()
# np.savez(os.path.join(voxels_directory,filename+"_normals"), normals)
# print(" -- extracting faces")
# faces = semantizer.get_faces_numpy()
# np.savez(os.path.join(voxels_directory,filename+"_faces"), faces)
# print(" -- extracting colors")
# colors = semantizer.get_colors_numpy()
# np.savez(os.path.join(voxels_directory,filename+"_colors"), colors)
# print(" -- extracting composite")
# composite = semantizer.get_composite_numpy()
# np.savez(os.path.join(voxels_directory,filename+"_composite"), composite)
# if config["training"]:
# print(" -- extracting labels")
# labels = semantizer.get_labels_numpy()
# np.savez(os.path.join(voxels_directory,filename+"_labels"), labels)
# print(" -- extracting labels colors")
# labelsColors = semantizer.get_labelsColors_numpy()
# np.savez(os.path.join(voxels_directory,filename+"_labelsColors"), labelsColors)
if create_views:
from python.viewGenerator import ViewGeneratorLauncher
from python.viewGenerator import ViewGeneratorNoDisplay as ViewGenerator
launcher = ViewGeneratorLauncher()
for filename in filenames:
print(filename)
view_gen = ViewGenerator()
view_gen.initialize_acquisition(
voxels_directory,
image_directory,
filename
)
view_gen.set_camera_generator(ViewGenerator.cam_generator_random_vertical_cone)
view_gen.opts["imsize"]= imsize
view_gen.generate_cameras_scales(cam_number, distances=[5,10,20])
view_gen.init()
launcher.launch(view_gen)
if create_images:
from python.imageGenerator import ImageGenerator
for filename in filenames:
print(filename)
# generate images
print(" -- generating images")
im_gen = ImageGenerator()
if config["training"]:
im_gen.set_isTraining(True)
im_gen.initialize_acquisition(
voxels_directory,
image_directory,
filename
)
im_gen.generate_images()