PARP Research Group University of Murcia, Spain


Projective Geometry
[Math extensions]

Functions related to Projective Geometry. More...

Functions

QVMatrix ComputeProjectiveHomography (const QList< QPointFMatching > &matchings)
 Obtains a planar homography from two lists of corresponding points.

This function obtains the planar homography which maps the location of the points from a source plane to a destination plane. One of the planes can be the image plane as well.

QVMatrix ComputeEuclideanHomography (const QList< QPointFMatching > &matchings)
 Obtains the fundamental matrix between two images, using the 8 point algorithm.

This function performs point normalization to robustly obtain the F matrix.

QPointF ApplyHomography (const QVMatrix &homography, const QPointF &point)
 Obtains the homogenized coordinates of a point mapped using an homography transformation.

This function obtains the point $ (x', y') $ which holds the following equation:.

QList< QPointF > ApplyHomography (const QVMatrix &homography, const QList< QPointF > &sourcePoints)
 Obtains the homogenized coordinates of a set of points mapped using an homography transformation.

This function applies a transformation homography over a set of points. For further info about this mapping see function ApplyHomography(const QVMatrix &, const QPointF &).

double HomographyTestError (const QVMatrix &homography)
 Function to test if a 3x3 matrix corresponds to an homography.

Every matrix which holds a perspective deformation from one plane to another should validate some constrains. The most important is that its two first columns should be perpendicular, and with a similar size, because for the matrix to correspond to an homography, they should be contained in a base of a rotated coordinate system. Given the following homography matrix:.

void GetExtrinsicCameraMatrixFromHomography (const QVMatrix &K, const QVMatrix &H, QVMatrix &M4x4)
void GetDirectIntrinsicCameraMatrixFromHomography (const QVMatrix &H, QVMatrix &K)
 Diagonal intrinsic camera matrix calibration

This function obtains a diagonal intrinsic camera matrix, consisting on the focal distance only. This matrix is such that.

void CalibrateCameraFromPlanarHomography (const QVMatrix &H, QVMatrix &K, QVMatrix &Rt)
 Diagonal intrinsic camera matrix calibration

This function obtains a diagonal intrinsic camera matrix, consisting on the focal distance only. This matrix is such that.

void GetPinholeCameraIntrinsicsFromPlanarHomography (const QVMatrix &H, QVMatrix &K, const int iterations=100, const double maxGradientNorm=1e-3, const double step=0.01, const double tol=1e-4)
 Obtains the intrinsic camera matrix from a planar homography

This functions obtains the intrinsic calibration matrix $ K $ corresponding to a simple pinhole camera model. The intrinsic camera matrix has only one free parameter, related to the focal distance of the camera:.


Detailed Description

Functions related to Projective Geometry.

Projective Geometry models the principles of perspective, and provides important results for Computer Vision.

Notation and conventions

The projection camera matrix

It is a matrix composed by the intrinsic and the extrinsic camera matrices:

$ \mathbf{P} = \mathbf{K} \left[ \begin{array}{c|c} \mathbf{R} & \mathbf{t} \end{array} \right] $

Matrix $ \mathbf{K}_{3 \times 3} $ represents the intrinsic camera parameters, and matrix $ \left[ \begin{array}{c|c} \mathbf{R}_{3 \times 3} & \mathbf{t}_{3 \times 1} \end{array} \right] $ the extrinsic camera configuration. The projection camera matrix $ \mathbf{P}_{3 \times 4} $ models the linear relationship between the location of a point in the 3D space $ \mathbf{X}_{4 \times 1} = (x,y,z,1) $ and its corresponding pixel in an image $ \mathbf{x}_{3 \times 1} = (column, row, 1) $:

$ \mathbf{x} \propto \mathbf{P} \mathbf{X} $

The canonical camera matrix.

The canonical camera matrix models a pinhole camera with an intrinsic camera matrix equal to the identity:

$ \mathbf{C}_N = \left[ \begin{array}{c|c} \mathbf{R} & \mathbf{t} \end{array} \right] $

It maps the 3D point to its corresponding point $ \mathbf{\hat{x}}_{3 \times 3} $ in the projective plane:

$ \mathbf{\hat{x}} \propto \mathbf{C}_N \mathbf{X} $

The projective plane point $ \mathbf{\hat{x}} $ can be obtained from the image point by multiplying the inverse of the intrinsic camera matrix:

$ \mathbf{\hat{x}}_{3 \times 1} = K^{-1} \mathbf{x}_{3 \times 1} $

The fundamental matrix.

$ \mathbf{x} F_{12} \mathbf{x}' = 0 $

The essential matrix.

The essential matrix relates the location of corresponding points at two different images:

$ \mathbf{\hat{x}} E_{12} \mathbf{\hat{x}}' = 0 $

The planar homography matrix

Results of the projective geometry

Camera Calibration

3D reconstruction


Function Documentation

QList<QPointF> ApplyHomography ( const QVMatrix homography,
const QList< QPointF > &  sourcePoints 
)

