frameProcessor.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 FRAME_PROCESSOR_HPP
  5. #define FRAME_PROCESSOR_HPP
  6. #include <opencv2/core.hpp>
  7. #include <opencv2/calib3d.hpp>
  8. #ifdef HAVE_OPENCV_ARUCO
  9. #include <opencv2/aruco/charuco.hpp>
  10. #endif
  11. #include "calibCommon.hpp"
  12. #include "calibController.hpp"
  13. namespace calib
  14. {
  15. class FrameProcessor
  16. {
  17. protected:
  18. public:
  19. virtual ~FrameProcessor();
  20. virtual cv::Mat processFrame(const cv::Mat& frame) = 0;
  21. virtual bool isProcessed() const = 0;
  22. virtual void resetState() = 0;
  23. };
  24. class CalibProcessor : public FrameProcessor
  25. {
  26. protected:
  27. cv::Ptr<calibrationData> mCalibData;
  28. TemplateType mBoardType;
  29. cv::Size mBoardSize;
  30. std::vector<cv::Point2f> mTemplateLocations;
  31. std::vector<cv::Point2f> mCurrentImagePoints;
  32. cv::Mat mCurrentCharucoCorners;
  33. cv::Mat mCurrentCharucoIds;
  34. cv::Ptr<cv::SimpleBlobDetector> mBlobDetectorPtr;
  35. #ifdef HAVE_OPENCV_ARUCO
  36. cv::Ptr<cv::aruco::Dictionary> mArucoDictionary;
  37. cv::Ptr<cv::aruco::CharucoBoard> mCharucoBoard;
  38. #endif
  39. int mNeededFramesNum;
  40. unsigned mDelayBetweenCaptures;
  41. int mCapuredFrames;
  42. double mMaxTemplateOffset;
  43. float mSquareSize;
  44. float mTemplDist;
  45. bool detectAndParseChessboard(const cv::Mat& frame);
  46. bool detectAndParseChAruco(const cv::Mat& frame);
  47. bool detectAndParseACircles(const cv::Mat& frame);
  48. bool detectAndParseDualACircles(const cv::Mat& frame);
  49. void saveFrameData();
  50. void showCaptureMessage(const cv::Mat &frame, const std::string& message);
  51. bool checkLastFrame();
  52. public:
  53. CalibProcessor(cv::Ptr<calibrationData> data, captureParameters& capParams);
  54. virtual cv::Mat processFrame(const cv::Mat& frame) CV_OVERRIDE;
  55. virtual bool isProcessed() const CV_OVERRIDE;
  56. virtual void resetState() CV_OVERRIDE;
  57. ~CalibProcessor() CV_OVERRIDE;
  58. };
  59. enum visualisationMode {Grid, Window};
  60. class ShowProcessor : public FrameProcessor
  61. {
  62. protected:
  63. cv::Ptr<calibrationData> mCalibdata;
  64. cv::Ptr<calibController> mController;
  65. TemplateType mBoardType;
  66. visualisationMode mVisMode;
  67. bool mNeedUndistort;
  68. double mGridViewScale;
  69. double mTextSize;
  70. void drawBoard(cv::Mat& img, cv::InputArray points);
  71. void drawGridPoints(const cv::Mat& frame);
  72. public:
  73. ShowProcessor(cv::Ptr<calibrationData> data, cv::Ptr<calibController> controller, TemplateType board);
  74. virtual cv::Mat processFrame(const cv::Mat& frame) CV_OVERRIDE;
  75. virtual bool isProcessed() const CV_OVERRIDE;
  76. virtual void resetState() CV_OVERRIDE;
  77. void setVisualizationMode(visualisationMode mode);
  78. void switchVisualizationMode();
  79. void clearBoardsView();
  80. void updateBoardsView();
  81. void switchUndistort();
  82. void setUndistort(bool isEnabled);
  83. ~ShowProcessor() CV_OVERRIDE;
  84. };
  85. }
  86. #endif