-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmainwindow.cpp
266 lines (233 loc) · 7.52 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "../include/LaneDetect.h"
#include "../include/SignDetect.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString title = QString::fromLocal8Bit("车道线识别和路牌识别");
setWindowTitle(title);
//初始化
videoPath = "";
isOpen = false;
isStart = false;
isPause = false;
isStop = false;
isLaneLine = true;
isSign = true;
gaussianBlurKernal = 1; //测试调节用,改变高斯模糊核
}
MainWindow::~MainWindow()
{
delete ui;
}
/**
* @brief MainWindow::MyRunner 检测控制函数
* @author HezeLao
* @date 2018-12-28 23:24
*/
int MainWindow::MyRunner(bool isSign){
isStart = true;
VideoCapture videoCapture(videoPath);
if(!videoCapture.isOpened()){
QMessageBox::critical(nullptr, "critical", QString::fromLocal8Bit("视频打开失败"), QMessageBox::Yes);
isStart = false;
isOpen = false;
return -1;
}
//获取帧数,不然会播放速度不对
Mat res;
bool haveSign;
int countShow=1;
while(true){
waitKey(33);
if(isPause) //暂停检测
continue;
videoCapture>>srcFrame;
if(srcFrame.empty() || isStop){
ui->label_video->clear(); //视频结束或按下结束按钮,清理播放窗口,退出
ui->label_sign_1->clear();
ui->label_sign_2->clear();
videoCapture.release();
break;
}
cv::resize(srcFrame, srcFrame, Size(576, 324), 0, 0, INTER_LINEAR);
if(isSign){
srcFrame = imgSignDetect(srcFrame, false);
qimg = QImage((const uchar*)(srcFrame.data),srcFrame.cols,srcFrame.rows, QImage::Format_RGB888); //简单地转换一下为Image对象,rgbSwapped是为了显示效果色彩好一些。
ui->label_video->setPixmap(QPixmap::fromImage(qimg));
ui->label_video->show();
}else{
srcFrame = imgLaneDetect(srcFrame, false);
qimg = QImage((const uchar*)(srcFrame.data),srcFrame.cols,srcFrame.rows, QImage::Format_RGB888); //简单地转换一下为Image对象,rgbSwapped是为了显示效果色彩好一些。
ui->label_video->setPixmap(QPixmap::fromImage(qimg));
ui->label_video->show();
}
}
videoCapture.release();
return 0;
}
/**
* @brief MainWindow::on_pushButton_open_clicked 点击选择文件
* @author HezeLao
* @date 2018-12-28 21:50
*/
void MainWindow::on_pushButton_open_clicked(){
cout << "debug:开始选择文件事件" << endl;
auto fileName = QFileDialog::getOpenFileName(nullptr, "Open Video!", QDir::currentPath(), "all files(*.*)");
if(fileName.isEmpty()){
cout << "debug:打开文件失败" << endl;
}
else{
videoPath = fileName.toStdString();
isOpen = true;
cout << "debug:打开文件成功" << endl;
cout << "debug:路径是:" << videoPath << endl;
}
cout << "debug:结束选择文件事件" << endl;
}
/**
* @brief MainWindow::on_pushButton_start_line_clicked 点击开始检测车道线
* @author HezeLao
* @date 2018-12-28 21:50
*/
void MainWindow::on_pushButton_start_line_clicked(){
//正在运行检测中
if(isStart && !isPause){
cout << "debug:正在检测中" << endl;
return;
}
//从暂停恢复检测
if(isPause){
isPause = false;
cout << "debug:从暂停恢复检测" << endl;
return;
}
//初次点击开始,检查是否选择目标视频
if(isOpen){
if(!MyRunner(false)){
//成功开始检测
cout << "debug:成功开始检测" << endl;
isOpen = false;
isStart = false;
isPause = false;
isStop = false;
}
else{
//检测失败
cout << "debug:检测失败" << endl;
}
}
else{
cout << "debug:未选择文件" << endl;
QMessageBox box(QMessageBox::Warning,"warning",QString::fromLocal8Bit("请先选择视频文件"));
box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
box.setButtonText (QMessageBox::Ok,QString::fromLocal8Bit("打开文件"));
box.setButtonText (QMessageBox::Cancel,QString::fromLocal8Bit("取消"));
auto select = box.exec ();
if(select == QMessageBox::Ok){
on_pushButton_open_clicked();
}
return;
}
cout << "debug:结束检测事件" << endl;
}
/**
* @brief MainWindow::on_pushButton_sign_clicked 点击开始检测
* @author HezeLao
* @date 2018-12-28 21:50
*/
void MainWindow::on_pushButton_start_sign_clicked(){
//正在运行检测中
if(isStart && !isPause){
cout << "debug:正在检测中" << endl;
return;
}
//从暂停恢复检测
if(isPause){
isPause = false;
cout << "debug:从暂停恢复检测" << endl;
return;
}
//初次点击开始,检查是否选择目标视频
if(isOpen){
if(!MyRunner(true)){
//成功开始检测
cout << "debug:成功开始检测" << endl;
isOpen = false;
isStart = false;
isPause = false;
isStop = false;
}
else{
//检测失败
cout << "debug:检测失败" << endl;
}
}
else{
cout << "debug:未选择文件" << endl;
QMessageBox box(QMessageBox::Warning,"warning",QString::fromLocal8Bit("请先选择视频文件"));
box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
box.setButtonText (QMessageBox::Ok,QString::fromLocal8Bit("打开文件"));
box.setButtonText (QMessageBox::Cancel,QString::fromLocal8Bit("取消"));
auto select = box.exec ();
if(select == QMessageBox::Ok){
on_pushButton_open_clicked();
}
return;
}
cout << "debug:结束检测事件" << endl;
}
/**
* @brief MainWindow::on_pushButton_pause_clicked 点击暂停
* @author HezeLao
* @date 2018-12-28 21:50
*/
void MainWindow::on_pushButton_pause_clicked(){
//在已经开始检测的条件下可以暂停
if(isStart){
isPause = true;
cout << "debug:已暂停" << endl;
return;
}
else{
//未在运行检测,无法暂停
QMessageBox::warning(nullptr, "warning", QString::fromLocal8Bit("未在运行检测"), QMessageBox::Yes);
cout << "debug:未在运行检测,无法暂停" << endl;
}
}
/**
* @brief MainWindow::on_pushButton_stop_clicked 点击结束
* @author HezeLao
* @date 2018-12-28 21:50
*/
void MainWindow::on_pushButton_stop_clicked(){
//未在运行检测,无法结束
if(!isStart){
QMessageBox::warning(nullptr, "warning", QString::fromLocal8Bit("未在运行检测"), QMessageBox::Yes);
cout << "debug:未在运行检测,无法结束" << endl;
}
else{
//执行结束事件
isOpen = false;
isStart = false;
isPause = false;
isStop = true;
cout << "debug:执行结束事件" << endl;
}
}
/**
* @brief MainWindow::closeEvent 关闭窗口事件
* @param event 事件
* @author HezeLao
* @date 2018-12-28 22:20
*/
void MainWindow::closeEvent(QCloseEvent *event){
auto isExit = QMessageBox::information(this, "Tips", QString::fromLocal8Bit("确认退出?"), QMessageBox::Yes | QMessageBox::No);
if(isExit == QMessageBox::Yes)
event->accept();
else
event->ignore();
}