You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "basicCameraInfo.h"
  2. #include "basicLogCollection.h"
  3. float calcFOV_inch(float SensorSize, float FN)
  4. {
  5. /*
  6. The calculator below converts between the focal length f and the field of view (FOV) of a rectilinear lens.
  7. The formula that it implements is FOV = 2 arctan (x / (2 f)), where x is the diagonal of the film.
  8. The FOV is measured across the frame's diagonal, and is therefore smaller across the horizontal dimension,
  9. and even smaller across the vertical dimension.
  10. */
  11. return 2.0f * atanf((SensorSize * 25.4f) / (2.0f * FN));
  12. }
  13. float calcFOV_mm(float SensorSize, float FN)
  14. {
  15. /*
  16. The calculator below converts between the focal length f and the field of view (FOV) of a rectilinear lens.
  17. The formula that it implements is FOV = 2 arctan (x / (2 f)), where x is the diagonal of the film.
  18. The FOV is measured across the frame's diagonal, and is therefore smaller across the horizontal dimension,
  19. and even smaller across the vertical dimension.
  20. */
  21. return 2.0f * atanf(SensorSize / (2.0f * FN));
  22. }
  23. float calcMaxDistance_inch(float SensorSize, float MaxFL, int ImageWidth)
  24. {
  25. float tFOV, tt;
  26. tFOV = calcFOV_inch(SensorSize, MaxFL);
  27. tt = tFOV / ((float) ImageWidth); // 1 pixel
  28. return .01 / tanf(tt / 2.0f); // return Distance in meters to see 1 cm as 1 pixel
  29. }
  30. float calcMaxDistance_mm(float SensorSize, float MaxFL, int ImageWidth)
  31. {
  32. float tFOV, tt;
  33. tFOV = calcFOV_mm(SensorSize, MaxFL);
  34. tt = tFOV / ((float) ImageWidth); // 1 pixel
  35. return .01 / tanf(tt / 2.0f); // return Distance in meters to see 1 cm as 1 pixel
  36. }
  37. float calcMinDistance_mm(float SensorSize, float MaxFL, int ImageWidth)
  38. {
  39. float tFOV, tt;
  40. tFOV = calcFOV_mm(SensorSize, MaxFL);
  41. tt = tFOV / ((float) ImageWidth); // 1 pixel
  42. return (0.01 / tanf(tt / 2.0f)) / 1.5f; // return Distance in meters to see 150 cm as ImageWidth pixel
  43. }
  44. float calcFL_deg(float SensorSize, float FOV)
  45. {
  46. return SensorSize / (2.0f * tanf(/*deg2rad(*/ FOV /*)*/ / 2.0f));
  47. }
  48. float calcCFL(float SensorSize, float Distance, int ImageWidth)
  49. {
  50. float tFOV = 2.0f * atanf(0.01f / Distance);
  51. return calcFL_deg(SensorSize, tFOV) / 1000.0f; // in mm
  52. }