Skip to content

Instantly share code, notes, and snippets.

@r7vme
Last active June 18, 2019 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r7vme/01f8418f788c2402b621fb5e83e999bf to your computer and use it in GitHub Desktop.
Save r7vme/01f8418f788c2402b621fb5e83e999bf to your computer and use it in GitHub Desktop.
Find camera intrinsics matrix from FOV and resolution
#!/usr/bin/env python3
import math
# input
VFOV=60
H=480
W=856
aspRatio=W/H
VFOV_rad=VFOV*math.pi/180.
HFOV_rad= 2 * math.atan( math.tan(VFOV_rad/2) * aspRatio )
fx = (W/2)/math.tan(HFOV_rad/2)
fy = (H/2)/math.tan(VFOV_rad/2)
u0 = W/2
v0 = H/2
print("fx:\t\t\t%.2f" % fx)
print("fy (same as fx):\t%.2f" % fy)
print("u0:\t\t\t%.2f" % u0)
print("v0:\t\t\t%.2f" % v0)
print()
print("Intrinsics matrix:")
print()
print("%.2f\t%.2f\t%.2f" % (fx,0,u0))
print("%.2f\t%.2f\t%.2f" % (0,fy,v0))
print("%.2f\t%.2f\t%.2f" % (0,0,1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment