#include "basicCameraInfo.h" #include "basicLogCollection.h" float calcFOV_inch(float SensorSize, float FN) { /* The calculator below converts between the focal length f and the field of view (FOV) of a rectilinear lens. The formula that it implements is FOV = 2 arctan (x / (2 f)), where x is the diagonal of the film. The FOV is measured across the frame's diagonal, and is therefore smaller across the horizontal dimension, and even smaller across the vertical dimension. */ return 2.0f * atanf((SensorSize * 25.4f) / (2.0f * FN)); } float calcFOV_mm(float SensorSize, float FN) { /* The calculator below converts between the focal length f and the field of view (FOV) of a rectilinear lens. The formula that it implements is FOV = 2 arctan (x / (2 f)), where x is the diagonal of the film. The FOV is measured across the frame's diagonal, and is therefore smaller across the horizontal dimension, and even smaller across the vertical dimension. */ return 2.0f * atanf(SensorSize / (2.0f * FN)); } float calcMaxDistance_inch(float SensorSize, float MaxFL, int ImageWidth) { float tFOV, tt; tFOV = calcFOV_inch(SensorSize, MaxFL); tt = tFOV / ((float) ImageWidth); // 1 pixel return .01f / tanf(tt / 2.0f); // return Distance in meters to see 1 cm as 1 pixel } float calcMaxDistance_mm(float SensorSize, float MaxFL, int ImageWidth) { float tFOV, tt; tFOV = calcFOV_mm(SensorSize, MaxFL); tt = tFOV / ((float) ImageWidth); // 1 pixel return .01f / tanf(tt / 2.0f); // return Distance in meters to see 1 cm as 1 pixel // i.e the (ImageWidth / 100) meters in width will be visible in the frame } float calcMinDistance_mm(float SensorSize, float MaxFL, int ImageWidth) { float tFOV, tt; tFOV = calcFOV_mm(SensorSize, MaxFL); tt = tFOV / ((float) ImageWidth); // 1 pixel //There was error of calculating return (.01f / tanf(tt / 2.0f)) /(ImageWidth/150.0f); // return Distance in meters to see 150 cm as ImageWidth pixels // i.e 1.5 meters in width will be visible in the frame } float calcFL_deg(float SensorSize, float FOV) { return SensorSize / (2.0f * tanf( deg2rad(FOV) / 2.0f)); } float calcFL_rad(float SensorSize, float FOV) { return SensorSize / (2.0f * tanf( FOV / 2.0f)); } float calcCFL(float SensorSize, float Distance ) { float tFOV = 2.0f * atanf(.01f / Distance); return calcFL_rad(SensorSize, tFOV) / 1000.0f; // in mm }