-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometry_utils.py
33 lines (27 loc) · 999 Bytes
/
geometry_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
import numpy as np
def pixel_coord_np(width, height):
"""
Pixel in homogenous coordinate
Returns:
Pixel coordinate: [3, width * height]
"""
x = np.linspace(0, width - 1, width).astype(np.int)
y = np.linspace(0, height - 1, height).astype(np.int)
[x, y] = np.meshgrid(x, y)
return np.vstack((x.flatten(), y.flatten(), np.ones_like(x.flatten())))
def intrinsic_from_fov(height, width, fov=90):
"""
Basic Pinhole Camera Model
intrinsic params from fov and sensor width and height in pixels
Returns:
K: [4, 4]
"""
px, py = (width / 2, height / 2)
hfov = fov / 360. * 2. * np.pi
fx = width / (2. * np.tan(hfov / 2.))
vfov = 2. * np.arctan(np.tan(hfov / 2) * height / width)
fy = height / (2. * np.tan(vfov / 2.))
return np.array([[fx, 0, px, 0.],
[0, fy, py, 0.],
[0, 0, 1., 0.],
[0., 0., 0., 1.]])