namespace referencePiiCalibration
Functions for camera calibration.
Classes
| struct |
A structure that stores all intrinsic camera parameters estimated by the calibration functions. |
| struct |
A structure that stores the extrinsic parameters related to a scene viewed. |
Enumerations
|
enum
|
{
NoCalibrationOptions = 0, EstimateIntrinsic = 1, FixPrincipalPoint = 2, FixAspectRatio = 4, NoTangentialDistortion = 8
}
Options for calibration functions. |
Functions
|
PII_CALIBRATION_EXPORT RelativePosition
|
(
Calculate the position of the camera reference frame with respect to the world coordinate system. |
|
PII_CALIBRATION_EXPORT RelativePosition
|
Calculate the relative position of |
|
PII_CALIBRATION_EXPORT void
|
(
Calibrate a camera. |
|
PII_CALIBRATION_EXPORT PiiMatrix< double >
|
Transforms points from camera reference frame to pixel coordinates. |
|
PII_CALIBRATION_EXPORT PiiMatrix< double >
|
Transform points from camera reference frame to world coordinates. |
|
PII_CALIBRATION_EXPORT void
|
Transforms a point from normalized image coordinates to pixel coordinates. |
|
PII_CALIBRATION_EXPORT PiiMatrix< double >
|
Transforms points from normalized image coordinates to pixel coordinates. |
|
PII_CALIBRATION_EXPORT PiiMatrix< double >
|
Perform perspective projection on |
|
|
|
|
PII_CALIBRATION_EXPORT PiiVector< double, 3 >
|
Convert a rotation matrix to a rotation vector. |
|
PII_CALIBRATION_EXPORT PiiMatrix< double >
|
Convert a rotation vector |
|
void
|
Converts pixel coordinates to normalized image coordinates. |
|
PII_CALIBRATION_EXPORT PiiMatrix< double >
|
Converts pixel coordinates to normalized image coordinates. |
|
template<class T>
PiiMatrix< T >
|
Removes lens distortions from sourceImage. |
|
PII_CALIBRATION_EXPORT PiiImage::DoubleCoordinateMap
|
Creates a coordinate map that converts distorted pixel coordinates to undistorted ones. |
|
PII_CALIBRATION_EXPORT PiiImage::IntCoordinateMap
|
Creates a coordinate map that converts distorted pixel coordinates to undistorted ones. |
|
PII_CALIBRATION_EXPORT PiiMatrix< double >
|
Transform points from world coordinate system to the camera reference frame. |
|
PII_CALIBRATION_EXPORT PiiMatrix< double >
|
(
Transform points from world coordinates to pixel coordinates. |
Enumeration details
-
enum CalibrationOption
Options for calibration functions.
NoCalibrationOptions- none of the options applies.EstimateIntrinsic- derive an initial guess of the intrinsic parameters based on the assumption that the calibration rig is planar. If this is not the case, you must provide an initial guess for intrinsic parameters. An estimate of the principal point (the image center) must always be provided.FixPrincipalPoint- the principal point will be fixed to the initial value and not changed during optimization.FixAspectRatio- the focal ratio between focal length components will be fixed. IfEstimateIntrinsicis used, the focal lengths will be set to arbitrary values. Only the ratio is meaningful.NoTangentialDistortion- do not estimate the tangetial distortion factors. The factors are set to zero and won't change in optimization.
Function details
-
PII_CALIBRATION_EXPORT RelativePosition calculateCameraPosition
(- const PiiMatrix< double > & worldPoints
- const PiiMatrix< double > & imagePoints
- const CameraParameters & intrinsic
#include <PiiCalibration.h>Calculate the position of the camera reference frame with respect to the world coordinate system.
This function can be used once the intrinsic camera parameters are known. See calibrateCamera() for a detailed description of the parameters.
Parameters
- worldPoints
the real-world coordinates of calibration points in one view. (at least four)
- imagePoints
the pixel coordinates of the corresponding calibration points.
- intrinsic
the intrinsic parameters of the camera.
Returns
the relative position of the camera with respect to the world coordinate system.
Exceptions
- PiiCalibrationException&
if the camera position cannot be calculated with the given data.
-
PII_CALIBRATION_EXPORT RelativePosition calculateRelativePosition
#include <PiiCalibration.h>Calculate the relative position of
camera2with respect tocamera1.When the positions of the cameras have been calculated with respect to the world coordinate system, this function can be used to find the transformation between the camera reference frames. As parameters, this function expects the relative positions of both cameras with respect to the same world coordinate system. The returned rotation matrix and translation vector are calculated as follows:

where X is a point in world coordinates.
and
are the rotation matrix and translation vector from
to
.
will be converted to the more compact rotation vector representation before returning.Parameters
- camera1
the relative position of the first camera with respect to the world coordinate system. Let us denote the rotation and translation matrices with
and
.- camera2
the relative position of the second camera with respect to the world coordinate system. Let us denote the rotation and translation matrices with
and
.
Returns
the relative position of
camera2with respect tocamera1. -
PII_CALIBRATION_EXPORT void calibrateCamera
(- const QList< PiiMatrix< double > > & worldPoints
- const QList< PiiMatrix< double > > & imagePoints
- CameraParameters & intrinsic
- QList< RelativePosition > * extrinsic = 0
- CalibrationOptions options = EstimateIntrinsic
#include <PiiCalibration.h>Calibrate a camera.
This function calculates the intrinsic parameters that minimize the reprojection error over the whole set of views. It also returns the extrinsic parameters related to each view.
Parameters
- worldPoints
a list of world coordinates of calibration points. Each matrix in this list corresponds to one view of the calibration rig and holds an N-by-3 matrix in which each row represents the 3-dimensional world coordinates of a calibration point. There must be at least three points in each view. If the world coordinates of the calibration points do not change, and all the points are visible in all views, the same world matrix can be reused. In such a case it suffices to store only one matrix in this list.
- imagePoints
the corresponding points in image coordinates. Each matrix in this list corresponds to one view of the calibration rig and holds an N-by-2 matrix in which each row represents the 2-dimensional image coordinates of a calibration point. The number of rows in each matrix must match
worldPoints.- intrinsic
store the calculated intrinsic parameters to this structure. If the
EstimateIntrinsicoption is not set, this structure must contain valid initial values for the intrinsic parameters. In any case, an initial estimate of the principal point must be provided. Therefore, always initialize the intrinsic parameters with the size of the camera image.- extrinsic
store the extrinsic parameters to this list (if non-zero). The extrinsic parameters are calculated for each view.
- options
a logical OR of calibration options, e.g.
EstimateIntrinsic|NoTangentialDistortion.
Exceptions
- PiiCalibrationException&
if the calibration cannot be performed with the given data.
-
PII_CALIBRATION_EXPORT PiiMatrix< double > cameraToPixelCoordinates
#include <PiiCalibration.h>Transforms points from camera reference frame to pixel coordinates.
Parameters
- points
input points in the camera reference frame. A N-by-3 matrix (x,y,z).
- intrinsic
camera parameters
Returns
a N-by-2 matrix which contains 2-dimensional pixel coordinates of the input points
-
PII_CALIBRATION_EXPORT PiiMatrix< double > cameraToWorldCoordinates
#include <PiiCalibration.h>Transform points from camera reference frame to world coordinates.
Parameters
- points
3-dimensional coordinates in the camera reference frame (N-by-3 matrix).
- extrinsic
the location of the camera wrt to the world coordinate system.
Returns
3-dimensional coordinates in the world coordinate system (N-by-3 matrix)
-
PII_CALIBRATION_EXPORT void normalizedToPixelCoordinates
#include <PiiCalibration.h>Transforms a point from normalized image coordinates to pixel coordinates.
Parameters
- intrinsic
the intrinsic parameters of the camera.
- x
the x coordinate of the input point in normalized image coordinates
- y
the y coordinate of the input point in normalized image coordinates
- newX
pixel x coordinate
- newY
pixel y coordinate
-
PII_CALIBRATION_EXPORT PiiMatrix< double > normalizedToPixelCoordinates
#include <PiiCalibration.h>Transforms points from normalized image coordinates to pixel coordinates.
Parameters
- points
normalized 2-dimensional coordinates (x,y) (N-by-2 matrix).
- intrinsic
camera parameters.
Returns
a N-by-2 matrix which contains the corresponding 2-dimensional pixel coordinates.
-
PII_CALIBRATION_EXPORT PiiMatrix< double > perspectiveProjection
#include <PiiCalibration.h>Perform perspective projection on
points.Parameters
- points
a N-by-3 matrix, (x,y,z) on each row
- zValue
a fixed value for the z coordinate. If this value is set to a valid numeric value, the projected pixels will all have it as the z coordinate. This is useful if you need to apply a 3D transformation to the coordinates afterwards.
Returns
a N-by-2 matrix (x/z,y/z), if zValue is NaN. Otherwise a N-by-3 matrix.
-
Q_DECLARE_FLAGS
#include <PiiCalibration.h> -
PII_CALIBRATION_EXPORT PiiVector< double, 3 > rotationMatrixToVector
#include <PiiCalibration.h>Convert a rotation matrix to a rotation vector.
The direction of the rotation vector tells the rotation axis, and its length is equal to the rotation angle. Given a rotation matrix R, the rotation vector V is derived as follows (see rotationVectorToMatrix() for definitions):

This equation makes use of the fact that M is an antisymmetric matrix. Thus,
and
.
Since the vector represented by M is a unit vector, we obtain both
and
from this equation. This doesn't fully resolve the rotation angle yet.
The only unknown here is
, which is trivial to solve. -
PII_CALIBRATION_EXPORT PiiMatrix< double > rotationVectorToMatrix
#include <PiiCalibration.h>Convert a rotation vector
rotationto a rotation matrix.This function converts the three-dimensional column vector
to a rotation matrix
as follows:
where M is an antisymmetric matrix:

where
and
.The norm of V (its geometric length) is used as the rotation angle wheras the direction of the vector specifies the rotation axis.
-
void undistort
#include <PiiCalibration.h>Converts pixel coordinates to normalized image coordinates.
This function first translates the input point according to the principal point and divides out the focal length. It then iteratively unapplies the lens distortion model for which there is no closed-form solution.
Parameters
- intrinsic
the intrinsic parameters of the camera.
- x
the x coordinate of the input point in pixel coordinates
- y
the y coordinate of the input point in pixel coordinates
- newX
undistorted x coordinate
- newY
undistorted y coordinate
-
PII_CALIBRATION_EXPORT PiiMatrix< double > undistort
#include <PiiCalibration.h>Converts pixel coordinates to normalized image coordinates.
This function undistorts each row in the input matrix.
Parameters
- distorted
2D pixel coordinates. A N-by-2 or N-by-3 matrix.
- intrinsic
the intrinsic parameters of the camera.
- zValue
a fixed value for the z coordinate. If this value is set to a valid numeric value, the undistorted pixels will all have it as the z coordinate. This is useful if you need to apply a 3D transformation to the coordinates afterwards.
Returns
pixel coordinates transformed into normalized image coordinates.
Exceptions
- PiiCalibrationException&
if the input data is invalid.
-
template<class T>
PiiMatrix< T > undistortImage
#include <PiiCalibration.h>Removes lens distortions from sourceImage.
This function first creates an undistortion map with undistortMap() and then applies PiiImage::remap(). If you need to repeat the process for many images, it is more efficient to calculate the undistortion map once and then apply it to all images.
Parameters
- sourceImage
the input image
- intrinsic
camera parameters found by calibration
Returns
an undistorted image
-
PII_CALIBRATION_EXPORT PiiImage::DoubleCoordinateMap undistortMap
#include <PiiCalibration.h>Creates a coordinate map that converts distorted pixel coordinates to undistorted ones.
The returned map can be used with PiiImage::remap() to correct an image against lens distortions. This function returns the distorted pixel coordinates in double precision.
-
PII_CALIBRATION_EXPORT PiiImage::IntCoordinateMap undistortMapInt
#include <PiiCalibration.h>Creates a coordinate map that converts distorted pixel coordinates to undistorted ones.
The returned map can be used with PiiImage::remap() to correct an image against lens distortions. This function returns the distorted pixel coordinates as integers, rounded to the position of the closest matching pixel.
-
PII_CALIBRATION_EXPORT PiiMatrix< double > worldToCameraCoordinates
#include <PiiCalibration.h>Transform points from world coordinate system to the camera reference frame.
Parameters
- points
3-dimensional coordinates in the world coordinate system (N-by-3 matrix).
- extrinsic
the location of the camera wrt to the world coordinate system.
Returns
3-dimensional coordinates in the camera reference frame (N-by-3 matrix)
-
PII_CALIBRATION_EXPORT PiiMatrix< double > worldToPixelCoordinates
(- const PiiMatrix< double > & points
- const RelativePosition & extrinsic
- const CameraParameters & intrinsic
#include <PiiCalibration.h>Transform points from world coordinates to pixel coordinates.
Parameters
- points
input points in the world coordinate system. A N-by-3 matrix (x,y,z).
- extrinsic
the location of the camera wrt to the world coordinate system.
- intrinsic
camera parameters
Returns
a N-by-2 matrix which contains 2-dimensional pixel coordinates of the input points
Add a note
Not a single note added yet. Be the first, add yours.