Hugin tutorial — Simple lens calibration

This tutorial describes the application of Hugin to obtain lens parameters a, b, c.

Note The pre-release version of Hugin 0.7.0 has been used for this tutorial. Although your version may differ, the underlying principle will remain the same.

The method used here is to set up some straight lines which pass near the edge of the image and across the image near the image centre. The lines do not have to be parallel, but they do need to be straight and either have a sharp edge or be fine enough to ensure that points selected on them define a straight line.

'Straight lines' in Hugin are defined by a special kind of control point called a straight line control point.

For this example I have set out four pegs in my lawn which roughly define a 4m square and then run a taut string line around the pegs and on one diagonal. The string used is a twisted red and white polypropylene of about 1mm diameter, which provides a very fine line. The alternating red and white helps locate the string against the background. I photographed the image from a step ladder.

You can download this image (p1010230.jpg) and try it yourself.

All pics

Start by launching Hugin, and using the Assistant tab select the 1. Load images... button to select the image for the project.

Select the Camera and Lens tab and check the Geometric data. The lens data should be automatically extracted (as shown in the last screen shot, below). The Radial Distortion parameters should all be zero.

Select the Control Points tab. The image should be shown in both image windows. Select your first point near the end of one of the string lines. I commenced near the left hand end of the string line near the lower edge of the image. Be sure to get your point as close to the centreline of the string as you can. Now choose a 'matching' point near the other end of this string line in the second image. It may be necessary to set the zoom to 100% or even higher.

Set mode: to add new line. The alignment should say Line 3.

Add additional point pairs working in from each end of the string line to give reasonably spaced points, each time setting alignment to Line 3. It may be necessary to switch the zoom back to "Fit to Window" between points to get a good overall view of the control points.

Add a second set of points along the diagonal string line, again working in from each end. After the first point set mode: add new line to ensure that Hugin understands that this set corresponds to a different straight line (Line 4).

control points

Select the Stitcher tab and set the projection to Rectilinear.

Select the Optimizer tab and set Quick Optimizer to the custom parameters below, then tick the Lens Parameters boxes Distortion (a):, Barrel (b):, and Distortion (c):, then select Optimize now!. If the results show very small errors select Yes to apply the changes.


Select the Camera and Lens tab to view the lens distortion parameters.

lens data

The lens parameters I obtained were a=0.00104, b=-0.00169 and c=0.00509. The lens calibration data can be saved using the Save lens... button, and used in future Hugin projects.

It should only be necessary to use two straight lines for this exercise.

Further information

For extra accuracy add more points to more 'straight lines', but to avoid confusion just add to the project an extra photo of the same scene from a slightly different angle. Put your new 'straight lines' in this photo, when you optimise, both images will be optimised together.

The same technique can be used to optimise fisheye photos, just ensure that the output Projection is always Rectilinear. You will find that the entire fisheye image doesn't fit into a 'rectilinear' output, so just work with half of the photo, Hugin will assume that the distortion is symmetrical.

Other techniques for calibrating a lens include:

Tutorial and photos — Terry Duell. Created July 2008