![]() |
Visual Servoing Platform version 3.7.0
|
#include <vpCameraParameters.h>
Public Types | |
| enum | vpCameraParametersProjType { perspectiveProjWithoutDistortion , perspectiveProjWithDistortion , ProjWithKannalaBrandtDistortion } |
Public Member Functions | |
| vpCameraParameters () | |
| vpCameraParameters (const vpCameraParameters &c) | |
| vpCameraParameters (double px, double py, double u0, double v0) | |
| vpCameraParameters (double px, double py, double u0, double v0, double kud, double kdu) | |
| vpCameraParameters (double px, double py, double u0, double v0, const std::vector< double > &distortion_coefficients) | |
| vpCameraParameters & | operator= (const vpCameraParameters &c) |
| bool | operator== (const vpCameraParameters &c) const |
| bool | operator!= (const vpCameraParameters &c) const |
| virtual | ~vpCameraParameters () |
| void | init () |
| void | init (const vpCameraParameters &c) |
| void | initFromCalibrationMatrix (const vpMatrix &K) |
| void | initFromFov (const unsigned int &w, const unsigned int &h, const double &hfov, const double &vfov) |
| void | initPersProjWithoutDistortion (double px, double py, double u0, double v0) |
| void | initPersProjWithDistortion (double px, double py, double u0, double v0, double kud, double kdu) |
| void | initProjWithKannalaBrandtDistortion (double px, double py, double u0, double v0, const std::vector< double > &distortion_coefficients) |
| bool | isFovComputed () const |
| void | computeFov (const unsigned int &w, const unsigned int &h) |
| double | getHorizontalFovAngle () const |
| double | getVerticalFovAngle () const |
| std::vector< vpColVector > | getFovNormals () const |
| double | get_px () const |
| double | get_px_inverse () const |
| double | get_py_inverse () const |
| double | get_py () const |
| double | get_u0 () const |
| double | get_v0 () const |
| double | get_kud () const |
| double | get_kdu () const |
| std::vector< double > | getKannalaBrandtDistortionCoefficients () const |
| vpCameraParametersProjType | get_projModel () const |
| vpMatrix | get_K () const |
| vpMatrix | get_K_inverse () const |
| void | printParameters () |
Friends | |
| class | vpMeterPixelConversion |
| class | vpPixelMeterConversion |
| VISP_EXPORT std::ostream & | operator<< (std::ostream &os, const vpCameraParameters &cam) |
| void | to_json (nlohmann::json &j, const vpCameraParameters &cam) |
| void | from_json (const nlohmann::json &j, vpCameraParameters &cam) |
Generic class defining intrinsic camera parameters.
1. Supported camera models
Two camera models are implemented in ViSP.
1.1. Pinhole camera model
In this model [36], a scene view is formed by projecting 3D points into the image plane using a perspective transformation.
where:
When
, the previous equation is equivalent to the following:
Real lenses usually have some radial distortion. So, the above model is extended as:
where
is the first order radial distortion. Higher order distortion coefficients are not considered in ViSP.
Now in ViSP we consider also the inverse transformation, where from pixel coordinates we want to compute their normalized coordinates in the image plane. Previous equations could be written like:
Considering radial distortion, the above model is extended as:
Finally, in ViSP the main intrinsic camera parameters are
the ratio between the focal length and the size of a pixel, and
the coordinates of the principal point in pixel. The lens distortion can also be considered by two additional parameters
.
From a practical point of view, two kinds of camera modelization are implemented in this class:
1.1.1. Camera parameters for a perspective projection without distortion model
In this modelization, only
parameters are considered.
Initialization of such a model can be done using:
1.1.2. Camera parameters for a perspective projection with distortion model
In this modelization, all the parameters
are considered. Initialization of such a model can be done using:
The selection of the camera model (without or with distortion) is done during vpCameraParameters initialisation.
Here an example of camera initialisation, for a model without distortion. A complete example is given in initPersProjWithoutDistortion().
Here an example of camera initialisation, for a model with distortion. A complete example is given in initPersProjWithDistortion().
The code below shows how to know the currently used projection model:
An XML parser for camera parameters is also provided in vpXmlParserCamera.
1.2. Kannala-Brandt camera model
This model [23] deals with fish-eye lenses designed to cover the whole hemispherical field in front of the camera and the angle of view is very large. In this case, the inherent distortion of a fish-eye lens should not be considered only as a derivation from the pinhole model.
The following projection in the general form is adapted:
where:
In ViSP, we only consider radially symmetric distortions (caused by fisheye lenses).
2. JSON serialization
Since ViSP 3.6.0, if ViSP is build with JSON for modern C++ 3rd-party we introduce JSON serialization capabilities for vpCameraParameters. The following sample code shows how to save camera parameters in a file named cam.json and reload the parameters from this JSON file.
If you build and execute the sample code, it will produce the following output:
The content of the cam.json file is the following:
Definition at line 310 of file vpCameraParameters.h.
Definition at line 316 of file vpCameraParameters.h.
| vpCameraParameters::vpCameraParameters | ( | ) |
Default constructor. By default, a perspective projection without distortion model is set.
Definition at line 67 of file vpCameraParameters.cpp.
References init().
Referenced by from_json, init(), operator!=(), operator<<, operator=(), operator==(), to_json, and vpCameraParameters().
| vpCameraParameters::vpCameraParameters | ( | const vpCameraParameters & | c | ) |
Copy constructor
Definition at line 79 of file vpCameraParameters.cpp.
References init(), and vpCameraParameters().
| vpCameraParameters::vpCameraParameters | ( | double | cam_px, |
| double | cam_py, | ||
| double | cam_u0, | ||
| double | cam_v0 ) |
Constructor for perspective projection without distortion model
| cam_px | : Pixel size along x axis (horizontal). |
| cam_py | : Pixel size along y axis (vertical) |
| cam_u0 | : Principal point coordinate in pixel along x. |
| cam_v0 | : Principal point coordinate in pixel along y. |
Definition at line 96 of file vpCameraParameters.cpp.
References initPersProjWithoutDistortion().
| vpCameraParameters::vpCameraParameters | ( | double | cam_px, |
| double | cam_py, | ||
| double | cam_u0, | ||
| double | cam_v0, | ||
| double | cam_kud, | ||
| double | cam_kdu ) |
Constructor for perspective projection with distortion model
| cam_px | : Pixel size along x axis (horizontal). |
| cam_py | : Pixel size along y axis (vertical) |
| cam_u0 | : Principal point coordinate in pixel along x. |
| cam_v0 | : Principal point coordinate in pixel along y. |
| cam_kud | : Undistorted to distorted radial distortion. |
| cam_kdu | : Distorted to undistorted radial distortion. |
Definition at line 115 of file vpCameraParameters.cpp.
References initPersProjWithDistortion().
| vpCameraParameters::vpCameraParameters | ( | double | cam_px, |
| double | cam_py, | ||
| double | cam_u0, | ||
| double | cam_v0, | ||
| const std::vector< double > & | coefficients ) |
Constructor for projection with Kannala-Brandt distortion model
| cam_px | : Pixel size along x axis (horizontal). |
| cam_py | : Pixel size along y axis (vertical) |
| cam_u0 | : Principal point coordinate in pixel along x. |
| cam_v0 | : Principal point coordinate in pixel along y. |
| coefficients | : distortion model coefficients |
Definition at line 134 of file vpCameraParameters.cpp.
References initProjWithKannalaBrandtDistortion().
|
virtual |
Destructor that does nothing.
Definition at line 334 of file vpCameraParameters.cpp.
| void vpCameraParameters::computeFov | ( | const unsigned int & | w, |
| const unsigned int & | h ) |
Compute angles and normals of the FOV.
| w | : Width of the image |
| h | : Height of the image. |
Definition at line 524 of file vpCameraParameters.cpp.
References vpColVector::normalize().
Referenced by vpMbtFaceDepthNormal::displayFeature(), vpMbtFaceDepthNormal::displayFeature(), vpMbDepthDenseTracker::getModelForDisplay(), vpMbDepthNormalTracker::getModelForDisplay(), vpMbKltTracker::getModelForDisplay(), vpMbtDistanceLine::getModelForDisplay(), initFromFov(), and vpMbtPolygon::isVisible().
| vpMatrix vpCameraParameters::get_K | ( | ) | const |
Return the camera matrix
given by:
![]()
Definition at line 591 of file vpCameraParameters.cpp.
| vpMatrix vpCameraParameters::get_K_inverse | ( | ) | const |
Return the inverted camera matrix
given by:
![]()
Definition at line 616 of file vpCameraParameters.cpp.
|
inline |
Definition at line 412 of file vpCameraParameters.h.
Referenced by vpCalibration::computeStdDeviation_dist().
|
inline |
Definition at line 411 of file vpCameraParameters.h.
Referenced by vpCalibration::computeStdDeviation_dist().
|
inline |
Definition at line 415 of file vpCameraParameters.h.
|
inline |
Definition at line 405 of file vpCameraParameters.h.
Referenced by vpCalibration::computeCalibration(), vpCalibration::computeCalibrationMulti(), vpCalibration::computeStdDeviation(), vpCalibration::computeStdDeviation_dist(), vpRBSilhouetteMeTracker::computeVVSIter(), vpRBSilhouetteMeTracker::extractFeatures(), vpSimulatorAfma6::initDisplay(), vpSimulatorViper850::initDisplay(), vpSimulator::setExternalCameraParameters(), and vpSimulator::setInternalCameraParameters().
|
inline |
Definition at line 406 of file vpCameraParameters.h.
|
inline |
Definition at line 408 of file vpCameraParameters.h.
Referenced by vpCalibration::computeCalibration(), vpCalibration::computeCalibrationMulti(), vpCalibration::computeStdDeviation(), vpCalibration::computeStdDeviation_dist(), vpSimulatorAfma6::initDisplay(), vpSimulatorViper850::initDisplay(), vpSimulator::setExternalCameraParameters(), and vpSimulator::setInternalCameraParameters().
|
inline |
Definition at line 407 of file vpCameraParameters.h.
|
inline |
Definition at line 409 of file vpCameraParameters.h.
Referenced by vpCalibration::computeCalibration(), vpCalibration::computeCalibrationMulti(), vpCalibration::computeStdDeviation(), and vpCalibration::computeStdDeviation_dist().
|
inline |
Definition at line 410 of file vpCameraParameters.h.
Referenced by vpCalibration::computeCalibration(), vpCalibration::computeCalibrationMulti(), vpCalibration::computeStdDeviation(), and vpCalibration::computeStdDeviation_dist().
|
inline |
Get the list of the normals corresponding to planes describing the field of view.
Definition at line 397 of file vpCameraParameters.h.
|
inline |
Get the horizontal angle in radian of the field of view.
Definition at line 362 of file vpCameraParameters.h.
|
inline |
Definition at line 413 of file vpCameraParameters.h.
|
inline |
Get the vertical angle in radian of the field of view.
Definition at line 377 of file vpCameraParameters.h.
| void vpCameraParameters::init | ( | ) |
Basic initialization with the default parameters.
Definition at line 147 of file vpCameraParameters.cpp.
References vpException::divideByZeroError.
Referenced by vpCameraParameters(), and vpCameraParameters().
| void vpCameraParameters::init | ( | const vpCameraParameters & | c | ) |
Initialization from another vpCameraParameters object.
Definition at line 339 of file vpCameraParameters.cpp.
References vpCameraParameters().
| void vpCameraParameters::initFromCalibrationMatrix | ( | const vpMatrix & | K | ) |
Initialise the camera from a calibration matrix. Using a calibration matrix leads to a camera without distortion.
The K matrix in parameters must be like:
![]()
| K | : the 3-by-3 calibration matrix |
Definition at line 355 of file vpCameraParameters.cpp.
References vpException::badValue, vpException::dimensionError, and initPersProjWithoutDistortion().
| void vpCameraParameters::initFromFov | ( | const unsigned int & | w, |
| const unsigned int & | h, | ||
| const double & | hfov, | ||
| const double & | vfov ) |
Initialize the camera model without distortion from the image dimension and the camera field of view.
| w | : Image width. |
| h | : Image height. |
| hfov | : Camera horizontal field of view angle expressed in radians. |
| vfov | : Camera vertical field of view angle expressed in radians. |
The following sample code shows how to use this function:
It produces the following output:
Definition at line 409 of file vpCameraParameters.cpp.
References computeFov(), and perspectiveProjWithoutDistortion.
| void vpCameraParameters::initPersProjWithDistortion | ( | double | cam_px, |
| double | cam_py, | ||
| double | cam_u0, | ||
| double | cam_v0, | ||
| double | cam_kud, | ||
| double | cam_kdu ) |
Initialization with specific parameters using perspective projection with distortion model.
| cam_px | : Pixel size along x axis (horizontal). |
| cam_py | : Pixel size along y axis (vertical) |
| cam_u0 | : Principal point coordinate in pixel along x. |
| cam_v0 | : Principal point coordinate in pixel along y. |
| cam_kud | : Undistorted to distorted radial distortion. |
| cam_kdu | : Distorted to undistorted radial distortion. |
The following sample code shows how to use this function:
It produces the following output:
Definition at line 274 of file vpCameraParameters.cpp.
References vpException::divideByZeroError, and perspectiveProjWithDistortion.
Referenced by vpCameraParameters().
| void vpCameraParameters::initPersProjWithoutDistortion | ( | double | cam_px, |
| double | cam_py, | ||
| double | cam_u0, | ||
| double | cam_v0 ) |
Initialization with specific parameters using perspective projection without distortion model.
| cam_px | : Pixel size along x axis (horizontal). |
| cam_py | : Pixel size along y axis (vertical) |
| cam_u0 | : Principal point coordinate in pixel along x. |
| cam_v0 | : Principal point coordinate in pixel along y. |
The following sample code shows how to use this function:
It produces the following output:
Definition at line 202 of file vpCameraParameters.cpp.
References vpException::divideByZeroError, and perspectiveProjWithoutDistortion.
Referenced by initFromCalibrationMatrix(), and vpCameraParameters().
| void vpCameraParameters::initProjWithKannalaBrandtDistortion | ( | double | cam_px, |
| double | cam_py, | ||
| double | cam_u0, | ||
| double | cam_v0, | ||
| const std::vector< double > & | coefficients ) |
Initialization with specific parameters using Kannala-Brandt distortion model
| cam_px | : Pixel size along x axis (horizontal). |
| cam_py | : Pixel size along y axis (vertical) |
| cam_u0 | : Principal point coordinate in pixel along x. |
| cam_v0 | : Principal point coordinate in pixel along y. |
| coefficients | : Distortion coefficients. |
Definition at line 306 of file vpCameraParameters.cpp.
References vpException::divideByZeroError, and ProjWithKannalaBrandtDistortion.
Referenced by vpCameraParameters().
|
inline |
Specify if the fov has been computed.
Definition at line 351 of file vpCameraParameters.h.
| bool vpCameraParameters::operator!= | ( | const vpCameraParameters & | c | ) | const |
False if the two objects are absolutely identical.
Definition at line 516 of file vpCameraParameters.cpp.
References vpCameraParameters().
| vpCameraParameters & vpCameraParameters::operator= | ( | const vpCameraParameters & | cam | ) |
Copy operator.
Definition at line 427 of file vpCameraParameters.cpp.
References vpCameraParameters().
| bool vpCameraParameters::operator== | ( | const vpCameraParameters & | c | ) | const |
True if the two objects are absolutely identical.
Definition at line 454 of file vpCameraParameters.cpp.
References vpMath::equal(), and vpCameraParameters().
| void vpCameraParameters::printParameters | ( | ) |
Print the camera parameters on the standard output.
Definition at line 637 of file vpCameraParameters.cpp.
References vpException::fatalError, perspectiveProjWithDistortion, perspectiveProjWithoutDistortion, ProjWithKannalaBrandtDistortion, and vpArray2D< Type >::size().
Referenced by vpCalibration::computeCalibration(), and vpCalibration::computeCalibrationMulti().
|
friend |
Deserialize a JSON object into camera parameters. The minimal required properties are:
If a projection model (vpCameraParameters::vpCameraParametersProjType) is supplied, then other parameters may be expected:
An example of a JSON object representing a camera is:
| j | The json object to deserialize. |
| cam | The modified camera. |
Definition at line 534 of file vpCameraParameters.h.
References vpException::fatalError, from_json, perspectiveProjWithDistortion, perspectiveProjWithoutDistortion, ProjWithKannalaBrandtDistortion, and vpCameraParameters().
Referenced by from_json.
|
friend |
Print on the output stream os the camera parameters.
| os | : Output stream. |
| cam | : Camera parameters. |
Definition at line 682 of file vpCameraParameters.cpp.
References vpException::fatalError, operator<<, perspectiveProjWithDistortion, perspectiveProjWithoutDistortion, ProjWithKannalaBrandtDistortion, and vpCameraParameters().
Referenced by operator<<.
|
friend |
Converts camera parameters into a JSON representation.
| j | The resulting JSON object. |
| cam | The camera to serialize. |
Definition at line 480 of file vpCameraParameters.h.
References vpException::fatalError, perspectiveProjWithDistortion, perspectiveProjWithoutDistortion, ProjWithKannalaBrandtDistortion, to_json, and vpCameraParameters().
Referenced by to_json.
|
friend |
Definition at line 312 of file vpCameraParameters.h.
References vpMeterPixelConversion.
Referenced by vpMeterPixelConversion.
|
friend |
Definition at line 313 of file vpCameraParameters.h.
References vpPixelMeterConversion.
Referenced by vpPixelMeterConversion.