Converting Hugin pto lens parameters to OpenCV compatible ones

357 views
Skip to first unread message

Iacovlev Pavel

unread,
Oct 16, 2017, 8:38:36 AM10/16/17
to hugin and other free panoramic software

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.
My challenges are marked bold:

```

<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 ?


k1 - Most likely corresponds to `c` pto value. In Hugin this parameter is called: Radial distortion (c).

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


T. Modes

unread,
Oct 16, 2017, 1:31:43 PM10/16/17
to hugin and other free panoramic software


Am Montag, 16. Oktober 2017 14:38:36 UTC+2 schrieb Iacovlev Pavel:

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 ?


k1 - Most likely corresponds to `c` pto value. In Hugin this parameter is called: Radial distortion (c).

k2 - Most likely corresponds to `a` pto value. In Hugin this parameter is called: Radial distortion (a).

k3 -

k4 -


This was already discussed. Short answer: this is not easily possible (and there is no 1:1 correspondence). see https://groups.google.com/d/msg/hugin-ptx/-r-yk8zI6Gs/p-1BP-ihBQAJ

Iacovlev Pavel

unread,
Oct 16, 2017, 2:38:24 PM10/16/17
to hugin and other free panoramic software
Thank you for the info. I will try the suggestions from the link you provided, maybe it will be a fit (or at least good enough) for my case also, since I only use the `a` and `c` parameters.
Any idea if my method for calculating `focal_pixels` is correct?  

T. Modes

unread,
Oct 16, 2017, 4:02:01 PM10/16/17
to hugin and other free panoramic software


Am Montag, 16. Oktober 2017 20:38:24 UTC+2 schrieb Iacovlev Pavel:
Thank you for the info. I will try the suggestions from the link you provided, maybe it will be a fit (or at least good enough) for my case also, since I only use the `a` and `c` parameters.
Any idea if my method for calculating `focal_pixels` is correct?  
It depends on the projection. Hugin has different fisheye projection and each one has slightly different formulas. And I think the second equation you wrote is for the rectilinear projection.

Pavel Iacovlev

unread,
Oct 16, 2017, 4:12:05 PM10/16/17
to hugi...@googlegroups.com
The projection is equirectangular, I have attached a screenshot of the project tab from Hugin.

--
A list of frequently asked questions is available at: http://wiki.panotools.org/Hugin_FAQ
---
You received this message because you are subscribed to a topic in the Google Groups "hugin and other free panoramic software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hugin-ptx/ZbrCrgLdNJk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hugin-ptx+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hugin-ptx/1bfc845a-bcc9-42de-a42b-68f0e2b48f5f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

projection.png

T. Modes

unread,
Oct 16, 2017, 4:19:32 PM10/16/17
to hugin and other free panoramic software


Am Montag, 16. Oktober 2017 22:12:05 UTC+2 schrieb Iacovlev Pavel:
The projection is equirectangular, I have attached a screenshot of the project tab from Hugin.
Sorry, but I was not clear enough. I was referring to the lens or input projection.
Equirectangular is the output projection.

Pavel Iacovlev

unread,
Oct 16, 2017, 4:49:55 PM10/16/17
to hugi...@googlegroups.com
Full frame fisheye ? is that it ? not 100% sure.

Inline image 1


--
A list of frequently asked questions is available at: http://wiki.panotools.org/Hugin_FAQ
---
You received this message because you are subscribed to a topic in the Google Groups "hugin and other free panoramic software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hugin-ptx/ZbrCrgLdNJk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hugin-ptx+unsubscribe@googlegroups.com.

T. Modes

unread,
Oct 17, 2017, 11:41:14 AM10/17/17
to hugin and other free panoramic software


Am Montag, 16. Oktober 2017 22:49:55 UTC+2 schrieb Iacovlev Pavel:
Full frame fisheye ? is that it ? not 100% sure.

For a full frame fisheye (but not e.g. for the stereographic fisheye) the following equation should be correct from Hugins point of view:

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

var focalLengthPx = (focalLengthMm / 5.70) * w;


But you are mixing constants and variables, e.q. you are calculating the sensorSizeX in the first place and then you are using the constant 5.7 in the last equation.

And when you combine both equation you don't need sensorSizeX at all.


Also I don't know if OpenCV/nvidia is using the same convention.

Pavel Iacovlev

unread,
Oct 18, 2017, 12:45:16 PM10/18/17
to hugi...@googlegroups.com
Thank you a ton Thomas, with your input I was able to get pretty close to what I need.

--
A list of frequently asked questions is available at: http://wiki.panotools.org/Hugin_FAQ
---
You received this message because you are subscribed to a topic in the Google Groups "hugin and other free panoramic software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hugin-ptx/ZbrCrgLdNJk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hugin-ptx+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages