calibCommon.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #ifndef CALIB_COMMON_HPP
  5. #define CALIB_COMMON_HPP
  6. #include <opencv2/core.hpp>
  7. #include <memory>
  8. #include <vector>
  9. #include <string>
  10. namespace calib
  11. {
  12. #define OVERLAY_DELAY 1000
  13. #define IMAGE_MAX_WIDTH 1280
  14. #define IMAGE_MAX_HEIGHT 960
  15. bool showOverlayMessage(const std::string& message);
  16. enum InputType { Video, Pictures };
  17. enum InputVideoSource { Camera, File };
  18. enum TemplateType { AcirclesGrid, Chessboard, ChArUco, DoubleAcirclesGrid, CirclesGrid };
  19. static const std::string mainWindowName = "Calibration";
  20. static const std::string gridWindowName = "Board locations";
  21. static const std::string consoleHelp = "Hot keys:\nesc - exit application\n"
  22. "s - save current data to .xml file\n"
  23. "r - delete last frame\n"
  24. "u - enable/disable applying undistortion\n"
  25. "d - delete all frames\n"
  26. "v - switch visualization";
  27. static const double sigmaMult = 1.96;
  28. struct calibrationData
  29. {
  30. cv::Mat cameraMatrix;
  31. cv::Mat distCoeffs;
  32. cv::Mat stdDeviations;
  33. cv::Mat perViewErrors;
  34. std::vector<cv::Mat> rvecs;
  35. std::vector<cv::Mat> tvecs;
  36. double totalAvgErr;
  37. cv::Size imageSize;
  38. std::vector<cv::Mat> allFrames;
  39. std::vector<std::vector<cv::Point2f> > imagePoints;
  40. std::vector< std::vector<cv::Point3f> > objectPoints;
  41. std::vector<cv::Mat> allCharucoCorners;
  42. std::vector<cv::Mat> allCharucoIds;
  43. cv::Mat undistMap1, undistMap2;
  44. calibrationData()
  45. {
  46. imageSize = cv::Size(IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT);
  47. }
  48. };
  49. struct cameraParameters
  50. {
  51. cv::Mat cameraMatrix;
  52. cv::Mat distCoeffs;
  53. cv::Mat stdDeviations;
  54. double avgError;
  55. cameraParameters(){}
  56. cameraParameters(cv::Mat& _cameraMatrix, cv::Mat& _distCoeffs, cv::Mat& _stdDeviations, double _avgError = 0) :
  57. cameraMatrix(_cameraMatrix), distCoeffs(_distCoeffs), stdDeviations(_stdDeviations), avgError(_avgError)
  58. {}
  59. };
  60. struct captureParameters
  61. {
  62. InputType captureMethod;
  63. InputVideoSource source;
  64. TemplateType board;
  65. cv::Size inputBoardSize;
  66. cv::Size boardSizeInnerCorners; // board size in inner corners for chessboard
  67. cv::Size boardSizeUnits; // board size in squares, circles, etc.
  68. int charucoDictName;
  69. std::string charucoDictFile;
  70. int calibrationStep;
  71. float charucoSquareLength, charucoMarkerSize;
  72. float captureDelay;
  73. float squareSize;
  74. float templDst;
  75. std::string videoFileName;
  76. bool flipVertical;
  77. int camID;
  78. int camBackend;
  79. int fps;
  80. cv::Size cameraResolution;
  81. int maxFramesNum;
  82. int minFramesNum;
  83. bool saveFrames;
  84. float zoom;
  85. bool forceReopen;
  86. captureParameters()
  87. {
  88. calibrationStep = 1;
  89. captureDelay = 500.f;
  90. maxFramesNum = 30;
  91. minFramesNum = 10;
  92. fps = 30;
  93. cameraResolution = cv::Size(IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT);
  94. saveFrames = false;
  95. }
  96. };
  97. struct internalParameters
  98. {
  99. double solverEps;
  100. int solverMaxIters;
  101. bool fastSolving;
  102. bool rationalModel;
  103. bool thinPrismModel;
  104. bool tiltedModel;
  105. double filterAlpha;
  106. internalParameters()
  107. {
  108. solverEps = 1e-7;
  109. solverMaxIters = 30;
  110. fastSolving = false;
  111. rationalModel = false;
  112. thinPrismModel = false;
  113. tiltedModel = false;
  114. filterAlpha = 0.1;
  115. }
  116. };
  117. }
  118. #endif