Converting Hugin pto lens parameters to rig_spec.xml compatible ones.

6 photos are stitched into a panorama.
For this I have a working Hugin .pto template file. It stitches well with the Hugin workflow.

The pto template needs to be converted to rig_spec.xml for the new NVIDIA VRWorks 360 workflow which expects parameters from a successful OpenCV calibration while I need to use the values from the pto template.

Example for just a single source image from the pto file:

# image lines
#-hugin  cropFactor=6.4
i w2560 h1920 f3 v118.537956650131 Ra0 Rb0 Rc0 Rd0 Re0 Eev14 Er1 Eb1 r94.606329053126 p-12.649859004975 y-70.9201302573682 TrX0 TrY0 TrZ0 Tpy0 Tpp0 j0 a-0.0128476647589936 b0 c-0.0263288686271355 d24.148292065888 e-42.619120967644 g0 t0 Va1 Vb0 Vc0 Vd0 Vx0 Vy0  Vm5 n"2.jpg"

The same data entered into the NVIDIA VRWorks rig_spec.xml equivalent.

<camera width="2560" height="1920" layout="equatorial">
	<input_calib_file name="2.png"/>
	<pose>
		<rotation roll_deg="94.606329053126" pitch_deg="-12.649859004975" yaw_deg="-70.9201302573682"/>
		<translation x_cm="0.0" y_cm="0.0" z_cm="0.0"/>
	</pose>        
	<optics>
		<focal_length focal_pixels="1257"/>
		<principal_point center_offset_x="0.0" center_offset_y="0.0"/>
		<lens type="fisheye" k1="0.0" k2="0.0" k3="0.0" k4="0.0"/>
		<fisheye_radius radius_pixels="1400"/>
	</optics>		
</camera>

Solved:
rig_spec.xml - .pto
roll_deg - same as r pto value
pitch_deg - same as p pto value
yaw_deg - same as y pto value
center_offset_x - same as d pto value
center_offset_y - same as e pto value
radius_pixels - 1400 pixels is a decent approximation

My challenge:
Can someone point me into the right direction to figure out how to properly calculate/convert focal_pixels and the k1, k2, k3, k4 parameters ?

focal_pixels
k1 - Most likely corresponds to c pto value. In Hugin this parameter is called: Radial distortion ©.
k2 - Most likely corresponds to a pto value. In Hugin this parameter is called: Radial distortion (a).
k3 -
k4 -

Here is how the k parameters are described in the VRWorks documentation: “Radial distortion coefficients for fisheye”.

For focal_pixels I have tried the following:

Sensor size in mm:
Horizontal (hfov): 5.7 mm
Vertical (vfov): 4.28 mm

Sensor size in pixel:
Horizontal (w): 2592 pixel
Vertical (h): 1944 pixel

cropFactor: 6.4
hfov: corresponds to `v` PTO value.

var d = Math.sqrt(36.0 * 36.0 + 24.0 * 24.0) / cropFactor;
var r = w / h; //“r” is not a radius.
var sensorSizeX = d / Math.sqrt(1 + 1 / (r * r));
var sensorSizeY = sensorSizeX / r;

var focalLengthMm = sensorSizeX / (hfov / 180 * Math.PI);
var focalLengthPx = (focalLengthMm / 5.70) * w;

This gives a value close to correct one, but the images are still not properly aligned when stitching with the rig_spec.xml file.

I have also tried:
focal_pixel = (image_width_in_pixels * 0.5) / tan(FOV * 0.5 * PI/180)
But this gives an even worse result, the value is too low.

If you need the source images, the .pto file, or the lens parameters they all can be found in this archive:
https://drive.google.com/open?id=1OzKGh8oieXIIMCn5Ou22rakxHY2TpFxB0V_x7OBmuyc