4
4
# This source code is licensed under the BSD-style license found in the
5
5
# LICENSE file in the root directory of this source tree.
6
6
7
+ import logging
7
8
import math
8
9
from typing import Optional , Tuple
9
10
10
11
import torch
11
12
from pytorch3d .common .compat import eigh
13
+ from pytorch3d .implicitron .tools import utils
12
14
from pytorch3d .implicitron .tools .circle_fitting import fit_circle_in_3d
13
15
from pytorch3d .renderer import look_at_view_transform , PerspectiveCameras
14
16
from pytorch3d .transforms import Scale
15
17
16
18
19
+ logger = logging .getLogger (__name__ )
20
+
21
+
17
22
def generate_eval_video_cameras (
18
23
train_cameras ,
19
24
n_eval_cams : int = 100 ,
@@ -27,6 +32,7 @@ def generate_eval_video_cameras(
27
32
infer_up_as_plane_normal : bool = True ,
28
33
traj_offset : Optional [Tuple [float , float , float ]] = None ,
29
34
traj_offset_canonical : Optional [Tuple [float , float , float ]] = None ,
35
+ remove_outliers_rate : float = 0.0 ,
30
36
) -> PerspectiveCameras :
31
37
"""
32
38
Generate a camera trajectory rendering a scene from multiple viewpoints.
@@ -50,9 +56,16 @@ def generate_eval_video_cameras(
50
56
Active for the `trajectory_type="circular"`.
51
57
scene_center: The center of the scene in world coordinates which all
52
58
the cameras from the generated trajectory look at.
59
+ remove_outliers_rate: the number between 0 and 1; if > 0,
60
+ some outlier train_cameras will be removed from trajectory estimation;
61
+ the filtering is based on camera center coordinates; top and
62
+ bottom `remove_outliers_rate` cameras on each dimension are removed.
53
63
Returns:
54
64
Dictionary of camera instances which can be used as the test dataset
55
65
"""
66
+ if remove_outliers_rate > 0.0 :
67
+ train_cameras = _remove_outlier_cameras (train_cameras , remove_outliers_rate )
68
+
56
69
if trajectory_type in ("figure_eight" , "trefoil_knot" , "figure_eight_knot" ):
57
70
cam_centers = train_cameras .get_camera_center ()
58
71
# get the nearest camera center to the mean of centers
@@ -167,6 +180,20 @@ def generate_eval_video_cameras(
167
180
return test_cameras
168
181
169
182
183
+ def _remove_outlier_cameras (
184
+ cameras : PerspectiveCameras , outlier_rate : float
185
+ ) -> PerspectiveCameras :
186
+ keep_indices = utils .get_inlier_indicators (
187
+ cameras .get_camera_center (), dim = 0 , outlier_rate = outlier_rate
188
+ )
189
+ clean_cameras = cameras [keep_indices ]
190
+ logger .info (
191
+ "Filtered outlier cameras when estimating the trajectory: "
192
+ f"{ len (cameras )} → { len (clean_cameras )} "
193
+ )
194
+ return clean_cameras
195
+
196
+
170
197
def _disambiguate_normal (normal , up ):
171
198
up_t = torch .tensor (up ).to (normal )
172
199
flip = (up_t * normal ).sum ().sign ()
0 commit comments