def construct_K(image_size, focal_len=None, fov_degrees=None, fov_radians=None):
""" create calibration matrix K using the image size and focal length or field of view angle
Assumes 0 skew and principal point at center of image
Note that image_size = (width, height)
Note that fov is assumed to be measured horizontally
"""
if not np.sum([focal_len is not None, fov_degrees is not None, fov_radians is not None]) == 1:
raise Exception('Specify exactly one of [focal_len, fov_degrees, fov_radians]')
if fov_degrees is not None:
fov_radians = np.deg2rad(fov_degrees)
if fov_radians is not None:
focal_len = image_size[0] / (2.0 * np.tan(fov_radians/2.0))
K = np.array([[focal_len, 0, image_size[0]/2.0], [0, focal_len, image_size[1]/2.0], [0, 0, 1]])
return K
评论列表
文章目录