-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_cygnus_blensor.py
187 lines (159 loc) · 5.63 KB
/
gen_cygnus_blensor.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
import glob
import json
import os
import shutil
import subprocess
import time
import blensor
import boto3
import bpy
import numpy as np
import starfish
import starfish.annotation
import tqdm
from mathutils import Euler, Quaternion
"""
0: timestamp
1: yaw,
2:pitch
3:distance,
4:distance_noise
5-7: x,y,z
8-10:x_noise,y_noise,z_noise
11:object_id
12:255*color[0]
13:255*color[1]
14:255*color[2]
15:idx
"""
def generate(ds_name, bucket, tags):
"""for i, frame in enumerate(sequence):
frame.setup(bpy.data.scenes['Real'], bpy.data.objects["Cygnus_Real"], bpy.data.objects["Camera_Real"], bpy.data.objects["Sun"])
scanner = bpy.data.objects["Camera_Real"]
blensor.blendodyne.scan_advanced(scanner, rotation_speed = 5.0,
simulation_fps=24, angle_resolution = 0.12,
max_distance = 120, evd_file= f"/home/jdeutsch/blensor_1.0.18-RC10_x64/{os.basename(fname)}.numpy",
noise_mu=0.0, noise_sigma=0.03, start_angle = 0.0,
end_angle = 360.0,
add_blender_mesh = False,
add_noisy_blender_mesh = False)"""
"""blensor.blendodyne.scan_advanced(scanner, rotation_speed = 5.0,
simulation_fps=24, angle_resolution = 0.12,
max_distance = 120, evd_file= f"/home/jdeutsch/blensor_1.0.18-RC10_x64/{os.path.basename(meta).split('.')[0]}.numpy",
noise_mu=0.0, noise_sigma=0.03, start_angle = 0.0,
end_angle = 360.0,
add_blender_mesh = False,
add_noisy_blender_mesh = False)"""
start_time = time.time()
# check if folder exists in render, if not, create folder
try:
os.mkdir(os.path.join("render", ds_name))
except Exception:
pass
data_storage_path = os.path.join(os.getcwd(), "render", ds_name)
# copy script and write to data storage path
with open(os.path.abspath(__file__), 'r') as f:
code = f.read()
with open(os.path.join(data_storage_path, 'gen_code_blensor.py'), 'w') as f:
f.write(code)
download_meta(ds_name, bucket)
metas = sorted(glob.glob(os.path.join(data_storage_path, "meta_*")))
scanner_type = "tof"
for meta in tqdm.tqdm(metas):
with open(meta, "r") as f:
info = json.load(f)
print(meta)
uuid = os.path.basename(meta).split(".")[0][5:]
print(uuid)
frame = starfish.Frame(
pose=Quaternion(info["pose"]),
lighting=Quaternion(info["lighting"]),
background=Quaternion([1,0,0,0]),
distance=info["distance"],
offset=info["offset"],
)
frame.setup(
bpy.data.scenes["Real"],
bpy.data.objects["Cygnus_Real"],
bpy.data.objects["Camera_Real"],
bpy.data.objects["Sun"],
)
scanner = bpy.data.objects["Camera_Real"]
output_path = os.path.join(data_storage_path, f"lidar_{uuid}.numpy")
blensor.tof.scan_advanced(
scanner,
max_distance=200,
evd_file=output_path,
noise_mu=0.0,
noise_sigma=0.1,
tof_res_x=176,
tof_res_y=144,
lens_angle_w=43.6,
lens_angle_h=34.6,
flength=10.0,
add_blender_mesh=False,
add_noisy_blender_mesh=False,
)
blensor_renamed = os.path.join(data_storage_path, f"lidar_{uuid}00000.numpy")
shutil.move(blensor_renamed, output_path)
info["lidar_tags"] = tags
with open(meta, "w") as f:
f.write(json.dumps(info, indent=2))
f.write('\n')
upload(ds_name, bucket)
print(f"Done! Took: {time.time()-start_time} seconds.")
def download_meta(ds_name, bucket_name):
print("\n\n______________STARTING DOWNLOAD_________")
subprocess.run(
[
"aws",
"s3",
"sync",
f"s3://{bucket_name}/{ds_name}",
os.path.join("render", ds_name),
"--exclude", "*",
"--include", "meta_*",
],
check=True # with out check=True, downloads all files
)
def upload(ds_name, bucket_name):
print("\n\n______________STARTING UPLOAD_________")
subprocess.run(
[
"aws",
"s3",
"sync",
os.path.join("render", ds_name),
f"s3://{bucket_name}/{ds_name}",
]
)
def validate_bucket_name(bucket_name):
s3t = boto3.resource("s3")
# check if bucket exits. If not return false
if s3t.Bucket(bucket_name).creation_date is None:
print("...Bucket does not exist, enter valid bucket name...")
return False
else:
# if exists, return true
print("...bucket exists....")
return True
def main():
try:
os.mkdir("render")
except Exception:
pass
yes = {"y", "Y", "yes"}
bucket_name = input("*> Enter Bucket name: ")
# check if bucket name valid
while not validate_bucket_name(bucket_name):
bucket_name = input("*> Enter Bucket name: ")
dataset_name = input("*> Enter name of Imageset: ")
print(
" Note: rendered images will be stored in a directory called 'render' in the same local directory this script is located under the directory name you specify."
)
tags = input("*> Enter tags for the batch seperated with space: ")
tags_list = tags.split()
generate(dataset_name, bucket_name, tags_list)
print("______________DONE EXECUTING______________")
if __name__ == "__main__":
main()