Spaces:
Build error
Build error
File size: 1,890 Bytes
fd5e0f7 |
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 |
import numpy as np
from ops.sky import Sky_Seg_Tool
from ops.utils import dpt2xyz
from .spiral import spiral_camera_poses
class Trajectory_Generation():
def __init__(self,
scene = None,
method = 'spiral') -> None:
'''
method = 'spiral'/ rot' / 'spin'
'''
self._method = method
self.forward_ratio = scene.traj_forward_ratio
self.backward_ratio = scene.traj_backward_ratio
self.min_percentage = scene.traj_min_percentage
self.max_percentage = scene.traj_max_percentage
def _radius(self, xyz):
# get range
_min = np.percentile(xyz,self.min_percentage,axis=0)
_max = np.percentile(xyz,self.max_percentage,axis=0)
_range = _max - _min
# set radius to mean range of three axes
self.radius = np.mean(_range)
def _traj_spiral(self, nframe):
trajs = spiral_camera_poses(nframe, self.radius, self.forward_ratio, self.backward_ratio)
return trajs
def __call__(self, nframe, xyz):
if xyz.ndim > 2:
xyz = xyz.reshape(-1,3)
self._radius(xyz)
if self._method == 'rot':
trajs = self._traj_rot(nframe)
elif self._method == 'spin':
trajs = self._traj_spin(nframe)
elif self._method == 'spiral':
trajs = self._traj_spiral(nframe)
else:
raise TypeError('method = rot / spiral')
return trajs
def _generate_trajectory(cfg, scene, nframes=None):
method = scene.traj_type
nframe = cfg.scene.traj.n_sample*6 if nframes is None else nframes
sky,dpt,intrinsic = scene.frames[0].sky,scene.frames[0].dpt,scene.frames[0].intrinsic
xyz = dpt2xyz(dpt,intrinsic)
init_xyz = xyz[~sky]
generator = Trajectory_Generation(scene=scene,method=method)
traj = generator(nframe,init_xyz)
return traj |