5
5
6
6
using namespace cv ;
7
7
8
- int Application::parseArguments (int argc, const char **argv, Application::Parameters ¶ms)
8
+ int Application::parseArguments (int argc, const char **argv,
9
+ Application::Parameters ¶ms)
9
10
{
10
11
if (argc < 2 )
11
12
{
@@ -37,9 +38,39 @@ int Application::processFrame(const Mat& src, Mat& dst)
37
38
return 0 ;
38
39
}
39
40
40
- int Application::showFrame ( const std::string &caption, const Mat& src, const Mat& dst )
41
+ int Application::drawButtons ( Mat &display )
41
42
{
42
- if (src.rows != dst.rows || src.cols != dst.cols )
43
+ guiState.onButtonPlace = Rect (20 , display.rows - 60 , 120 , 40 );
44
+ guiState.offButtonPlace = Rect (160 , display.rows - 60 , 120 , 40 );
45
+ rectangle (display, guiState.onButtonPlace ,
46
+ Scalar (128 , 128 , 128 ), CV_FILLED);
47
+ rectangle (display, guiState.offButtonPlace ,
48
+ Scalar (128 , 128 , 128 ), CV_FILLED);
49
+
50
+ putText (display, " on" ,
51
+ Point (guiState.onButtonPlace .x + guiState.onButtonPlace .width / 2 - 15 ,
52
+ guiState.onButtonPlace .y + guiState.onButtonPlace .height / 2 + 10 ),
53
+ FONT_HERSHEY_SIMPLEX, 1.0 , Scalar (0 , 0 , 0 ), 2 );
54
+ putText (display, " off" ,
55
+ Point (guiState.offButtonPlace .x + guiState.offButtonPlace .width / 2 - 20 ,
56
+ guiState.offButtonPlace .y + guiState.offButtonPlace .height / 2 + 10 ),
57
+ FONT_HERSHEY_SIMPLEX, 1.0 , Scalar (0 , 0 , 0 ), 2 );
58
+
59
+ return 0 ;
60
+ }
61
+
62
+ int Application::showFrame (const std::string &caption,
63
+ const Mat& src, Mat& dst)
64
+ {
65
+ if (guiState.state == OffFilter)
66
+ {
67
+ src.copyTo (dst);
68
+ }
69
+ else if (guiState.state == OnFilter)
70
+ {
71
+ processFrame (src, dst);
72
+ }
73
+ else
43
74
{
44
75
return 1 ;
45
76
}
@@ -48,11 +79,54 @@ int Application::showFrame(const std::string &caption, const Mat& src, const Mat
48
79
Mat srcRoi = display (Rect (0 , 0 , src.cols , src.rows ));
49
80
src.copyTo (srcRoi);
50
81
Mat dstRoi = display (Rect (src.cols , 0 , dst.cols , dst.rows ));
51
- dst.copyTo (dstRoi);
52
-
53
- namedWindow (caption);
82
+ dst.copyTo (dstRoi);
83
+
84
+ drawButtons (display);
85
+
86
+ namedWindow (caption);
54
87
imshow (caption, display);
88
+ setMouseCallback (caption, onButtonsOnOffClick, &guiState);
55
89
char key = waitKey (1 );
56
90
57
91
return key;
58
92
}
93
+
94
+ void onButtonsOnOffClick (int eventId, int x, int y, int flags, void *userData)
95
+ {
96
+ if (eventId != EVENT_LBUTTONDOWN)
97
+ {
98
+ return ;
99
+ }
100
+ Application::GUIElementsState *elems =
101
+ (Application::GUIElementsState *)userData;
102
+ if (onButtonClicked (elems->onButtonPlace , x, y))
103
+ {
104
+ elems->state = Application::WindowState::OnFilter;
105
+ return ;
106
+ }
107
+ if (offButtonClicked (elems->offButtonPlace , x, y))
108
+ {
109
+ elems->state = Application::WindowState::OffFilter;
110
+ return ;
111
+ }
112
+ }
113
+
114
+ bool onButtonClicked (cv::Rect onButtonPlace, int x, int y)
115
+ {
116
+ if (x < onButtonPlace.x || x > onButtonPlace.x + onButtonPlace.width ||
117
+ y < onButtonPlace.y || y > onButtonPlace.y + onButtonPlace.height )
118
+ {
119
+ return false ;
120
+ }
121
+ return true ;
122
+ }
123
+
124
+ bool offButtonClicked (cv::Rect offButtonPlace, int x, int y)
125
+ {
126
+ if (x < offButtonPlace.x || x > offButtonPlace.x + offButtonPlace.width ||
127
+ y < offButtonPlace.y || y > offButtonPlace.y + offButtonPlace.height )
128
+ {
129
+ return false ;
130
+ }
131
+ return true ;
132
+ }
0 commit comments