15
15
16
16
17
17
def undistort_reconstruction (tracks_manager , reconstruction , data , udata ):
18
+ image_format = data .config ["undistorted_image_format" ]
18
19
urec = types .Reconstruction ()
19
20
urec .points = reconstruction .points
20
21
utracks_manager = pysfm .TracksManager ()
@@ -24,18 +25,20 @@ def undistort_reconstruction(tracks_manager, reconstruction, data, udata):
24
25
if shot .camera .projection_type == "perspective" :
25
26
camera = perspective_camera_from_perspective (shot .camera )
26
27
urec .add_camera (camera )
27
- subshots = [get_shot_with_different_camera (urec , shot , camera )]
28
+ subshots = [get_shot_with_different_camera (urec , shot , camera , image_format )]
28
29
elif shot .camera .projection_type == "brown" :
29
30
camera = perspective_camera_from_brown (shot .camera )
30
31
urec .add_camera (camera )
31
- subshots = [get_shot_with_different_camera (urec , shot , camera )]
32
+ subshots = [get_shot_with_different_camera (urec , shot , camera , image_format )]
32
33
elif shot .camera .projection_type in ["fisheye" , "fisheye_opencv" ]:
33
34
camera = perspective_camera_from_fisheye (shot .camera )
34
35
urec .add_camera (camera )
35
- subshots = [get_shot_with_different_camera (urec , shot , camera )]
36
+ subshots = [get_shot_with_different_camera (urec , shot , camera , image_format )]
36
37
elif pygeometry .Camera .is_panorama (shot .camera .projection_type ):
37
38
subshot_width = int (data .config ["depthmap_resolution" ])
38
- subshots = perspective_views_of_a_panorama (shot , subshot_width , urec )
39
+ subshots = perspective_views_of_a_panorama (
40
+ shot , subshot_width , urec , image_format
41
+ )
39
42
40
43
for subshot in subshots :
41
44
if tracks_manager :
@@ -46,6 +49,13 @@ def undistort_reconstruction(tracks_manager, reconstruction, data, udata):
46
49
if tracks_manager :
47
50
udata .save_undistorted_tracks_manager (utracks_manager )
48
51
52
+ udata .save_undistorted_shot_ids (
53
+ {
54
+ shot_id : [ushot .id for ushot in ushots ]
55
+ for shot_id , ushots in undistorted_shots .items ()
56
+ }
57
+ )
58
+
49
59
return undistorted_shots
50
60
51
61
@@ -122,25 +132,26 @@ def undistort_image(shot, undistorted_shots, original, interpolation, max_size):
122
132
123
133
projection_type = shot .camera .projection_type
124
134
if projection_type in ["perspective" , "brown" , "fisheye" , "fisheye_opencv" ]:
125
- new_camera = undistorted_shots [0 ].camera
135
+ [undistorted_shot ] = undistorted_shots
136
+ new_camera = undistorted_shot .camera
126
137
height , width = original .shape [:2 ]
127
138
map1 , map2 = pygeometry .compute_camera_mapping (
128
139
shot .camera , new_camera , width , height
129
140
)
130
141
undistorted = cv2 .remap (original , map1 , map2 , interpolation )
131
- return {shot .id : scale_image (undistorted , max_size )}
142
+ return {undistorted_shot .id : scale_image (undistorted , max_size )}
132
143
elif pygeometry .Camera .is_panorama (projection_type ):
133
144
subshot_width = undistorted_shots [0 ].camera .width
134
145
width = 4 * subshot_width
135
146
height = width // 2
136
147
image = cv2 .resize (original , (width , height ), interpolation = interpolation )
137
148
mint = cv2 .INTER_LINEAR if interpolation == cv2 .INTER_AREA else interpolation
138
149
res = {}
139
- for subshot in undistorted_shots :
150
+ for undistorted_shot in undistorted_shots :
140
151
undistorted = render_perspective_view_of_a_panorama (
141
- image , shot , subshot , mint
152
+ image , shot , undistorted_shot , mint
142
153
)
143
- res [subshot .id ] = scale_image (undistorted , max_size )
154
+ res [undistorted_shot .id ] = scale_image (undistorted , max_size )
144
155
return res
145
156
else :
146
157
raise NotImplementedError (
@@ -161,8 +172,16 @@ def scale_image(image, max_size):
161
172
return cv2 .resize (image , (width , height ), interpolation = cv2 .INTER_NEAREST )
162
173
163
174
164
- def get_shot_with_different_camera (urec , shot , camera ):
165
- new_shot = urec .create_shot (shot .id , shot .camera .id , shot .pose )
175
+ def add_image_format_extension (shot_id , image_format ):
176
+ if shot_id .endswith (f".{ image_format } " ):
177
+ return shot_id
178
+ else :
179
+ return f"{ shot_id } .{ image_format } "
180
+
181
+
182
+ def get_shot_with_different_camera (urec , shot , camera , image_format ):
183
+ new_shot_id = add_image_format_extension (shot .id , image_format )
184
+ new_shot = urec .create_shot (new_shot_id , shot .camera .id , shot .pose )
166
185
new_shot .metadata = shot .metadata
167
186
return new_shot
168
187
@@ -206,6 +225,7 @@ def perspective_camera_from_fisheye_opencv(fisheye_opencv):
206
225
camera .height = fisheye_opencv .height
207
226
return camera
208
227
228
+
209
229
def perspective_camera_from_fisheye62 (fisheye62 ):
210
230
"""Create a perspective camera from a fisheye extended."""
211
231
camera = pygeometry .Camera .create_perspective (
@@ -216,7 +236,8 @@ def perspective_camera_from_fisheye62(fisheye62):
216
236
camera .height = fisheye62 .height
217
237
return camera
218
238
219
- def perspective_views_of_a_panorama (spherical_shot , width , reconstruction ):
239
+
240
+ def perspective_views_of_a_panorama (spherical_shot , width , reconstruction , image_format ):
220
241
"""Create 6 perspective views of a panorama."""
221
242
camera = pygeometry .Camera .create_perspective (0.5 , 0.0 , 0.0 )
222
243
camera .id = "perspective_panorama_camera"
@@ -240,9 +261,12 @@ def perspective_views_of_a_panorama(spherical_shot, width, reconstruction):
240
261
pose = pygeometry .Pose ()
241
262
pose .set_rotation_matrix (R )
242
263
pose .set_origin (o )
264
+ shot_id = add_image_format_extension (
265
+ f"{ spherical_shot .id } _perspective_view_{ name } " , image_format
266
+ )
243
267
shots .append (
244
268
reconstruction .create_shot (
245
- "{}_perspective_view_{}" . format ( spherical_shot . id , name ) ,
269
+ shot_id ,
246
270
camera .id ,
247
271
pose ,
248
272
)
0 commit comments