Most self-calibration algorithms require a prior knowledge of the camera calibration matrix ; as an instance, you need it to normalize the image points as and therefore fit the essential matrix .
With most commercial cameras it is safe to assume that the pixels are square and have no slant; in this case, , where
- are the coordinates of the principal point in pixel units; it is usually an acceptable first approximation to assume that the principal point is at the centre of the sensor;
- is the number of pixels per mm; it is usually safe to take the nominal value specified by the sensor vendor;
- is the focal length in mm. Taking the nominal value specified by the lens vendor could not be sufficient; even worse if, working with a zoom lens, one tries to read the focus scale.
So it would be nice to obtain at least , or better the whole calibration matrix, from the images. The calibration matrix can be computed from the image of the absolute conic which, in the above conditions, is ; it is related to by .
, in turn, can be obtained from three couples of vanishing points ; ; corresponding to pencils of lines which are orthogonal in the object space; each couple contributes a constraint . Three constraints are sufficient because has four distinct non-null entries but, being the matrix of a conic section, it is homogeneous (defined up to a scale factor).
In an ideal world, things are so simple. All the lines of the pencil intersect exactly in the same point, whose coordinates are readily computed and can be used to obtain .
In the real world, nothing is perfect and things are not so simple. Straight lines must be obtained by fitting them to points (edgels), which are noisy. As a result, each couple of lines in the pencil will intersect in a different point (though all the points should be very close).
Taking the centroid of the intersections may work, but it is possible to do better by realizing that we are facing a constrained minimum problem: we are looking for a pencil of straight lines, minimizing the sum of squared distances of each line from its own cloud of points, all lines constrained to intersect in the same point.
- be the number of lines,
- be the number of points in the cloud of the i-th line,
- be the coordinates of the j-th point in the cloud of the i-th line,
- be the parameters of the polar representation of the i-th line,
- be the coordinates of the intersection;
then the problem can be written as
The lagrangian is
where are the Lagrange multipliers.
This is a nonlinear problem and as such needs an initial approximation to start with. The unconstrained straight lines can be fitted eg with the method of Alciatore and Miranda, which is closed form and fast, and in this context possible outliers can be rejected eg with RANSAC; the intersection can be obtained as the centroid of all the intersections. It is a good idea to check that no intersection be too far from the centroid; this could be a symptom of something gone astray in the previous steps.
Unluckily, it is not possible to adapt to this problem the linear method I described here (reduction to the subspace of constraints) because the common intersection point is not known in advance.