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