Obtains the homogenized coordinates of a set of points mapped using an homography transformation.

This function applies a transformation homography over a set of points. For further info about this mapping see function ApplyHomography(const QVMatrix &, const QPointF &).

See also:
ApplyHomography(const QVMatrix &, const QPointF &)

ComputeProjectiveHomography

Parameters:
homography The homography transformation matrix
sourcePoints Points to apply the homography transformation

Definition at line 340 of file qvprojective.cpp.

QPointF ApplyHomography ( const QVMatrix homography,
const QPointF &  point 
)

Obtains the homogenized coordinates of a point mapped using an homography transformation.

This function obtains the point $ (x', y') $ which holds the following equation:.

$ \left(\begin{array}{c} x' \\ y' \\ 1 \end{array}\right) \propto H \left(\begin{array}{c} x \\ y \\ 1 \end{array}\right) $

Where $ H $ and $ (x,y) $ are the input transformation homography and point respectively. Matrix $ H $ must be of size $ 3 \times 3 $.

See also:
ComputeProjectiveHomography
Parameters:
homography The homography transformation matrix
point Point to apply the homography transformation

Definition at line 329 of file qvprojective.cpp.

Referenced by ApplyHomography().

void CalibrateCameraFromPlanarHomography ( const QVMatrix H,
QVMatrix K,
QVMatrix Rt 
)

Diagonal intrinsic camera matrix calibration

This function obtains a diagonal intrinsic camera matrix, consisting on the focal distance only. This matrix is such that.

$ H = K \left[ R | t\right] $

Where $ R $ is a rotation matrix. This matrix is obtained with a minimization process, so its result is more precise than that obtained with GetDirectIntrinsicCameraMatrixFromHomography function.

See also:
GetDirectIntrinsicCameraMatrixFromHomography
Todo:
write documentation for this function

Definition at line 386 of file qvprojective.cpp.

QVMatrix ComputeEuclideanHomography ( const QList< QPointFMatching > &  matchings  ) 

Obtains the fundamental matrix between two images, using the 8 point algorithm.

This function performs point normalization to robustly obtain the F matrix.

Note:
This function uses OpenCV functionallity. The QVision must be compiled with the OpenCV compatibility enabled to provide this function.
Parameters:
matchings list of 8 point matchings
This function obtains an euclidean mapping between the source an destination locations of a set of point matchings. The mapping is returned as a $ 3 \times 3 $ matrix which can be multiplied to the source location of each mapping point in homogeneous coordinates, obtaining a location close to the destination location from the matching.

Todo:
write documentation for this function

Definition at line 272 of file qvprojective.cpp.

QVMatrix ComputeProjectiveHomography ( const QList< QPointFMatching > &  matchings  ) 

Obtains a planar homography from two lists of corresponding points.

This function obtains the planar homography which maps the location of the points from a source plane to a destination plane. One of the planes can be the image plane as well.

The function returns the matrix corresponding to the planar homography, from a list of four or more point correspondences between the location of those points at the source plane and their location in the destination plane.

This function can be used to compute a rectification homography, which can be used to obtain a frontal view of any planar figure appearing in an image. The following code and images shows this effect:

rectification_homography.png

Image on the left is the original picture obtained with a pin-hole camera. Image on the right was obtained aplying a rectification homography to the pixels in the original image. This rectification homography is obtained using the function ComputeProjectiveHomography with the four point correspondences between the points in the images featured with yellow dots:

QList< QPair<QPointF, QPointF> > matchings;
matchings.append(QPair<QPointF, QPointF>(QPointF(-171,109),     QPointF(-100,+100)));
matchings.append(QPair<QPointF, QPointF>(QPointF(-120,31),      QPointF(-100,-100)));
matchings.append(QPair<QPointF, QPointF>(QPointF(117,53),       QPointF(+100,-100)));
matchings.append(QPair<QPointF, QPointF>(QPointF(11,115),       QPointF(+100,+100)));

const QVMatrix H = ComputeProjectiveHomography(matchings);

The obtained matrix $H$ holds the following equation:

$ H \propto \left( \begin{array}{ccc} 0.63868 & 0.77290 & -39.73059 \\ -0.11082 & 1.94177 & -165.90578 \\ -0.00034 & -0.00378 & 1 \\ \end{array} \right)$

Also for each point matching $ p \mapsto p' $ contained in the matchings list, the following equation holds.

$ p' \propto H p $

or

$ p' \times H p = 0 $

In C++ source code:

QPair<QPointF, QPointF> matching;
foreach(matching, matchings)
        {
        const QVVector  p_0 = QVVector::homogeneousCoordinates(matching.first),
                        p_1 = QVVector::homogeneousCoordinates(matching.second);
        std::cout << "p1 x H p0 =" << (p_1 ^ H*p_0) << std::endl;
        }

The printed values must be close to 0.

The location $ p_1 $ at the rectified version of an image corresponding to pixel $ p_0 $ at the original version of the image can be obtained given the rectification homography $ H $ using the following C++ code:

