1、理论知识
![](https://i-blog.csdnimg.cn/blog_migrate/f3ea63454f72f8f4d038fd787aaa644a.png)
从图可以很直观的看出fov_y 焦距f和图像高之间的关系,tan(fov_y/2) = 2/h / fy.所以正反向的转换过程就很直接。f以pixel为单位。
2、代码
def camera_intrinsic_transform(fov_x=45,fov_y=60,pixel_width=320,pixel_height=240):
camera_intrinsics = np.zeros((3,4))
camera_intrinsics[2,2] = 1
camera_intrinsics[0,0] = (pixel_width/2.0)/math.tan(math.radians(fov_x/2.0))
camera_intrinsics[0,2] = pixel_width/2.0
camera_intrinsics[1,1] = (pixel_height/2.0)/math.tan(math.radians(fov_y/2.0))
camera_intrinsics[1,2] = pixel_height/2.0
return camera_intrinsics
def camera_intrinsic_fov(intrinsic):
#计算FOV
w, h = intrinsic[0][2]*2, intrinsic[1][2]*2
fx, fy = intrinsic[0][0], intrinsic[1][1]
# Go
fov_x = np.rad2deg(2 * np.arctan2(w, 2 * fx))
fov_y = np.rad2deg(2 * np.arctan2(h, 2 * fy))
return fov_x, fov_y