LensCalibrationTest.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import argparse
  2. import sys
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. #parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  6. #parser.add_argument("-f", "--file", type=str, help="Voxel file (.vxl)", required=True)
  7. #args = parser.parse_args()
  8. ## Voxel-A lens
  9. k1 = -0.1583968
  10. k2 = 0.06113919
  11. k3 = 0.09898978
  12. p1 = 0.001591975
  13. p2 = -0.0001962754
  14. x = np.linspace(0, 0.9, 200)
  15. y = 0
  16. r2 = x*x
  17. r4 = r2*r2
  18. r6 = r4*r2
  19. x1 = x*(1 + k1*r2 + k2*r4 + k3*r6) + 2*p1*x*y + p2*(r2 + 2*x*x)
  20. y1 = y*(1 + k1*r2 + k2*r4 + k3*r6) + p1*(r2 + 2*y*y) + p2*x*y
  21. ## Tintin lens
  22. k1 = 0.909882
  23. k2 = -3.559455
  24. k3 = 3.626591
  25. p1 = 0.047604
  26. p2 = -0.005546
  27. x2 = x*(1 + k1*r2 + k2*r4 + k3*r6) + 2*p1*x*y + p2*(r2 + 2*x*x)
  28. y2 = y*(1 + k1*r2 + k2*r4 + k3*r6) + p1*(r2 + 2*y*y) + p2*x*y
  29. r2 = x1*x1 + y1*y1
  30. r4 = r2*r2
  31. r6 = r4*r2
  32. x3 = x1*(1 + k1*r2 + k2*r4 + k3*r6) + 2*p1*x1*y1 + p2*(r2 + 2*x1*x1)
  33. y3 = y1*(1 + k1*r2 + k2*r4 + k3*r6) + p1*(r2 + 2*y1*y1) + p2*x1*y1
  34. plt.plot(x, x1, x, x2, 'r', x, x3, 'k')
  35. plt.grid(True)
  36. plt.legend(['Voxel-A', 'TintinCDK', 'Distorted to Corrected'])
  37. plt.show()