QPointF p_1 = H * QVVector::homogeneousCoordinates(p_0);

Or the ApplyHomography functions.

See also:
ApplyHomography(const QVMatrix &, const QPointF &)

ApplyHomography(const QVMatrix &, const QList<QPointF> &)

Parameters:
matchings list of point matchings from the original location, to the destination location.

Definition at line 93 of file qvprojective.cpp.

void GetDirectIntrinsicCameraMatrixFromHomography ( const QVMatrix H,
QVMatrix K 
)

Diagonal intrinsic camera matrix calibration

This function obtains a diagonal intrinsic camera matrix, consisting on the focal distance only. This matrix is such that.

$ H = K \left[ R | t\right] $

Where $ R $ is a rotation matrix. This function returns a direct approximation for the $ K $ matrix.

Todo:
rename to GetDirectCameraIntrinsicsFromPlanarHomography
See also:
GetIntrinsicCameraMatrixFromHomography

Definition at line 370 of file qvprojective.cpp.

Referenced by CalibrateCameraFromPlanarHomography().

void GetExtrinsicCameraMatrixFromHomography ( const QVMatrix K,
const QVMatrix H,
QVMatrix M4x4 
)

Todo:
write documentation for this function

Definition at line 423 of file qvprojective.cpp.

void GetPinholeCameraIntrinsicsFromPlanarHomography ( const QVMatrix H,
QVMatrix K,
const int  iterations = 100,
const double  maxGradientNorm = 1e-3,
const double  step = 0.01,
const double  tol = 1e-4 
)

Obtains the intrinsic camera matrix from a planar homography

This functions obtains the intrinsic calibration matrix $ K $ corresponding to a simple pinhole camera model. The intrinsic camera matrix has only one free parameter, related to the focal distance of the camera:.

$ K = \begin{array}{ccc} f & 0 & 0 \\ 0 & f & 0 \\ 0 & 0 & 1 \\ \end{array} $

This function should receive a planar homography corresponding to the mapping of a set of know template points, to an image frame captured with the camera containing a view of that template.

The following is an example of a full intrinsic camera calibration, knowing a set of point matchings between the template image and the input image read from the camera:

[...]
QList< QPointFMatching > matchings;
matchings.append(QPointFMatching(QPointF(-171,109),     QPointF(-100,+100)));
matchings.append(QPointFMatching(QPointF(-120,31),      QPointF(-100,-100)));
matchings.append(QPointFMatching(QPointF(117,53),       QPointF(+100,-100)));
matchings.append(QPointFMatching(QPointF(11,115),       QPointF(+100,+100)));

QVMatrix H, K;
H = ComputeProjectiveHomography(matchings);
GetPinholeCameraIntrinsicsFromPlanarHomography(H, K);
[...]

For further understanding of the planar homography calibration process, see ComputeProjectiveHomography function documentation.

Parameters:
H Input planar homography.
K Matrix to store the intrinsic camera matrix
iterations Cumber of iterations to perform camera calibration
maxGradientNorm Minimal value of the gradient size (norm 2) to stop the minimization when reached.
step Corresponds to parameter step for the gsl_multimin_fdfminimizer_set function.
tol Corresponds to parameter tol for the gsl_multimin_fdfminimizer_set function.
Returns:
a value close to 1 when the matrix doesn't corresponds to an homography, and close to 0 when it is close to be an homography.
See also:
ComputeProjectiveHomography

Definition at line 443 of file qvprojective.cpp.

double HomographyTestError ( const QVMatrix homography  ) 

Function to test if a 3x3 matrix corresponds to an homography.

Every matrix which holds a perspective deformation from one plane to another should validate some constrains. The most important is that its two first columns should be perpendicular, and with a similar size, because for the matrix to correspond to an homography, they should be contained in a base of a rotated coordinate system. Given the following homography matrix:.

$ H = \left[ R_1 R_2 -CR^t \right] $

The error value returned by this function for it will be:

$ error = \left| \frac{ \|R_1\| - \|R_2\| }{ \|R_1\| + \|R_2\| } \right| + \left| \frac{ R_1 \cdot R_2}{ \|R_1\| \|R_2\| } \right| $

That error is a measure of the difference of sizes between the norm of the two column vectors of the homography, corresponding to the two first columns of the rotation matrix, and their dot product. When both values are close to zero, the matrix corresponds to an homography, and it won't otherwise.

A good method to prove that a matrix corresponds to an homography using this function, can be done testing the return value with a threshold of aproximately 0.3. If the return value of this function for a matrix is lower than this threshold, that matrix is likely to correspond to an homography, and is not likely to correspond otherwise.

Parameters:
homography a possible homography matrix.
Returns:
a value close to 1 when the matrix doesn't corresponds to an homography, and close to 0 when it is close to be an homography.

Definition at line 348 of file qvprojective.cpp.




QVision framework. PARP research group, copyright 2007, 2008.