calibCommon.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 };
  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<std::vector<cv::Point2f> > imagePoints;
  39. std::vector< std::vector<cv::Point3f> > objectPoints;
  40. std::vector<cv::Mat> allCharucoCorners;
  41. std::vector<cv::Mat> allCharucoIds;
  42. cv::Mat undistMap1, undistMap2;
  43. calibrationData()
  44. {
  45. imageSize = cv::Size(IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT);
  46. }
  47. };
  48. struct cameraParameters
  49. {
  50. cv::Mat cameraMatrix;
  51. cv::Mat distCoeffs;
  52. cv::Mat stdDeviations;
  53. double avgError;
  54. cameraParameters(){}
  55. cameraParameters(cv::Mat& _cameraMatrix, cv::Mat& _distCoeffs, cv::Mat& _stdDeviations, double _avgError = 0) :
  56. cameraMatrix(_cameraMatrix), distCoeffs(_distCoeffs), stdDeviations(_stdDeviations), avgError(_avgError)
  57. {}
  58. };
  59. struct captureParameters
  60. {
  61. InputType captureMethod;
  62. InputVideoSource source;
  63. TemplateType board;
  64. cv::Size boardSize;
  65. int charucoDictName;
  66. int calibrationStep;
  67. float charucoSquareLength, charucoMarkerSize;
  68. float captureDelay;
  69. float squareSize;
  70. float templDst;
  71. std::string videoFileName;
  72. bool flipVertical;
  73. int camID;
  74. int fps;
  75. cv::Size cameraResolution;
  76. int maxFramesNum;
  77. int minFramesNum;
  78. captureParameters()
  79. {
  80. calibrationStep = 1;
  81. captureDelay = 500.f;
  82. maxFramesNum = 30;
  83. minFramesNum = 10;
  84. fps = 30;
  85. cameraResolution = cv::Size(IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT);
  86. }
  87. };
  88. struct internalParameters
  89. {
  90. double solverEps;
  91. int solverMaxIters;
  92. bool fastSolving;
  93. double filterAlpha;
  94. internalParameters()
  95. {
  96. solverEps = 1e-7;
  97. solverMaxIters = 30;
  98. fastSolving = false;
  99. filterAlpha = 0.1;
  100. }
  101. };
  102. }
  103. #endif