Camera model parameters and functions for a single camera. More...
#include <Calibration.h>
Classes | |
struct | CCameraParameters |
Struct containing all parameters of the camera model. More... | |
Public Member Functions | |
void | CameraToImageCoordinates (const Vec3d &cameraPoint, Vec2d &imagePoint, bool bUseDistortionParameters=true) const |
Transforms 3D camera coordinates to 2D image coordinates. | |
void | CameraToWorldCoordinates (const Vec3d &cameraPoint, Vec3d &worldPoint) const |
Transforms 3D camera coordinates to 3D world coordinates. | |
CCalibration () | |
The default constructor. | |
void | DistortCameraCoordinates (const Vec2d &undistortedCameraPoint, Vec2d &distortedCameraPoint) const |
Deprecated. | |
void | DistortImageCoordinates (const Vec2d &undistortedImagePoint, Vec2d &distortedImagePoint) const |
Transforms 2D undistorted image coordinates to 2D distorted image coordinates. | |
void | GetCalibrationMatrix (Mat3d &K) const |
Sets up the calibration matrix K. | |
void | GetCameraCoordinates (const Vec3d &worldPoint, Vec2d &imagePoint, bool bUseDistortionParameters=true) const |
Deprecated. | |
const CCameraParameters & | GetCameraParameters () const |
Gives access to the camera parameters. | |
void | GetProjectionMatrix (Mat3d &P1, Vec3d &p2) const |
Sets up the projection matrix P. | |
void | GetWorldCoordinates (const Vec2d &imagePoint, Vec3d &worldPoint, float zc=1.0f, bool bUseDistortionParameters=true) const |
Deprecated. | |
void | ImageToCameraCoordinates (const Vec2d &imagePoint, Vec3d &cameraPoint, float zc=1.0f, bool bUseDistortionParameters=true) const |
Transforms 2D image coordinates to 3D camera coordinates. | |
void | ImageToWorldCoordinates (const Vec2d &imagePoint, Vec3d &worldPoint, float zc=1.0f, bool bUseDistortionParameters=true) const |
Transforms 2D image coordinates to 3D world coordinates. | |
bool | LoadCameraParameters (const char *pCameraParameterFileName, int nCamera=0, bool bSetExtrinsicToIdentity=false) |
Initializes the camera model, given a file path to a camera parameter file. | |
void | PrintCameraParameters () const |
Prints all camera parameters in the console window (STDOUT). | |
bool | SaveCameraParameters (const char *pCameraParameterFileName) const |
Writes the parameters of the camera model to camera parameter file. | |
void | Set (const CCalibration &calibration) |
Initializes the camera model, given an instance of CCalibration. | |
void | SetCameraParameters (float fx, float fy, float cx, float cy, float d1, float d2, float d3, float d4, const Mat3d &R, const Vec3d &t, int width, int height) |
Initializes the camera model, given a complete parameter set. | |
void | SetDistortion (float d1, float d2, float d3, float d4) |
Sets the distortion parameters of the distortion model. | |
void | SetIntrinsicBase (float cx, float cy, float fx, float fy) |
Sets the principal point and the focal lengths. | |
void | SetRotation (const Mat3d &R) |
Sets the extrinsic parameter R (rotation matrix). | |
void | SetTranslation (const Vec3d &t) |
Sets the extrinsic parameter t (translation vector). | |
void | UndistortCameraCoordinates (const Vec2d &distortedCameraPoint, Vec2d &undistortedCameraPoint) const |
Deprecated. | |
void | UndistortImageCoordinates (const Vec2d &distortedImagePoint, Vec2d &undistortedImagePoint) const |
Transforms 2D distorted image coordinates to 2D undistorted image coordinates. | |
void | WorldToCameraCoordinates (const Vec3d &worldPoint, Vec3d &cameraPoint) const |
Transforms 3D world coordinates to 3D camera coordinates. | |
void | WorldToImageCoordinates (const Vec3d &worldPoint, Vec2d &imagePoint, bool bUseDistortionParameters=true) const |
Transforms 3D world coordinates to 2D image coordinates. | |
~CCalibration () | |
The destructor. | |
Public Attributes | |
Mat3d | m_rotation_inverse |
Rotation matrix of the inverted extrinsic transformation. | |
Vec3d | m_translation_inverse |
Translation vector of the inverted extrinsic transformation. | |
Private Member Functions | |
void | CalculateInverseTransformation () |
void | CalculateRadialLensDistortion () |
Private Attributes | |
CCameraParameters | m_cameraParameters |
Camera model parameters and functions for a single camera.
The linear projection is modeled as a central perspective projection with the parameters fx, fy and cx, cy.
where u, v denote image coordinates, fx, fy the focal lengths, cx, cy the principal point, and xc, yc, zc denote camera coordinates.
The relationship between the world coordinate system and the camera coordinate system is modeled as a rigid body coordinate transformation from the world coordinate system into the camera coordinate system:
where denotes world coordinates, denotes camera coordinates, R is a 3x3 rotation matrix and t is a translation vector (R, t are the extrinsic camera parameters).
The distortion model is composed of radial lens distortion (parameters d1, d2) and tangential lens distortion (parameters d3, d4). It is modeled as the computation of distorted image coordinates (ud, vd), given undistorted image coordinates (u, v):
The camera model is described in detail in (P. Azad, T. Gockel, R. Dillmann, "Computer Vision - Principles and Practice", Elektor, Netherlands). It is the same camera model as used in OpenCV 1.0.
Definition at line 125 of file Calibration.h.
The default constructor.
The default constructor initializes the camera model with the values width = 640, height = 480, fx = fy = 580, cx = 320, cy = 240, R = I, t = 0, d1 = d2 = d3 = d4 = 0. See CCameraParameters for further information on these parameters.
Camera parameters computed with calibration algorithms can be loaded by calling the method CCalibration::LoadCameraParameters.
Definition at line 68 of file Calibration.cpp.
The destructor.
Definition at line 82 of file Calibration.cpp.
void CCalibration::CalculateInverseTransformation | ( | ) | [private] |
Definition at line 109 of file Calibration.cpp.
void CCalibration::CalculateRadialLensDistortion | ( | ) | [private] |
void CCalibration::CameraToImageCoordinates | ( | const Vec3d & | cameraPoint, |
Vec2d & | imagePoint, | ||
bool | bUseDistortionParameters = true |
||
) | const |
Transforms 3D camera coordinates to 2D image coordinates.
Performs the mapping from the camera coordinate system to the image coordinate system, i.e. projection.
[in] | cameraPoint | The 3D camera coordinates. |
[out] | imagePoint | The result parameter for the 2D image coordinates. |
[in] | bUseDistortionParameters | If set to true, the distortion model will be applied after linear projection, i.e. distorted image coordinates will be written to the parameter imagePoint. If set to false, the distortion model is skipped, i.e. undistorted image coordinates will be written to the parameter imagePoint. |
Definition at line 210 of file Calibration.cpp.
void CCalibration::CameraToWorldCoordinates | ( | const Vec3d & | cameraPoint, |
Vec3d & | worldPoint | ||
) | const |
Transforms 3D camera coordinates to 3D world coordinates.
Performs the coordinate transformation from the camera coordinate system to the world coordinate system, i.e. application of the inverse extrinsic camera parameters.
[in] | cameraPoint | The 3D camera coordinates. |
[out] | worldPoint | The result parameter for the 3D world coordinates. |
Definition at line 205 of file Calibration.cpp.
void CCalibration::DistortCameraCoordinates | ( | const Vec2d & | undistortedCameraPoint, |
Vec2d & | distortedCameraPoint | ||
) | const |
Deprecated.
This method is deprecated. It internally calls DistortImageCoordinates(const Vec2d&, Vec2d&); please refer to the documentation of this function for more information.
Definition at line 305 of file Calibration.cpp.
void CCalibration::DistortImageCoordinates | ( | const Vec2d & | undistortedImagePoint, |
Vec2d & | distortedImagePoint | ||
) | const |
Transforms 2D undistorted image coordinates to 2D distorted image coordinates.
Applies the distortion model to 2D image coordinates.
[in] | undistortedImagePoint | The 2D undistorted image coordinates. |
[out] | distortedImagePoint | The result parameter for the 2D distorted image coordinates. |
Definition at line 266 of file Calibration.cpp.
void CCalibration::GetCalibrationMatrix | ( | Mat3d & | K | ) | const |
Sets up the calibration matrix K.
The calibration matrix is defined as:
The camera model is described in the general information about the class CCalibration.
[out] | K | The result parameter for the 3x3 calibration matrix. |
Definition at line 91 of file Calibration.cpp.
void CCalibration::GetCameraCoordinates | ( | const Vec3d & | worldPoint, |
Vec2d & | imagePoint, | ||
bool | bUseDistortionParameters = true |
||
) | const |
Deprecated.
This method is deprecated. It internally calls WorldToImageCoordinates(const Vec3d&, Vec2d&, bool); please refer to the documentation of this function for more information.
Definition at line 290 of file Calibration.cpp.
const CCameraParameters& CCalibration::GetCameraParameters | ( | ) | const [inline] |
Gives access to the camera parameters.
Definition at line 268 of file Calibration.h.
void CCalibration::GetProjectionMatrix | ( | Mat3d & | P1, |
Vec3d & | p2 | ||
) | const |
Sets up the projection matrix P.
The projection matrix P is a 3x4 matrix defined as:
, where K denotes the calibration matrix (see CCalibration::GetCalibrationMatrix) and R, t are the extrinsic camera parameters.
The camera model is described in the general information about the class CCalibration.
[out] | P1 | The left 3x3 part of the projection matrix, i.e. P1 = K R. |
[out] | p2 | The right 3x1 part of the projection matrix, i.e. p2 = K t. |
Definition at line 99 of file Calibration.cpp.
void CCalibration::GetWorldCoordinates | ( | const Vec2d & | imagePoint, |
Vec3d & | worldPoint, | ||
float | zc = 1.0f , |
||
bool | bUseDistortionParameters = true |
||
) | const |
Deprecated.
This method is deprecated. It internally calls ImageToWorldCoordinates(const Vec2d&, Vec3d&, float, bool); please refer to the documentation of this function for more information.
Definition at line 295 of file Calibration.cpp.
void CCalibration::ImageToCameraCoordinates | ( | const Vec2d & | imagePoint, |
Vec3d & | cameraPoint, | ||
float | zc = 1.0f , |
||
bool | bUseDistortionParameters = true |
||
) | const |
Transforms 2D image coordinates to 3D camera coordinates.
Performs the mapping from the image coordinate system to the camera coordinate system, i.e. back projection.
This mapping is ambiguous: All points that are mapped to 2D image point are located on straight line through the center of projection.
[in] | imagePoint | The 2D image coordinates. |
[out] | cameraPoint | The result parameter for the 3D camera coordinates. |
[in] | zc | As the 2D => 3D mapping is ambiguous, this parameter is required as an additional constraint to specify a unique point. zc specifies the z-coordinate of the target point in the camera coordinate system. |
[in] | bUseDistortionParameters | If set to true, the (inverse) distortion model will be applied before linear back projection, i.e. the input parameter imagePoint must contain distorted image coordinates. If set to false, the distortion model is skipped, i.e. the input parameter imagePoint must contain undistorted image coordinates. |
Definition at line 219 of file Calibration.cpp.
void CCalibration::ImageToWorldCoordinates | ( | const Vec2d & | imagePoint, |
Vec3d & | worldPoint, | ||
float | zc = 1.0f , |
||
bool | bUseDistortionParameters = true |
||
) | const |
Transforms 2D image coordinates to 3D world coordinates.
Performs the mapping from the image coordinate system to the world coordinate system, i.e. back projection and application of the (inverse) extrinsic camera parameters.
This mapping is ambiguous: All points that are mapped to 2D image point are located on straight line through the center of projection.
[in] | imagePoint | The 2D image coordinates. |
[out] | worldPoint | The result parameter for the 3D world coordinates. |
[in] | zc | As the 2D => 3D mapping is ambiguous, this parameter is required as an additional constraint to specify a unique point. zc specifies the z-coordinate of the target point in the camera coordinate system (not world coordinate system!). |
[in] | bUseDistortionParameters | If set to true, the (inverse) distortion model will be applied before linear back projection, i.e. the input parameter imagePoint must contain distorted image coordinates. If set to false, the distortion model is skipped, i.e. the input parameter imagePoint must contain undistorted image coordinates. |
Definition at line 193 of file Calibration.cpp.
bool CCalibration::LoadCameraParameters | ( | const char * | pCameraParameterFileName, |
int | nCamera = 0 , |
||
bool | bSetExtrinsicToIdentity = false |
||
) |
Initializes the camera model, given a file path to a camera parameter file.
The format of the file is the same as the one used in OpenCV 1.0. The file format is described in CStereoCalibration::LoadCameraParameters.
Camera calibration can be performed with the application found in IVT/examples/CalibrationApp (resp. IVT/win32/CalibrationApp). See also the class CDLTCalibration.
[in] | pCameraParameterFileName | The file path to the camera parameter file to be loaded. |
[in] | nCamera | If the camera parameter file contains a stereo calibration, this parameter indicates the parameters of which camera are to be loaded (0: first (usually left) camera, 1 : second (usually right) camera). |
[in] | bSetExtrinsicToIdentity | If set to true, then the extrinsic camera parameters R and t will be set to the identity transformation, i.e. R will be set to the identity matrix and t will be set to the translation vector. |
Definition at line 312 of file Calibration.cpp.
void CCalibration::PrintCameraParameters | ( | ) | const |
Prints all camera parameters in the console window (STDOUT).
Definition at line 410 of file Calibration.cpp.
bool CCalibration::SaveCameraParameters | ( | const char * | pCameraParameterFileName | ) | const |
Writes the parameters of the camera model to camera parameter file.
The format of the file is the same as the one used in OpenCV 1.0. The file format is described in CStereoCalibration::LoadCameraParameters.
[in] | pCameraParameterFileName | The file path to the target camera parameter file. |
Definition at line 380 of file Calibration.cpp.
void CCalibration::Set | ( | const CCalibration & | calibration | ) |
Initializes the camera model, given an instance of CCalibration.
calibration | The template instance. |
Definition at line 138 of file Calibration.cpp.
void CCalibration::SetCameraParameters | ( | float | fx, |
float | fy, | ||
float | cx, | ||
float | cy, | ||
float | d1, | ||
float | d2, | ||
float | d3, | ||
float | d4, | ||
const Mat3d & | R, | ||
const Vec3d & | t, | ||
int | width, | ||
int | height | ||
) |
Initializes the camera model, given a complete parameter set.
[in] | fx | The focal length in horizontal direction. |
[in] | fy | The focal length in vertical direction. |
[in] | cx | The x-coordinate (or u-coordinate) of the principal point. |
[in] | cy | The y-coordinate (or v-coordinate) of the principal point. |
[in] | d1 | The first radial lens distortion parameter. |
[in] | d2 | The second radial lens distortion parameter. |
[in] | d3 | The first tangential lens distortion parameter. |
[in] | d4 | The second tangential lens distortion parameter. |
[in] | R | The rotation matrix as part of the extrinsic camera parameters. |
[in] | t | The translation vector as part of the extrinsic camera parameters. |
[in] | width | The width of the image sensor in pixels. |
[in] | height | The height of the image sensor in pixels. |
Definition at line 117 of file Calibration.cpp.
void CCalibration::SetDistortion | ( | float | d1, |
float | d2, | ||
float | d3, | ||
float | d4 | ||
) |
Sets the distortion parameters of the distortion model.
[in] | d1 | The first radial lens distortion parameter. |
[in] | d2 | The second radial lens distortion parameter. |
[in] | d3 | The first tangential lens distortion parameter. |
[in] | d4 | The second tangential lens distortion parameter. |
Definition at line 177 of file Calibration.cpp.
void CCalibration::SetIntrinsicBase | ( | float | cx, |
float | cy, | ||
float | fx, | ||
float | fy | ||
) |
Sets the principal point and the focal lengths.
[in] | cx | The x-coordinate (or u-coordinate) of the principal point. |
[in] | cy | The y-coordinate (or v-coordinate) of the principal point. |
[in] | fx | The focal length in horizontal direction. |
[in] | fy | The focal length in vertical direction. |
Definition at line 171 of file Calibration.cpp.
void CCalibration::SetRotation | ( | const Mat3d & | R | ) |
Sets the extrinsic parameter R (rotation matrix).
The member variables CCalibration::m_rotation_inverse and CCalibration::m_translation_inverse are updated automatically.
[in] | R | The rotation matrix as part of the extrinsic camera parameters. |
Definition at line 159 of file Calibration.cpp.
void CCalibration::SetTranslation | ( | const Vec3d & | t | ) |
Sets the extrinsic parameter t (translation vector).
The member variable CCalibration::m_translation_inverse is updated automatically.
[in] | t | The translation vector as part of the extrinsic camera parameters. |
Definition at line 165 of file Calibration.cpp.
void CCalibration::UndistortCameraCoordinates | ( | const Vec2d & | distortedCameraPoint, |
Vec2d & | undistortedCameraPoint | ||
) | const |
Deprecated.
This method is deprecated. It internally calls UndistortImageCoordinates(const Vec2d&, Vec2d&); please refer to the documentation of this function for more information.
Definition at line 300 of file Calibration.cpp.
void CCalibration::UndistortImageCoordinates | ( | const Vec2d & | distortedImagePoint, |
Vec2d & | undistortedImagePoint | ||
) | const |
Transforms 2D distorted image coordinates to 2D undistorted image coordinates.
Applies the inverse distortion model to 2D image coordinates.
Note that the distortion model cannot be inverted algebraically. Therfore, an iterative algorithm is applied.
[in] | distortedImagePoint | The 2D distorted image coordinates. |
[out] | undistortedImagePoint | The result parameter for the 2D undistorted image coordinates. |
Definition at line 233 of file Calibration.cpp.
void CCalibration::WorldToCameraCoordinates | ( | const Vec3d & | worldPoint, |
Vec3d & | cameraPoint | ||
) | const |
Transforms 3D world coordinates to 3D camera coordinates.
Performs the coordinate transformation from the world coordinate system to the camera coordinate system, i.e. application of the extrinsic camera parameters.
[in] | worldPoint | The 3D world coordinates. |
[out] | cameraPoint | The result parameter for the 3D camera coordinates. |
Definition at line 200 of file Calibration.cpp.
void CCalibration::WorldToImageCoordinates | ( | const Vec3d & | worldPoint, |
Vec2d & | imagePoint, | ||
bool | bUseDistortionParameters = true |
||
) | const |
Transforms 3D world coordinates to 2D image coordinates.
Performs the mapping from the world coordinate system to the image coordinate system, i.e. application of the extrinsic camera parameters and the projection.
[in] | worldPoint | The 3D world coordinates. |
[out] | imagePoint | The result parameter for the 2D image coordinates. |
[in] | bUseDistortionParameters | If set to true, the distortion model will be applied after linear projection, i.e. distorted image coordinates will be written to the parameter imagePoint. If set to false, the distortion model is skipped, i.e. undistorted image coordinates will be written to the parameter imagePoint. |
Definition at line 186 of file Calibration.cpp.
Definition at line 465 of file Calibration.h.
Rotation matrix of the inverted extrinsic transformation.
The extrinsic parameters specify the mapping .
The inverse extrinsic parameters specify .
CCalibration::m_rotation_inverse thus is .
Definition at line 443 of file Calibration.h.
Translation vector of the inverted extrinsic transformation.
The extrinsic parameters specify the mapping .
The inverse extrinsic parameters specify .
CCalibration::m_translation_inverse thus is . It also equals the world coordinates of the center of projection.
Definition at line 454 of file Calibration.h.