SLProject
4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
Live video camera calibration class with OpenCV an OpenCV calibration. More...
#include <CVCalibration.h>
Public Member Functions | |
CVCalibration (CVCameraType camType, string computerInfos) | |
CVCalibration (const cv::Mat &cameraMat, const cv::Mat &distortion, cv::Size imageSize, cv::Size boardSize, float boardSquareMM, float reprojectionError, int numCaptured, const string &calibrationTime, int camSizeIndex, bool mirroredH, bool mirroredV, CVCameraType camType, string computerInfos, int calibFlags, bool calcUndistortionMaps) | |
CVCalibration (const cv::Size &imageSize, float fovH, bool mirroredH, bool mirroredV, CVCameraType camType, string computerInfos) | |
CVCalibration (float sensorWMM, float sensorHMM, float focalLengthMM, const cv::Size &imageSize, bool mirroredH, bool mirroredV, CVCameraType camType, string computerInfos) | |
bool | load (const string &calibDir, const string &calibFileName, bool calcUndistortionMaps) |
Loads the calibration information from the config file. More... | |
bool | save (const string &calibDir, const string &calibFileName) |
Saves the camera calibration parameters to the config file. More... | |
void | remap (CVMat &inDistorted, CVMat &outUndistorted) |
Undistorts the inDistorted image into the outUndistorted. More... | |
void | adaptForNewResolution (const CVSize &newSize, bool calcUndistortionMaps) |
Adapts an already calibrated camera to a new resolution (cropping and scaling) More... | |
void | buildUndistortionMaps () |
Builds undistortion maps after calibration or loading. More... | |
CVSize | imageSize () const |
CVSize | imageSizeOriginal () const |
float | imageAspectRatio () const |
const CVMat & | cameraMat () const |
const CVMat & | cameraMatUndistorted () const |
const CVMat & | distortion () const |
float | cameraFovVDeg () const |
float | cameraFovHDeg () const |
int | calibrationFlags () |
bool | calibFixPrincipalPoint () |
bool | calibFixAspectRatio () |
bool | calibZeroTangentDist () |
bool | calibRationalModel () |
bool | calibTiltedModel () |
bool | calibThinPrismModel () |
bool | isMirroredH () |
bool | isMirroredV () |
float | fx () const |
float | fy () const |
float | cx () const |
float | cy () const |
float | k1 () const |
float | k2 () const |
float | p1 () const |
float | p2 () const |
float | k3 () const |
float | k4 () const |
float | k5 () const |
float | k6 () const |
float | s1 () const |
float | s2 () const |
float | s3 () const |
float | s4 () const |
float | tauX () const |
float | tauY () const |
CVCameraType | camType () const |
CVCalibState | state () const |
int | numCapturedImgs () const |
float | reprojectionError () const |
CVSize | boardSize () const |
float | boardSquareMM () const |
float | boardSquareM () const |
string | calibrationTime () const |
string | calibFileName () const |
string | computerInfos () const |
string | stateStr () const |
Private Member Functions | |
void | calcCameraFovFromUndistortedCameraMat () |
Calculates the vertical field of view angle in degrees. More... | |
void | calculateUndistortedCameraMat () |
Calculate a camera matrix that we use for the scene graph and for the reprojection of the undistorted image. More... | |
void | createFromGuessedFOV (int imageWidthPX, int imageHeightPX, float fovH) |
Calculates camera intrinsics from a guessed FOV angle. More... | |
Private Attributes | |
CVMat | _cameraMat |
3x3 Matrix for intrinsic camera matrix More... | |
CVMat | _distortion |
4x1 Matrix for intrinsic distortion More... | |
CVMat | _cameraMatOrig |
3x3 Matrix for intrinsic camera matrix (original from loading or calibration estimation) More... | |
CVSize | _imageSizeOrig |
original image size (original from loading or calibration estimation) More... | |
CVCalibState | _state = CS_uncalibrated |
calibration state enumeration More... | |
float | _cameraFovVDeg = 0.0f |
Vertical field of view in degrees. More... | |
float | _cameraFovHDeg = 0.0f |
Horizontal field of view in degrees. More... | |
string | _calibFileName |
name for calibration file More... | |
int | _calibFlags = 0 |
OpenCV calibration flags. More... | |
bool | _isMirroredH = false |
Flag if image must be horizontally mirrored. More... | |
bool | _isMirroredV = false |
Flag if image must be vertically mirrored. More... | |
int | _numCaptured = 0 |
NO. of images captured. More... | |
CVSize | _boardSize |
NO. of inner chessboard corners. More... | |
float | _boardSquareMM = 20.f |
Size of chessboard square in mm. More... | |
float | _reprojectionError = -1.0f |
Reprojection error after calibration. More... | |
CVSize | _imageSize |
Input image size in pixels (after cropping) More... | |
int | _camSizeIndex = -1 |
The requested camera size index. More... | |
CVMat | _undistortMapX |
Undistortion float map in x-direction. More... | |
CVMat | _undistortMapY |
Undistortion float map in y-direction. More... | |
CVMat | _cameraMatUndistorted |
Camera matrix that defines scene camera and may also be used for reprojection of undistorted image. More... | |
string | _calibrationTime = "-" |
Time stamp string of calibration. More... | |
string | _computerInfos |
CVCameraType | _camType = CVCameraType::FRONTFACING |
Static Private Attributes | |
static const int | _CALIBFILEVERSION = 6 |
Global const file format version. More... | |
Live video camera calibration class with OpenCV an OpenCV calibration.
The camera calibration can determine the inner or intrinsic parameters such as the focal length and the lens distortion and external or extrinsic parameter such as the camera pose towards a known geometry.
For a good calibration we have to make 15-20 images from a chessboard pattern. The chessboard pattern can be printed from the CalibrationChessboard_8x5_A4.pdf in the folder data/calibration. It is important that one side has an odd number of inner corners. Like this it is unambiguous and can be rotated in any direction.
The different calibration states are handled within AppDemoTracking::onUpdateTracking:
Definition at line 70 of file CVCalibration.h.
CVCalibration::CVCalibration | ( | CVCameraType | camType, |
string | computerInfos | ||
) |
Definition at line 30 of file CVCalibration.cpp.
CVCalibration::CVCalibration | ( | const cv::Mat & | cameraMat, |
const cv::Mat & | distortion, | ||
cv::Size | imageSize, | ||
cv::Size | boardSize, | ||
float | boardSquareMM, | ||
float | reprojectionError, | ||
int | numCaptured, | ||
const string & | calibrationTime, | ||
int | camSizeIndex, | ||
bool | mirroredH, | ||
bool | mirroredV, | ||
CVCameraType | camType, | ||
string | computerInfos, | ||
int | calibFlags, | ||
bool | calcUndistortionMaps | ||
) |
Definition at line 49 of file CVCalibration.cpp.
CVCalibration::CVCalibration | ( | const cv::Size & | imageSize, |
float | fovH, | ||
bool | mirroredH, | ||
bool | mirroredV, | ||
CVCameraType | camType, | ||
string | computerInfos | ||
) |
Definition at line 89 of file CVCalibration.cpp.
CVCalibration::CVCalibration | ( | float | sensorWMM, |
float | sensorHMM, | ||
float | focalLengthMM, | ||
const cv::Size & | imageSize, | ||
bool | mirroredH, | ||
bool | mirroredV, | ||
CVCameraType | camType, | ||
string | computerInfos | ||
) |
Definition at line 106 of file CVCalibration.cpp.
Adapts an already calibrated camera to a new resolution (cropping and scaling)
Definition at line 438 of file CVCalibration.cpp.
|
inline |
Definition at line 170 of file CVCalibration.h.
|
inline |
Definition at line 172 of file CVCalibration.h.
|
inline |
Definition at line 171 of file CVCalibration.h.
void CVCalibration::buildUndistortionMaps | ( | ) |
Builds undistortion maps after calibration or loading.
Definition at line 344 of file CVCalibration.cpp.
|
private |
Calculates the vertical field of view angle in degrees.
Definition at line 562 of file CVCalibration.cpp.
|
private |
Calculate a camera matrix that we use for the scene graph and for the reprojection of the undistorted image.
(The following is the algorithm from cv::getOptimalNewCameraMatrix and the code is here for understanding (it does the same))
Definition at line 496 of file CVCalibration.cpp.
|
inline |
Definition at line 174 of file CVCalibration.h.
|
inline |
Definition at line 139 of file CVCalibration.h.
|
inline |
Definition at line 138 of file CVCalibration.h.
|
inline |
Definition at line 141 of file CVCalibration.h.
|
inline |
Definition at line 137 of file CVCalibration.h.
|
inline |
Definition at line 173 of file CVCalibration.h.
|
inline |
Definition at line 143 of file CVCalibration.h.
|
inline |
Definition at line 142 of file CVCalibration.h.
|
inline |
Definition at line 140 of file CVCalibration.h.
|
inline |
Definition at line 135 of file CVCalibration.h.
|
inline |
Definition at line 134 of file CVCalibration.h.
|
inline |
Definition at line 131 of file CVCalibration.h.
|
inline |
Definition at line 132 of file CVCalibration.h.
|
inline |
Definition at line 166 of file CVCalibration.h.
|
inline |
Definition at line 175 of file CVCalibration.h.
|
private |
Calculates camera intrinsics from a guessed FOV angle.
Most laptop-, webcam- or mobile camera have a horizontal view angle or so called field of view (FOV) of around 65 degrees. From this parameter we can calculate the most important intrinsic parameter the focal length. All other parameters are set as if the lens would be perfect: No lens distortion and the view axis goes through the center of the image. If the focal length and sensor size is provided by the device we deduce the the fovV from it.
imageWidthPX | Height of image in pixels |
imageHeightPX | Width of image in pixels |
fovH | Average horizontal view angle in degrees |
Definition at line 407 of file CVCalibration.cpp.
|
inline |
Definition at line 149 of file CVCalibration.h.
|
inline |
Definition at line 150 of file CVCalibration.h.
|
inline |
Definition at line 133 of file CVCalibration.h.
|
inline |
Definition at line 147 of file CVCalibration.h.
|
inline |
Definition at line 148 of file CVCalibration.h.
|
inline |
Definition at line 130 of file CVCalibration.h.
|
inline |
Definition at line 126 of file CVCalibration.h.
|
inline |
Definition at line 127 of file CVCalibration.h.
|
inline |
Definition at line 144 of file CVCalibration.h.
|
inline |
Definition at line 145 of file CVCalibration.h.
|
inline |
Definition at line 151 of file CVCalibration.h.
|
inline |
Definition at line 152 of file CVCalibration.h.
|
inline |
Definition at line 155 of file CVCalibration.h.
|
inline |
Definition at line 156 of file CVCalibration.h.
|
inline |
Definition at line 157 of file CVCalibration.h.
|
inline |
Definition at line 158 of file CVCalibration.h.
bool CVCalibration::load | ( | const string & | calibDir, |
const string & | calibFileName, | ||
bool | calcUndistortionMaps | ||
) |
Loads the calibration information from the config file.
Added a flag to disable calculation of undistortion maps because this may take a lot of time for big images on mobile devices
Definition at line 138 of file CVCalibration.cpp.
|
inline |
Definition at line 168 of file CVCalibration.h.
|
inline |
Definition at line 153 of file CVCalibration.h.
|
inline |
Definition at line 154 of file CVCalibration.h.
Undistorts the inDistorted image into the outUndistorted.
Definition at line 378 of file CVCalibration.cpp.
|
inline |
Definition at line 169 of file CVCalibration.h.
|
inline |
Definition at line 159 of file CVCalibration.h.
|
inline |
Definition at line 160 of file CVCalibration.h.
|
inline |
Definition at line 161 of file CVCalibration.h.
|
inline |
Definition at line 162 of file CVCalibration.h.
bool CVCalibration::save | ( | const string & | calibDir, |
const string & | calibFileName | ||
) |
Saves the camera calibration parameters to the config file.
Definition at line 225 of file CVCalibration.cpp.
|
inline |
Definition at line 167 of file CVCalibration.h.
|
inline |
Definition at line 176 of file CVCalibration.h.
|
inline |
Definition at line 163 of file CVCalibration.h.
|
inline |
Definition at line 164 of file CVCalibration.h.
|
private |
NO. of inner chessboard corners.
Definition at line 210 of file CVCalibration.h.
|
private |
Size of chessboard square in mm.
Definition at line 211 of file CVCalibration.h.
|
private |
name for calibration file
Definition at line 204 of file CVCalibration.h.
|
staticprivate |
Global const file format version.
Increase the _CALIBFILEVERSION each time you change the file format.
Definition at line 223 of file CVCalibration.h.
|
private |
OpenCV calibration flags.
Definition at line 205 of file CVCalibration.h.
|
private |
Time stamp string of calibration.
Definition at line 219 of file CVCalibration.h.
|
private |
Horizontal field of view in degrees.
Definition at line 203 of file CVCalibration.h.
|
private |
Vertical field of view in degrees.
Definition at line 202 of file CVCalibration.h.
|
private |
3x3 Matrix for intrinsic camera matrix
Definition at line 193 of file CVCalibration.h.
|
private |
3x3 Matrix for intrinsic camera matrix (original from loading or calibration estimation)
Definition at line 198 of file CVCalibration.h.
|
private |
Camera matrix that defines scene camera and may also be used for reprojection of undistorted image.
Definition at line 218 of file CVCalibration.h.
|
private |
The requested camera size index.
Definition at line 214 of file CVCalibration.h.
|
private |
Definition at line 221 of file CVCalibration.h.
|
private |
Definition at line 220 of file CVCalibration.h.
|
private |
4x1 Matrix for intrinsic distortion
Definition at line 194 of file CVCalibration.h.
|
private |
Input image size in pixels (after cropping)
Definition at line 213 of file CVCalibration.h.
|
private |
original image size (original from loading or calibration estimation)
Definition at line 199 of file CVCalibration.h.
|
private |
Flag if image must be horizontally mirrored.
Definition at line 206 of file CVCalibration.h.
|
private |
Flag if image must be vertically mirrored.
Definition at line 207 of file CVCalibration.h.
|
private |
NO. of images captured.
Definition at line 209 of file CVCalibration.h.
|
private |
Reprojection error after calibration.
Definition at line 212 of file CVCalibration.h.
|
private |
calibration state enumeration
Definition at line 201 of file CVCalibration.h.
|
private |
Undistortion float map in x-direction.
Definition at line 216 of file CVCalibration.h.
|
private |
Undistortion float map in y-direction.
Definition at line 217 of file CVCalibration.h.