-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcamera_utils.py
42 lines (35 loc) · 1.13 KB
/
camera_utils.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
import torch
import numpy as np
trans_t = lambda t : torch.Tensor([
[1,0,0,0],
[0,1,0,0],
[0,0,1,t],
[0,0,0,1]]).float()
trans_t2 = lambda t : torch.Tensor([
[1,0,0,0],
[0,1,0,t],
[0,0,1,0],
[0,0,0,1]]).float()
rot_phi = lambda phi : torch.Tensor([
[1,0,0,0],
[0,np.cos(phi),-np.sin(phi),0],
[0,np.sin(phi), np.cos(phi),0],
[0,0,0,1]]).float()
rot_theta = lambda th : torch.Tensor([
[np.cos(th),0,-np.sin(th),0],
[0,1,0,0],
[np.sin(th),0, np.cos(th),0],
[0,0,0,1]]).float()
rot_z = lambda z : torch.Tensor([
[np.cos(z),-np.sin(z),0,0],
[np.sin(z), np.cos(z),0,0],
[0,0,1,0],
[0,0,0,1]]).float()
def pose_spherical(theta, phi, z, radius, translate):
c2w = trans_t(radius)
c2w = rot_phi(phi/180.*np.pi) @ c2w
c2w = rot_theta(theta/180.*np.pi) @ c2w
c2w = rot_z(z/180.*np.pi) @ c2w
c2w = trans_t2(translate) @ c2w #the scene is not centered. The transformations above rotates the camera spirally around the origin. So here we translate the spiral.
c2w = torch.Tensor(np.array([[-1,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,1]])) @ c2w
return c2w