78 for (
int i = 0; i < 4; i++)
118 float d1,
float d2,
float d3,
float d4,
215 if (bUseDistortionParameters)
223 if (bUseDistortionParameters)
248 for (
int i = 0; i < 10; i++)
251 const float rr = x * x + y *
y;
252 const float factor = 1 + d1 * rr + d2 * rr * rr;
255 const float dx = d3 * (2 * x *
y) + d4 * (rr + 2 * x * x);
256 const float dy = d3 * (rr + 2 * y *
y) + d4 * (2 * x * y);
258 x = (x_const - dx) / factor;
259 y = (y_const - dy) / factor;
278 const float rr = x * x +
y *
y;
279 const float factor = 1 + d1 * rr + d2 * rr * rr;
282 const float dx = d3 * (2 * x *
y) + d4 * (rr + 2 * x * x);
283 const float dy = d3 * (rr + 2 * y *
y) + d4 * (2 * x * y);
314 int i, nCameraCount = 0;
316 FILE* f = fopen(pCameraParameterFileName,
"r");
320 if (fscanf(f,
"%d", &nCameraCount) != 1 || nCameraCount < nCamera + 1)
326 float skip_value,
w, h;
328 for (i = 0; i < nCamera; i++)
329 for (
int j = 0; j < 27; j++)
330 if (fscanf(f,
"%f", &skip_value) != 1)
336 if (fscanf(f,
"%f", &w) != 1) { fclose(f);
return false; }
337 if (fscanf(f,
"%f", &h) != 1) { fclose(f);
return false; }
339 if (fscanf(f,
"%f", &skip_value) != 1) { fclose(f);
return false; }
341 if (fscanf(f,
"%f", &skip_value) != 1) { fclose(f);
return false; }
344 if (fscanf(f,
"%f", &skip_value) != 1) { fclose(f);
return false; }
345 if (fscanf(f,
"%f", &skip_value) != 1) { fclose(f);
return false; }
346 if (fscanf(f,
"%f", &skip_value) != 1) { fclose(f);
return false; }
347 for (i = 0; i < 4; i++)
367 if (bSetExtrinsicToIdentity)
395 FILE *f = fopen(pFileName,
"w");
400 fprintf(f,
"%i %i %.10f %.10f %.10f %.10f %.10f %.10f %.10f %.10f %.10f ",
m_cameraParameters.
width,
m_cameraParameters.
height, fx, 0.0, cx, 0.0, fy, cy, 0.0, 0.0, 1.0);
401 fprintf(f,
"%.10f %.10f %.10f %.10f ", d1, d2, d3, d4);
402 fprintf(f,
"%.10f %.10f %.10f %.10f %.10f %.10f %.10f %.10f %.10f ", rotation.
r1, rotation.
r2, rotation.
r3, rotation.
r4, rotation.
r5, rotation.
r6, rotation.
r7, rotation.
r8, rotation.
r9);
403 fprintf(f,
"%.10f %.10f %.10f\n", translation.
x, translation.
y, translation.
z);
412 printf(
"cx/cy = %.10f / %.10f\nfx/fy = %.10f / %.10f\nt = %.10f %.10f %.10f\nR = %.10f %.10f %.10f %.10f %.10f %.10f %.10f %.10f %.10f\nd1/d2/d3/d4 = %.10f %.10f %.10f %.10f\n\n",
Struct containing all parameters of the camera model.
Mat3d m_rotation_inverse
Rotation matrix of the inverted extrinsic transformation.
void SetDistortion(float d1, float d2, float d3, float d4)
Sets the distortion parameters of the distortion model.
void ImageToCameraCoordinates(const Vec2d &imagePoint, Vec3d &cameraPoint, float zc=1.0f, bool bUseDistortionParameters=true) const
Transforms 2D image coordinates to 3D camera coordinates.
CCameraParameters m_cameraParameters
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 UndistortImageCoordinates(const Vec2d &distortedImagePoint, Vec2d &undistortedImagePoint) const
Transforms 2D distorted image coordinates to 2D undistorted image coordinates.
void CameraToWorldCoordinates(const Vec3d &cameraPoint, Vec3d &worldPoint) const
Transforms 3D camera coordinates to 3D world coordinates.
void Transpose(const Mat3d &matrix, Mat3d &result)
bool LoadCameraParameters(const char *pCameraParameterFileName, int nCamera=0, bool bSetExtrinsicToIdentity=false)
Initializes the camera model, given a file path to a camera parameter file.
Data structure for the representation of a 3D vector.
void CameraToImageCoordinates(const Vec3d &cameraPoint, Vec2d &imagePoint, bool bUseDistortionParameters=true) const
Transforms 3D camera coordinates to 2D image coordinates.
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 PrintCameraParameters() const
Prints all camera parameters in the console window (STDOUT).
const CCameraParameters & GetCameraParameters() const
Gives access to the camera parameters.
bool SaveCameraParameters(const char *pCameraParameterFileName) const
Writes the parameters of the camera model to camera parameter file.
void SetVec(Vec3d &vec, float x, float y, float z)
void GetCameraCoordinates(const Vec3d &worldPoint, Vec2d &imagePoint, bool bUseDistortionParameters=true) const
Deprecated.
void ImageToWorldCoordinates(const Vec2d &imagePoint, Vec3d &worldPoint, float zc=1.0f, bool bUseDistortionParameters=true) const
Transforms 2D image coordinates to 3D world coordinates.
void MulVecScalar(const Vec3d &vec, float scalar, Vec3d &result)
void GetProjectionMatrix(Mat3d &P1, Vec3d &p2) const
Sets up the projection matrix P.
void SetIntrinsicBase(float cx, float cy, float fx, float fy)
Sets the principal point and the focal lengths.
void GetWorldCoordinates(const Vec2d &imagePoint, Vec3d &worldPoint, float zc=1.0f, bool bUseDistortionParameters=true) const
Deprecated.
void MulMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result)
void MulMatVec(const Mat3d &matrix, const Vec3d &vec, Vec3d &result)
~CCalibration()
The destructor.
void UndistortCameraCoordinates(const Vec2d &distortedCameraPoint, Vec2d &undistortedCameraPoint) const
Deprecated.
void DistortCameraCoordinates(const Vec2d &undistortedCameraPoint, Vec2d &distortedCameraPoint) const
Deprecated.
CCalibration()
The default constructor.
Vec3d m_translation_inverse
Translation vector of the inverted extrinsic transformation.
GLenum GLsizei GLsizei height
void Set(const CCalibration &calibration)
Initializes the camera model, given an instance of CCalibration.
Data structure for the representation of a 2D vector.
void SetTranslation(const Vec3d &t)
Sets the extrinsic parameter t (translation vector).
void CalculateInverseTransformation()
void SetVec(Vec2d &vec, float x, float y)
void WorldToCameraCoordinates(const Vec3d &worldPoint, Vec3d &cameraPoint) const
Transforms 3D world coordinates to 3D camera coordinates.
void SetRotation(const Mat3d &R)
Sets the extrinsic parameter R (rotation matrix).
void SetMat(Mat3d &matrix, float r1, float r2, float r3, float r4, float r5, float r6, float r7, float r8, float r9)
Data structure for the representation of a 3x3 matrix.
GLubyte GLubyte GLubyte GLubyte w
Camera model parameters and functions for a single camera.
void WorldToImageCoordinates(const Vec3d &worldPoint, Vec2d &imagePoint, bool bUseDistortionParameters=true) const
Transforms 3D world coordinates to 2D image coordinates.