Section 2: Calibrating the Lens
In PTGui you no longer need to calibrate your lens! This is done automatically by the application, and it does an incredibly good job. As a result the accuracy of the stitching in PTGui is much more accurate, and it most cases you'll never even need to touch up stitch seams at all!
So, if you're using PTGui, you can Proceed to Section 3: Shooting the Scene
Unfortunately you still need to manually calibrate your lens in PTMac, and this is a very complex and tedious process that is prone to error. Once you've done it accurately then you can use that calibration information for all of your panoramas and life gets much easier, but the initial calibration can be difficult. The basic workflow when using PTMac is as follows:
1. Load your fisheye images into PTMac.
2. Set the lens parameters.
3. Crop the images.
4. Set control points.
6. Stitch / Render
Step #2 is the tricky part. You've got to know what parameters to set the lens to. The lens parameters tell PTMac about the physical characteristics of your lens and how it distortes the images. All lenses have some degree of distortion in them, especially fisheye lenses. We must compensate for that distortion by calibrating our lens. You'll never get your shots to stitch correctly unless you've calibrated the lens! PTMac (and PTGui) has several calibration parameters that are used to correct this distortion: a, b, c, d and e. These are the values that we need to calculate only once for the lens, and then we'll never have to do this again.
PTMac Lens Calibration Tutorial & Tips
Rather than reinventing the wheel here, I'm going to refer you to the official PTMac lens calibration tutorial on the Kekus web site. This tutorial explains the steps involved in performing lens calibration, but here are some extra notes that I'll throw in:
1. When you shoot your test images to use for calibration, take extra effort to precisely align each shot. Make sure each shot is perfectly level so that PTMac won't have as much work to do to "fix" things.
2. There is a huge database available from Kekus that contains lens calibration values for over 100 different cameras and lenses. This is a good starting point for your calibration. You may be able to use the values in the database as-is, or you may need to refine them a little. This is discussed in detail below.
3. Don't optimize the yaw pitch roll (YPR) and the a,b,c values all at the same time! Once you've done this further optimization passes won't have any effect. It's always best to optimize YPR and a,b,c separately. Only do them all together as the last step since it may help a little, but just remember that you won't be able to optimize more after that.
4. If your Maximum Control Point distances are large and don't seem to be getting any smaller as you optimize then you may need to start over. Sometimes the numbers get "locked up", and there's no way to fix this. Just reset the lens parameters to default values, reset the YPR values to the default values (0, 90, 180, etc.), and start optimizing all over again, but this time use a slightly different sequence.
5. As you optimize, keep an eye on the FOV value. Sometimes weird things happen and you'll get unusually small or large FOV values. These are always incorrect, so if you suddenly see an optimized FOV of 190º then don't accept those optimization values by clicking Cancel, and then try optimizing different parameters. The same thing goes for the d and e values. Occasionally, they'll get way out of whack, and if that happens you need to manually fix it before continuing.
6. Remember that the d and e lens parameters represent the x,y offsets to the center of the lens. These values are valid only for the current crop that you've applied to your images. Once you have calibrated lens parameters you should always use the exact same crop whenever you use them. Changing the crop will change the FOV, d, and e values. In other words always use the same lens calibration values with the same crop parameters; otherwise you'll never get a good stitch.
7. You might create a test pano for calibrating your lens, do the optimizations, and end up with extremely low control point distances just like you'd hoped for. But then whenever you try these settings on other panos you don't get the same low control point distances. If this happens, it means that the calibrated values are actually incorrect, but they just happen to coincidentally work for that test pano. In this case, shoot a new test pano and try again.
8. Changing the focus changes the calibration! If you generate really good lens calibration values for your lens on a panorama, and then can't figure out why the next panorama you shoot doesn't stitch well, it may be because the focus changed. If you want to use the same calibration values on each pano that you shoot then you need to use the exact same focus setting on your lens, and I mean *exact*. Otherwise, you'll have to optimize the a,b,c,d,e parameters again with each panorama - the original calibration values should still be pretty close, but you'll need to do some optimizing to correct for the change in focus distortions.
If all of this is just too much of a pain in the ass you really should just invest in PTGui since you never have to mess with this in that app.
Using the LensFix Database
There is a large lens database calibration that you can access by downloading the LensFix and Panorama Tools plug-ins. A while back this database was pretty useful, but for some reason the guy who maintains the database removed all of the fisheye lens entries from it, so it's pretty useless now. But if for some reason you aren't using a fisheye lens you might be able to gain from it. Just run LensFix and choose your lens. It will show you the lens calibration values, so just copy-paste those into PTMac.
If you've got a fisheye lens (like most of us do) then you have to either calculate the calibration values yourself, or ask around on the various forums for the values from other users with your same camera/lens combo.
PanoTools and the Fisheye HFOV Limit
To make a long story short, there's a patent on using fisheye lenses to make panoramas. As a result, the shipping version of the PanoTools library limits your FOV to 160º in order to avoid legal problems. The source code to PanoTools is freely available, and if you know what you're doing you can download it and recompile a version that doesn't have the 160º limitation on it.
Luckily, you only need more than 160º if your images really do have a horizontal FOV greater than that. Odds are that your lens's HFOV is well below that (vertically it may be 180º, but not horizontally). However, if your Lens Type in PTMac is set to Circular Fisheye then PTMac treats your lens as a full 180º fisheye lens:
Circular Fisheye - PTMac treats the lens as ~180º
This can be resolved by simply using the Full-Frame Fisheye [Rectangular] lens type instead of Circular Fisheye. This way you only need an FOV equivalent to what you really have in your image. In the above example, I've set my circular crop to be just a little bit inside the outer edge of the fisheye image (since those outer pixels are too distorted to be useful), so when I optimize my FOV for this crop I'll end up with an FOV of around 178º. This is well over the limit that the unhacked "legal" version of PanoTools can support. If I instead choose a Full-Frame Fisheye lens type then I'll get a rectangle crop box instead of a circle:
Full-Frame Rectangular cropping - PTMac treats the lens as ~110º
The crop bounds here are flush with the sides of the fisheye image, and since my Sigma 8mm lens only captures about 110º horizontally, my FOV value will optimize out to around 110º which is well below the PanoTools 160º limit. Problem solved!