gopro/gpmf-parser

Questions about lens distortion parameters

Opened this issue · 1 comments

Hi :)
I'd like to use the POLY values to implement the lens distortion model, but I have a few questions:

  1. POLY - are r0-r4 the radial coefficients and r5-r6 the tangential coefficients, or are all 7 radial?
  2. POLY - coefficients are for distortion or undistortion? It seems like they are for undistortion, is this correct?
  3. Are the POLY coefficients for any specific model, or just generic polynomial? They are supposed to be used to distort the radius?
  4. I understand that the ZFOV is diagonal FOV that can be used to calculate the camera intrinsic matrix. However, when calculating focal length and horizontal/vertical FOV, I have different values than listed here
  5. What's ZMPL?
  6. Are there any other GPMF fields relevant for lens distortions?

Code for 4.:

function focalLengthFromFOV(diagonalFOV, width, height) {
    const diagonalFOVRadians = diagonalFOV * Math.PI / 180;
    const diagonal = Math.sqrt(width * width + height * height);
    return diagonal / (2 * Math.tan(diagonalFOVRadians / 2));
}
function calculateFOVs(fovDiag, width, height) {
    const fovDiagRadians = fovDiag * Math.PI / 180;
    const diagonal = Math.sqrt(width * width + height * height);
    const horizontalFOVRadians = 2 * Math.atan((width / 2) / (diagonal / 2 / Math.tan(fovDiagRadians / 2)));
    const verticalFOVRadians = 2 * Math.atan((height / 2) / (diagonal / 2 / Math.tan(fovDiagRadians / 2)));

    return [ horizontalFOVRadians * 180 / Math.PI, verticalFOVRadians * 180 / Math.PI ];
}

for ZFOV = 133.39 and 5312x2988 this yields 1312 pixel focal length and 127 HFOV and 97 VFOV, but the specs page lists 118 and 69 when the diagonal fov is 133. What am I missing here?

POLY r0-r7 are all radial coefficients of increasingly powers.

The curve is normalized radius to world angle. ZMPL is required to normalize the input. It is little odd. r = x.ZMPL

In desmos
Screenshot_20240519-125127

If you set x=1 the output will be half ZFOV.

If you set x=0.752 (if a calculated correctly) this would be HFOV position, and I get 122 degrees. Matching the spec.