SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
CVCalibration.cpp
Go to the documentation of this file.
1 /**
2  * \file CVCalibration.cpp
3  * \date Winter 2016
4  * \remarks Please use clangformat to format the code. See more code style on
5  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
6  * \authors Marcus Hudritsch, Michael Goettlicher
7  * \copyright http://opensource.org/licenses/GPL-3.0
8  */
9 
10 /*
11 The OpenCV library version 3.4 or above with extra module must be present.
12 If the application captures the live video stream with OpenCV you have
13 to define in addition the constant APP_USES_CVCAPTURE.
14 All classes that use OpenCV begin with CV.
15 See also the class docs for CVCapture, CVCalibration and CVTracked
16 for a good top down information.
17 */
18 
19 #include <CVCalibration.h>
20 #include <Utils.h>
21 #include <HighResTimer.h>
22 
23 #include <utility>
24 
25 //-----------------------------------------------------------------------------
26 //! Increase the _CALIBFILEVERSION each time you change the file format
27 // Version 6, Date: 6.JUL.2019: Added device parameter from Android
29 //-----------------------------------------------------------------------------
30 CVCalibration::CVCalibration(CVCameraType type, string computerInfos)
31  : _state(CS_uncalibrated),
32  _cameraFovHDeg(0.0f),
33  _cameraFovVDeg(0.0f),
34  _calibFileName(""), // is set in load
35  _boardSize(0, 0),
36  _boardSquareMM(0.0f),
37  _numCaptured(0),
38  _reprojectionError(-1.0f),
39  _camSizeIndex(-1),
40  _calibrationTime("-"),
41  _isMirroredH(false),
42  _isMirroredV(false),
43  _camType(type),
44  _computerInfos(std::move(computerInfos))
45 {
46 }
47 //-----------------------------------------------------------------------------
48 // creates a fully defined calibration
49 CVCalibration::CVCalibration(const cv::Mat& cameraMat,
50  const cv::Mat& distortion,
51  cv::Size imageSize,
52  cv::Size boardSize,
53  float boardSquareMM,
54  float reprojectionError,
55  int numCaptured,
56  const string& calibrationTime,
57  int camSizeIndex,
58  bool mirroredH,
59  bool mirroredV,
60  CVCameraType camType,
61  string computerInfos,
62  int calibFlags,
63  bool calcUndistortionMaps)
64  : _cameraMat(cameraMat.clone()),
65  _distortion(distortion.clone()),
66  _imageSize(std::move(imageSize)),
67  _boardSize(std::move(boardSize)),
68  _boardSquareMM(boardSquareMM),
69  _reprojectionError(reprojectionError),
70  _numCaptured(numCaptured),
71  _calibrationTime(calibrationTime),
72  _camSizeIndex(camSizeIndex),
73  _isMirroredH(mirroredH),
74  _isMirroredV(mirroredV),
75  _camType(camType),
76  _computerInfos(std::move(computerInfos)),
77  _calibFlags(calibFlags)
78 {
79  _cameraMatOrig = _cameraMat.clone();
81 
86 }
87 //-----------------------------------------------------------------------------
88 // create a guessed calibration using image size and horizontal fovV angle
89 CVCalibration::CVCalibration(const cv::Size& imageSize,
90  float fovH,
91  bool mirroredH,
92  bool mirroredV,
93  CVCameraType camType,
94  string computerInfos)
95  : _isMirroredH(mirroredH),
96  _isMirroredV(mirroredV),
97  _camType(camType),
98  _computerInfos(std::move(computerInfos))
99 {
100  createFromGuessedFOV(imageSize.width, imageSize.height, fovH);
101  _cameraMatOrig = _cameraMat.clone();
103 }
104 //-----------------------------------------------------------------------------
105 // create a guessed calibration using sensor size, camera focal length and captured image size
107  float sensorHMM,
108  float focalLengthMM,
109  const cv::Size& imageSize,
110  bool mirroredH,
111  bool mirroredV,
112  CVCameraType camType,
113  string computerInfos)
114  : _isMirroredH(mirroredH),
115  _isMirroredV(mirroredV),
116  _camType(camType),
117  _computerInfos(std::move(computerInfos))
118 {
119  // aspect ratio
120  float devFovH = 2.0f * atan(sensorWMM / (2.0f * focalLengthMM)) * Utils::RAD2DEG;
121  if (devFovH > 60.0f && devFovH < 70.0f)
122  {
123  createFromGuessedFOV(imageSize.width, imageSize.height, devFovH);
124  }
125  else
126  {
127  // if not between
128  createFromGuessedFOV(imageSize.width, imageSize.height, 65.0);
129  }
130  _cameraMatOrig = _cameraMat.clone();
132 }
133 //-----------------------------------------------------------------------------
134 //! Loads the calibration information from the config file
135 /*! Added a flag to disable calculation of undistortion maps because this may take
136  a lot of time for big images on mobile devices
137 */
138 bool CVCalibration::load(const string& calibDir,
139  const string& calibFileName,
140  bool calcUndistortionMaps)
141 {
142  // load camera parameter
143  string fullPathAndFilename = Utils::unifySlashes(calibDir) + calibFileName;
144 
145  // try to open the local calibration file
146  cv::FileStorage fs(fullPathAndFilename, cv::FileStorage::READ);
147  if (!fs.isOpened())
148  {
149  Utils::log("SLProject", "Calibration : %s", calibFileName.c_str());
150  Utils::log("SLProject", "Calib. created : No. Calib. will be estimated");
151  _numCaptured = 0;
152  _isMirroredH = false;
153  _isMirroredV = false;
154  _reprojectionError = 0;
155  _calibrationTime = "-";
157  _camSizeIndex = -1;
158  return false;
159  }
160 
161  // Reset if new file format version is available
162  int calibFileVersion = 0;
163  fs["CALIBFILEVERSION"] >> calibFileVersion;
164  if (calibFileVersion < _CALIBFILEVERSION)
165  {
166  _numCaptured = 0;
167  _reprojectionError = -1;
168  _calibrationTime = "-";
170  _camSizeIndex = -1;
171  }
172  else
173  {
174  fs["imageSizeWidth"] >> _imageSize.width;
175  fs["imageSizeHeight"] >> _imageSize.height;
176  fs["numCaptured"] >> _numCaptured;
177  fs["isMirroredH"] >> _isMirroredH;
178  fs["isMirroredV"] >> _isMirroredV;
179  fs["cameraMat"] >> _cameraMat;
180  fs["distortion"] >> _distortion;
181  fs["reprojectionError"] >> _reprojectionError;
182  fs["calibrationTime"] >> _calibrationTime;
183  fs["camSizeIndex"] >> _camSizeIndex;
184  fs["boardSizeWidth"] >> _boardSize.width;
185  fs["boardSizeHeight"] >> _boardSize.height;
186  fs["boardSquareMM"] >> _boardSquareMM;
188  }
189 
190  // estimate computer infos
191  if (!fs["computerInfos"].empty())
192  fs["computerInfos"] >> _computerInfos;
193  else
194  {
195  vector<string> stringParts;
197  if (stringParts.size() >= 3)
198  _computerInfos = stringParts[1];
199  }
200 
201  // close the input file
202  fs.release();
203 
204  // calculate FOV and undistortion maps
205  if (_state == CS_calibrated)
206  {
207  // calcCameraFov();
210  if (calcUndistortionMaps)
212  }
213 
214  Utils::log("SLProject", "Calib. loaded : %s", fullPathAndFilename.c_str());
215  Utils::log("SLProject", "Calib. created : %s", _calibrationTime.c_str());
216  Utils::log("SLProject", "Camera FOV H/V : %3.1f/%3.1f", _cameraFovVDeg, _cameraFovHDeg);
217 
218  _cameraMatOrig = _cameraMat.clone();
220 
221  return true;
222 }
223 //-----------------------------------------------------------------------------
224 //! Saves the camera calibration parameters to the config file
225 bool CVCalibration::save(const string& calibDir,
226  const string& calibFileName)
227 {
228  string fullPathAndFilename = Utils::unifySlashes(calibDir) + calibFileName;
229 
230  cv::FileStorage fs(fullPathAndFilename, cv::FileStorage::WRITE);
231 
232  if (!fs.isOpened())
233  {
234  Utils::log("SLProject", "Failed to write calib. %s", fullPathAndFilename.c_str());
235  return false;
236  }
237 
238  char buf[1024];
239  snprintf(buf,
240  sizeof(buf),
241  "flags:%s%s%s%s%s%s%s",
242  _calibFlags & cv::CALIB_USE_INTRINSIC_GUESS ? " +use_intrinsic_guess" : "",
243  _calibFlags & cv::CALIB_FIX_ASPECT_RATIO ? " +fix_aspectRatio" : "",
244  _calibFlags & cv::CALIB_FIX_PRINCIPAL_POINT ? " +fix_principal_point" : "",
245  _calibFlags & cv::CALIB_ZERO_TANGENT_DIST ? " +zero_tangent_dist" : "",
246  _calibFlags & cv::CALIB_RATIONAL_MODEL ? " +rational_model" : "",
247  _calibFlags & cv::CALIB_THIN_PRISM_MODEL ? " +thin_prism_model" : "",
248  _calibFlags & cv::CALIB_TILTED_MODEL ? " +tilted_model" : "");
249  fs.writeComment(buf, 0);
250 
251  fs << "CALIBFILEVERSION" << _CALIBFILEVERSION;
252  fs << "calibrationTime" << _calibrationTime;
253  fs << "imageSizeWidth" << _imageSize.width;
254  fs << "imageSizeHeight" << _imageSize.height;
255  fs << "boardSizeWidth" << _boardSize.width; // do not reload
256  fs << "boardSizeHeight" << _boardSize.height; // do not reload
257  fs << "boardSquareMM" << _boardSquareMM; // do not reload
258  fs << "numCaptured" << _numCaptured;
259  fs << "calibFlags" << _calibFlags;
260  fs << "isMirroredH" << _isMirroredH;
261  fs << "isMirroredV" << _isMirroredV;
262  fs << "calibFixAspectRatio" << (_calibFlags & cv::CALIB_FIX_ASPECT_RATIO);
263  fs << "calibFixPrincipalPoint" << (_calibFlags & cv::CALIB_FIX_PRINCIPAL_POINT);
264  fs << "calibZeroTangentDist" << (_calibFlags & cv::CALIB_ZERO_TANGENT_DIST);
265  fs << "calibRationalModel" << (_calibFlags & cv::CALIB_RATIONAL_MODEL);
266  fs << "calibTiltedModel" << (_calibFlags & cv::CALIB_TILTED_MODEL);
267  fs << "calibThinPrismModel" << (_calibFlags & cv::CALIB_THIN_PRISM_MODEL);
268  fs << "cameraMat" << _cameraMat;
269  fs << "distortion" << _distortion;
270  fs << "reprojectionError" << _reprojectionError;
271  fs << "cameraFovVDeg" << _cameraFovVDeg;
272  fs << "cameraFovHDeg" << _cameraFovHDeg;
273  fs << "camSizeIndex" << _camSizeIndex;
274  fs << "computerInfos" << _computerInfos;
275 
276  // close file
277  fs.release();
278  Utils::log("SLProject", "Calib. saved : %s", fullPathAndFilename.c_str());
279  return true;
280  // uploadCalibration(fullPathAndFilename);
281 }
282 //-----------------------------------------------------------------------------
283 //! get inscribed and circumscribed rectangle
284 void getInnerAndOuterRectangles(const cv::Mat& cameraMatrix,
285  const cv::Mat& distCoeffs,
286  const cv::Mat& R,
287  const cv::Mat& newCameraMatrix,
288  const cv::Size& imgSize,
289  cv::Rect_<float>& inner,
290  cv::Rect_<float>& outer)
291 {
292  const int N = 9;
293  // Fill matrix with N * N sampling points
294  cv::Mat pts(N * N, 2, CV_32F);
295  for (int y = 0, k = 0; y < N; y++)
296  {
297  for (int x = 0; x < N; x++)
298  {
299  pts.at<float>(k, 0) = (float)x * (float)imgSize.width / (N - 1);
300  pts.at<float>(k, 1) = (float)y * (float)imgSize.height / (N - 1);
301  k++;
302  }
303  }
304 
305  pts = pts.reshape(2);
306  cv::undistortPoints(pts,
307  pts,
308  cameraMatrix,
309  distCoeffs,
310  R,
311  newCameraMatrix);
312  pts = pts.reshape(1);
313 
314  float iX0 = -FLT_MAX, iX1 = FLT_MAX, iY0 = -FLT_MAX, iY1 = FLT_MAX;
315  float oX0 = FLT_MAX, oX1 = -FLT_MAX, oY0 = FLT_MAX, oY1 = -FLT_MAX;
316  // find the inscribed rectangle.
317  // the code will likely not work with extreme rotation matrices (R) (>45%)
318  for (int y = 0, k = 0; y < N; y++)
319  for (int x = 0; x < N; x++)
320  {
321  cv::Point2f p = {pts.at<float>(k, 0),
322  pts.at<float>(k, 1)};
323  oX0 = MIN(oX0, p.x);
324  oX1 = MAX(oX1, p.x);
325  oY0 = MIN(oY0, p.y);
326  oY1 = MAX(oY1, p.y);
327 
328  if (x == 0)
329  iX0 = MAX(iX0, p.x);
330  if (x == N - 1)
331  iX1 = MIN(iX1, p.x);
332  if (y == 0)
333  iY0 = MAX(iY0, p.y);
334  if (y == N - 1)
335  iY1 = MIN(iY1, p.y);
336  k++;
337  }
338  inner = cv::Rect_<float>(iX0, iY0, iX1 - iX0, iY1 - iY0);
339  outer = cv::Rect_<float>(oX0, oY0, oX1 - oX0, oY1 - oY0);
340 }
341 
342 //-----------------------------------------------------------------------------
343 //! Builds undistortion maps after calibration or loading
345 {
346  if (_cameraMatUndistorted.rows != 3 || _cameraMatUndistorted.cols != 3)
347  Utils::exitMsg("SLProject",
348  "CVCalibration::buildUndistortionMaps: No _cameraMatUndistorted available",
349  __LINE__,
350  __FILE__);
351 
352  // Create undistortion maps
353  _undistortMapX.release();
354  _undistortMapY.release();
355 
356  HighResTimer t;
357  cv::initUndistortRectifyMap(_cameraMat,
358  _distortion,
359  cv::Mat(), // Identity matrix R
361  _imageSize,
362  CV_16SC2, // before we had CV_32FC1 but in all tutorials they use CV_16SC2.. is there a reason?
365 #if _DEBUG
366  Utils::log("CVCalibration",
367  "initUndistortRectifyMap: %fms",
369 #endif
370  if (_undistortMapX.empty() || _undistortMapY.empty())
371  Utils::exitMsg("SLProject",
372  "CVCalibration::buildUndistortionMaps failed.",
373  __LINE__,
374  __FILE__);
375 }
376 //-----------------------------------------------------------------------------
377 //! Undistorts the inDistorted image into the outUndistorted
378 void CVCalibration::remap(CVMat& inDistorted,
379  CVMat& outUndistorted)
380 {
381  assert(!inDistorted.empty() &&
382  "Input image is empty!");
383 
384  assert(!_undistortMapX.empty() &&
385  !_undistortMapY.empty() &&
386  "Undistortion Maps are empty!");
387 
388  cv::remap(inDistorted,
389  outUndistorted,
392  cv::INTER_LINEAR);
393 }
394 //-----------------------------------------------------------------------------
395 //! Calculates camera intrinsics from a guessed FOV angle
396 /*! Most laptop-, webcam- or mobile camera have a horizontal view angle or
397 so called field of view (FOV) of around 65 degrees. From this parameter we
398 can calculate the most important intrinsic parameter the focal length. All
399 other parameters are set as if the lens would be perfect: No lens distortion
400 and the view axis goes through the center of the image.
401 If the focal length and sensor size is provided by the device we deduce the
402 the fovV from it.
403  @param imageWidthPX Height of image in pixels
404  @param imageHeightPX Width of image in pixels
405  @param fovH Average horizontal view angle in degrees
406 */
408  int imageHeightPX,
409  float fovH)
410 {
411  // if (fx == fy) and (cx == imgwidth * 0.5f) and (cy == imgheight * 0.5f)
412  float f = (0.5f * (float)imageWidthPX) / tanf(fovH * 0.5f * Utils::DEG2RAD);
413  float fovV = 2.0f * (float)atan2(0.5f * (float)imageHeightPX, f) * Utils::RAD2DEG;
414 
415  // Create standard camera matrix
416  // fx, fx, cx, cy are all in pixel values not mm
417  // We asume that we have an ideal image sensor with square pixels
418  // so that the focal length fx and fy are identical
419  // See the OpenCV documentation for more details:
420  // http://docs.opencv.org/3.1.0/dc/dbb/tutorial_py_calibration.html
421 
422  float cx = (float)imageWidthPX * 0.5f;
423  float cy = (float)imageHeightPX * 0.5f;
424  float fx = cx / tanf(fovH * 0.5f * Utils::DEG2RAD);
425  float fy = fx;
426 
427  _imageSize.width = imageWidthPX;
428  _imageSize.height = imageHeightPX;
429  _cameraMat = (cv::Mat_<double>(3, 3) << fx, 0, cx, 0, fy, cy, 0, 0, 1);
430  _distortion = (cv::Mat_<double>(5, 1) << 0, 0, 0, 0, 0); // No distortion
431  _cameraFovHDeg = fovH;
432  _cameraFovVDeg = fovV;
434  _state = CS_guessed;
435 }
436 //-----------------------------------------------------------------------------
437 //! Adapts an already calibrated camera to a new resolution (cropping and scaling)
438 void CVCalibration::adaptForNewResolution(const CVSize& newSize, bool calcUndistortionMaps)
439 {
440  if (_state == CS_uncalibrated)
441  return;
442 
443  // new center and focal length in pixels not mm
444  float fx, fy, cy, cx;
445 
446  // use original camera matrix for adaptions.
447  // Otherwise we get rounding errors after too many adaptions.
448  float fxOrig = (float)_cameraMatOrig.at<double>(0, 0);
449  float fyOrig = (float)_cameraMatOrig.at<double>(1, 1);
450  float cxOrig = (float)_cameraMatOrig.at<double>(0, 2);
451  float cyOrig = (float)_cameraMatOrig.at<double>(1, 2);
452 
453  if (((float)newSize.width / (float)newSize.height) >
454  ((float)_imageSizeOrig.width / (float)_imageSizeOrig.height))
455  {
456  float scaleFactor = (float)newSize.width / (float)_imageSizeOrig.width;
457 
458  fx = fxOrig * scaleFactor;
459  fy = fyOrig * scaleFactor;
460  float oldHeightScaled = (float)_imageSizeOrig.height * scaleFactor;
461  float heightDiff = (oldHeightScaled - (float)newSize.height) * 0.5f;
462 
463  cx = cxOrig * scaleFactor;
464  cy = cyOrig * scaleFactor - heightDiff;
465  }
466  else
467  {
468  float scaleFactor = (float)newSize.height / (float)_imageSizeOrig.height;
469  fx = fxOrig * scaleFactor;
470  fy = fyOrig * scaleFactor;
471  float oldWidthScaled = (float)_imageSizeOrig.width * scaleFactor;
472  float widthDiff = (oldWidthScaled - (float)newSize.width) * 0.5f;
473 
474  cx = cxOrig * scaleFactor - widthDiff;
475  cy = cyOrig * scaleFactor;
476  }
477 
478  // std::cout << "adaptForNewResolution: _cameraMat before: " << _cameraMat << std::endl;
479  _cameraMat = (cv::Mat_<double>(3, 3) << fx, 0, cx, 0, fy, cy, 0, 0, 1);
480  // std::cout << "adaptForNewResolution: _cameraMat after: " << _cameraMat << std::endl;
481  //_distortion remains unchanged
483 
484  // std::cout << "adaptForNewResolution: _imageSize before: " << _imageSize << std::endl;
485  _imageSize.width = newSize.width;
486  _imageSize.height = newSize.height;
487  // std::cout << "adaptForNewResolution: _imageSize after: " << _imageSize << std::endl;
488 
491  if (calcUndistortionMaps)
493 }
494 //-----------------------------------------------------------------------------
495 //! Calculate a camera matrix that we use for the scene graph and for the reprojection of the undistorted image
497 {
498  if (_cameraMat.rows != 3 || _cameraMat.cols != 3)
499  Utils::exitMsg("SLProject", "CVCalibration::calculateUndistortedCameraMat: No intrinsic parameter available", __LINE__, __FILE__);
500 
501  // An alpha of 0 leads to no black borders
502  // An alpha of 1 leads to black borders
503  // (with alpha equaly zero the augmentation fits best)
504  double alpha = 1.0;
505 
506  bool centerPrinciplePoint = true;
507  if (centerPrinciplePoint)
508  {
509  // Attention: the principle point has to be centered because for the projection matrix we assume that image plane is "symmetrically arranged wrt the focal plane"
510  //(see http://kgeorge.github.io/2014/03/08/calculating-opengl-perspective-matrix-from-opencv-intrinsic-matrix)
511  //_cameraMatUndistorted = cv::getOptimalNewCameraMatrix(_cameraMat, _distortion, _imageSize, alpha, _imageSize, nullptr, centerPrinciplePoint);
512  //! (The following is the algorithm from cv::getOptimalNewCameraMatrix and the code is here for understanding (it does the same))
513 
514  double cx0 = _cameraMat.at<double>(0, 2);
515  double cy0 = _cameraMat.at<double>(1, 2);
516  double cx = (_imageSize.width) * 0.5;
517  double cy = (_imageSize.height) * 0.5;
518 
519  cv::Rect_<float> inner, outer;
521  _distortion,
522  cv::Mat(),
523  _cameraMat,
524  _imageSize,
525  inner,
526  outer);
527 
528  double s0 = std::max(std::max(std::max((double)cx / (cx0 - inner.x),
529  (double)cy / (cy0 - inner.y)),
530  (double)cx / (inner.x + inner.width - cx0)),
531  (double)cy / (inner.y + inner.height - cy0));
532 
533  double s1 = std::min(std::min(std::min((double)cx / (cx0 - outer.x),
534  (double)cy / (cy0 - outer.y)),
535  (double)cx / (outer.x + outer.width - cx0)),
536  (double)cy / (outer.y + outer.height - cy0));
537 
538  double s = s0 * (1 - alpha) + s1 * alpha;
539 
541  _cameraMatUndistorted.at<double>(0, 0) *= s;
542  _cameraMatUndistorted.at<double>(1, 1) *= s;
543  _cameraMatUndistorted.at<double>(0, 2) = cx;
544  _cameraMatUndistorted.at<double>(1, 2) = cy;
545  }
546  else
547  {
548  _cameraMatUndistorted = cv::getOptimalNewCameraMatrix(_cameraMat,
549  _distortion,
550  _imageSize,
551  alpha,
552  _imageSize,
553  nullptr,
554  centerPrinciplePoint);
555  }
556 
557  // std::cout << "_cameraMatUndistorted: " << _cameraMatUndistorted << std::endl;
558  // std::cout << "_cameraMat: " << _cameraMat << std::endl;
559 }
560 //-----------------------------------------------------------------------------
561 //! Calculates the vertical field of view angle in degrees
563 {
564  if (_cameraMatUndistorted.rows != 3 || _cameraMatUndistorted.cols != 3)
565  Utils::exitMsg("SLProject", "CVCalibration::calcCameraFovFromSceneCameraMat: No _cameraMatUndistorted available", __LINE__, __FILE__);
566 
567  // calculate vertical field of view
568  float fx = (float)_cameraMatUndistorted.at<double>(0, 0);
569  float fy = (float)_cameraMatUndistorted.at<double>(1, 1);
570  float cx = (float)_cameraMatUndistorted.at<double>(0, 2);
571  float cy = (float)_cameraMatUndistorted.at<double>(1, 2);
572  _cameraFovHDeg = 2.0f * (float)atan2(cx, fx) * Utils::RAD2DEG;
573  _cameraFovVDeg = 2.0f * (float)atan2(cy, fy) * Utils::RAD2DEG;
574 }
575 //-----------------------------------------------------------------------------
void getInnerAndOuterRectangles(const cv::Mat &cameraMatrix, const cv::Mat &distCoeffs, const cv::Mat &R, const cv::Mat &newCameraMatrix, const cv::Size &imgSize, cv::Rect_< float > &inner, cv::Rect_< float > &outer)
get inscribed and circumscribed rectangle
@ CS_calibrated
The camera is calibrated.
Definition: CVCalibration.h:33
@ CS_uncalibrated
The camera is not calibrated (no calibration found)
Definition: CVCalibration.h:32
@ CS_guessed
The camera intrinsics where estimated from FOV.
Definition: CVCalibration.h:34
cv::Size CVSize
Definition: CVTypedefs.h:55
cv::Mat CVMat
Definition: CVTypedefs.h:38
CVCameraType
Definition: CVTypes.h:62
float _boardSquareMM
Size of chessboard square in mm.
float _cameraFovVDeg
Vertical field of view in degrees.
void calculateUndistortedCameraMat()
Calculate a camera matrix that we use for the scene graph and for the reprojection of the undistorted...
bool _isMirroredV
Flag if image must be vertically mirrored.
float fx() const
float _reprojectionError
Reprojection error after calibration.
CVMat _undistortMapX
Undistortion float map in x-direction.
static const int _CALIBFILEVERSION
Global const file format version.
void calcCameraFovFromUndistortedCameraMat()
Calculates the vertical field of view angle in degrees.
CVSize imageSize() const
CVCalibState _state
calibration state enumeration
void remap(CVMat &inDistorted, CVMat &outUndistorted)
Undistorts the inDistorted image into the outUndistorted.
CVMat _cameraMatUndistorted
Camera matrix that defines scene camera and may also be used for reprojection of undistorted image.
void createFromGuessedFOV(int imageWidthPX, int imageHeightPX, float fovH)
Calculates camera intrinsics from a guessed FOV angle.
float fy() const
CVMat _undistortMapY
Undistortion float map in y-direction.
CVSize _imageSize
Input image size in pixels (after cropping)
string _computerInfos
float cx() const
CVCalibration(CVCameraType camType, string computerInfos)
void adaptForNewResolution(const CVSize &newSize, bool calcUndistortionMaps)
Adapts an already calibrated camera to a new resolution (cropping and scaling)
CVMat _distortion
4x1 Matrix for intrinsic distortion
float _cameraFovHDeg
Horizontal field of view in degrees.
string _calibrationTime
Time stamp string of calibration.
float s1() const
bool load(const string &calibDir, const string &calibFileName, bool calcUndistortionMaps)
Loads the calibration information from the config file.
CVMat _cameraMat
3x3 Matrix for intrinsic camera matrix
int _camSizeIndex
The requested camera size index.
CVSize _imageSizeOrig
original image size (original from loading or calibration estimation)
float cy() const
string calibFileName() const
int _numCaptured
NO. of images captured.
bool _isMirroredH
Flag if image must be horizontally mirrored.
CVMat _cameraMatOrig
3x3 Matrix for intrinsic camera matrix (original from loading or calibration estimation)
bool save(const string &calibDir, const string &calibFileName)
Saves the camera calibration parameters to the config file.
CVSize _boardSize
NO. of inner chessboard corners.
void buildUndistortionMaps()
Builds undistortion maps after calibration or loading.
int _calibFlags
OpenCV calibration flags.
High Resolution Timer class using C++11.
Definition: HighResTimer.h:31
float elapsedTimeInMilliSec()
Definition: HighResTimer.h:38
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
string getDateTime2String()
Returns local time as string like "20190213-154611".
Definition: Utils.cpp:289
static const float DEG2RAD
Definition: Utils.h:239
string unifySlashes(const string &inputDir, bool withTrailingSlash)
Returns the inputDir string with unified forward slashes, e.g.: "dirA/dirB/".
Definition: Utils.cpp:368
string getFileNameWOExt(const string &pathFilename)
Returns the filename without extension.
Definition: Utils.cpp:616
void splitString(const string &s, char delimiter, vector< string > &splits)
Splits an input string at a delimiter character into a string vector.
Definition: Utils.cpp:152
void exitMsg(const char *tag, const char *msg, const int line, const char *file)
Terminates the application with a message. No leak checking.
Definition: Utils.cpp:1135
static const float RAD2DEG
Definition: Utils.h:238
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
Definition: Utils.cpp:1103