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.

68 lines
2.4 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 .01f / 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 .01f / tanf(tt / 2.0f); // return Distance in meters to see 1 cm as 1 pixel
  36. // i.e the (ImageWidth / 100) meters in width will be visible in the frame
  37. }
  38. float calcMinDistance_mm(float SensorSize, float MaxFL, int ImageWidth)
  39. {
  40. float tFOV, tt;
  41. tFOV = calcFOV_mm(SensorSize, MaxFL);
  42. tt = tFOV / ((float) ImageWidth); // 1 pixel
  43. //There was error of calculating
  44. return (.01f / tanf(tt / 2.0f)) /(ImageWidth/150.0f); // return Distance in meters to see 150 cm as ImageWidth pixels
  45. // i.e 1.5 meters in width will be visible in the frame
  46. }
  47. float calcFL_deg(float SensorSize, float FOV)
  48. {
  49. return SensorSize / (2.0f * tanf( deg2rad(FOV) / 2.0f));
  50. }
  51. float calcFL_rad(float SensorSize, float FOV)
  52. {
  53. return SensorSize / (2.0f * tanf( FOV / 2.0f));
  54. }
  55. float calcCFL(float SensorSize, float Distance )
  56. {
  57. float tFOV = 2.0f * atanf(.01f / Distance);
  58. return calcFL_rad(SensorSize, tFOV) / 1000.0f; // in mm
  59. }