1
1
#include " application.hpp"
2
2
#include " processing.hpp"
3
+ #include " time.h"
3
4
4
5
#include < opencv2/highgui/highgui.hpp>
5
6
@@ -44,10 +45,13 @@ int Application::drawButtons(Mat &display)
44
45
{
45
46
guiState.onButtonPlace = Rect (20 , display.rows - 60 , 120 , 40 );
46
47
guiState.offButtonPlace = Rect (160 , display.rows - 60 , 120 , 40 );
48
+ guiState.saveButtonPlace = Rect (300 , display.rows - 60 , 120 , 40 );
47
49
rectangle (display, guiState.onButtonPlace ,
48
50
Scalar (128 , 128 , 128 ), CV_FILLED);
49
51
rectangle (display, guiState.offButtonPlace ,
50
52
Scalar (128 , 128 , 128 ), CV_FILLED);
53
+ rectangle (display, guiState.saveButtonPlace ,
54
+ Scalar (128 , 128 , 128 ), CV_FILLED);
51
55
52
56
putText (display, " on" ,
53
57
Point (guiState.onButtonPlace .x + guiState.onButtonPlace .width / 2 - 15 ,
@@ -57,6 +61,10 @@ int Application::drawButtons(Mat &display)
57
61
Point (guiState.offButtonPlace .x + guiState.offButtonPlace .width / 2 - 20 ,
58
62
guiState.offButtonPlace .y + guiState.offButtonPlace .height / 2 + 10 ),
59
63
FONT_HERSHEY_SIMPLEX, 1.0 , Scalar (0 , 0 , 0 ), 2 );
64
+ putText (display, " save" ,
65
+ Point (guiState.saveButtonPlace .x + guiState.saveButtonPlace .width / 2 - 30 ,
66
+ guiState.saveButtonPlace .y + guiState.saveButtonPlace .height / 2 + 10 ),
67
+ FONT_HERSHEY_SIMPLEX, 1.0 , Scalar (0 , 0 , 0 ), 2 );
60
68
61
69
return 0 ;
62
70
}
@@ -77,12 +85,28 @@ int Application::showFrame(const std::string &caption,
77
85
return 1 ;
78
86
}
79
87
88
+
80
89
Mat display (src.rows , src.cols + dst.cols , src.type ());
81
90
Mat srcRoi = display (Rect (0 , 0 , src.cols , src.rows ));
82
91
src.copyTo (srcRoi);
83
92
Mat dstRoi = display (Rect (src.cols , 0 , dst.cols , dst.rows ));
84
93
dst.copyTo (dstRoi);
85
94
95
+
96
+ if (guiState.saveState )
97
+ {
98
+ // ïîëó÷èòü òåêóùåå âðåìÿ
99
+ // ñãåíåðèðîâàòü íàçâàíèå èçîáðàæåíèÿ
100
+ // <image_name> - ñãåíåðèðîâàííîå íàçâàíèå èçîáðàæåíèÿ
101
+ // ñ ìåòêîé òåêóùåãî âðåìåíè
102
+ // âûçâàòü ôóíêöèþ ñîõðàíåíèÿ imwrite(<image_name>, display)
103
+ // ñáðîñèòü çíà÷åíèå guiState.saveState â false
104
+ String imgString = " image" + std::to_string (time (0 ));
105
+ imwrite (imgString+" .jpg" ,display);
106
+ guiState.saveState = false ;
107
+ }
108
+
109
+
86
110
drawButtons (display);
87
111
88
112
namedWindow (caption);
@@ -111,6 +135,11 @@ void onButtonsOnOffClick(int eventId, int x, int y, int flags, void *userData)
111
135
elems->state = Application::OffFilter;
112
136
return ;
113
137
}
138
+ if (onButtonClicked (elems->saveButtonPlace , x, y))
139
+ {
140
+ elems->saveState = true ;
141
+ return ;
142
+ }
114
143
}
115
144
116
145
bool onButtonClicked (cv::Rect buttonPlace, int x, int y)
0 commit comments