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.

52 lines
2.1 KiB

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