代码拉取完成,页面将自动刷新
/*********************************
* 主窗口
* @ray
* date:2019/9/24
* *******************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "liclabel.h"
#include<QBoxLayout>
#include <QMessageBox>
#include <QGridLayout>
#include <QFileDialog>
#include <opencv2/opencv.hpp>
#include <opencv2/video.hpp>
#include <QImage>
#include <qdebug.h>
#include <QTime>
#include "logprinttextbrowser.h"
#include "ipccamera.h"
#include <QSound>
using namespace cv;
bool process = false;
extern VideoLabel* videolabel;
extern LicLabel *stright_pic,*left_pic,*right_pic,*pressline_pic,*wrongroad_pic,*str_ob_rate,*ob_rate_class,*tot_num;//
extern LogPrintTextBrowser *logprinter;
extern Mat img;
extern VideoCapture capture;
extern int ROIindex;
extern bool key_to_detect ;
extern Mat str_license;
extern QSound beels;
void MainWindow::intUI()
{
setWindowTitle("路口交通违章AI监测器");
/***************各个控件的布局********************/
QWidget *cenWidget=new QWidget(this);
setCentralWidget(cenWidget);
QHBoxLayout *layout = new QHBoxLayout(cenWidget);
videolabel=new VideoLabel;
videolabel->setParent(this);
/***************定义网格布局并添加控件********************/
QGridLayout *pLayout = new QGridLayout();
//定义控件
logprinter=new LogPrintTextBrowser;
logprinter->setParent(this);
logprinter->moveCursor(QTextCursor::End);
stright_pic=new LicLabel;
stright_pic->setParent(this);
right_pic=new LicLabel;
right_pic->setParent(this);
left_pic=new LicLabel;
left_pic->setParent(this);
pressline_pic=new LicLabel;
pressline_pic->setParent(this);
wrongroad_pic=new LicLabel;
wrongroad_pic->setParent(this);
str_ob_rate=new LicLabel;
str_ob_rate->setParent(this);
ob_rate_class=new LicLabel;
ob_rate_class->setParent(this);
tot_num=new LicLabel;
tot_num->setParent(this);
//布局控件的位置
pLayout->addWidget(ui->ROIlabel,0,0);
pLayout->addWidget(ui->roiChoice,0,1);
pLayout->addWidget(ui->break_info_label,1,0);
pLayout->addWidget(logprinter,2,0,1,2);
pLayout->addWidget(ui->stright,3,0);
pLayout->addWidget(stright_pic,3,1,Qt::AlignCenter);
pLayout->addWidget(ui->left,4,0);
pLayout->addWidget(left_pic,4,1,Qt::AlignCenter);
pLayout->addWidget(ui->right,5,0);
pLayout->addWidget(right_pic,5,1,Qt::AlignCenter);
pLayout->addWidget(ui->pressline,6,0);
pLayout->addWidget(pressline_pic,6,1,Qt::AlignCenter);
pLayout->addWidget(ui->wrongroad,7,0);
pLayout->addWidget(wrongroad_pic,7,1,Qt::AlignCenter);
pLayout->addWidget(ui->str_ob_rate_lab,9,0);
pLayout->addWidget(str_ob_rate,9,1,Qt::AlignCenter);
pLayout->addWidget(ui->ob_rate_class_lab,10,0);
pLayout->addWidget(ob_rate_class,10,1,Qt::AlignCenter);
pLayout->addWidget(ui->tot_num_lab,8,0);
pLayout->addWidget(tot_num,8,1,Qt::AlignCenter);
//调整每行的比例
pLayout->setRowStretch(0,1);
pLayout->setRowStretch(1,1);
pLayout->setRowStretch(2,3);
pLayout->setRowStretch(3,1);
pLayout->setRowStretch(4,1);
pLayout->setRowStretch(5,1);
pLayout->setRowStretch(6,1);
pLayout->setRowStretch(7,1);
pLayout->setRowStretch(8,1);
pLayout->setRowStretch(9,1);
pLayout->setRowStretch(10,1);
pLayout->setRowStretch(11,2);
//调整布局之间的比例
layout->addWidget(videolabel);
layout->addLayout(pLayout);
layout->setStretchFactor(videolabel, 4);
layout->setStretchFactor(pLayout, 1);
/******************菜单设置****************************/
localfile = new QAction(this);
localfile->setText(QString::fromLocal8Bit("打开本地视频"));
netcam = new QAction(this);
netcam->setText(QString::fromLocal8Bit("打开网络摄像头"));
fileMenu=new QMenu(this);
fileMenu = menuBar()->addMenu(QString::fromLocal8Bit("文件"));
fileMenu->addAction(localfile);
fileMenu->addAction(netcam);
begineprocess=new QAction(this);
begineprocess->setText(QString::fromLocal8Bit("开始检测"));
stopprocess=new QAction(this);
stopprocess->setText(QString::fromLocal8Bit("停止检测"));
processMenu=new QMenu(this);
processMenu=menuBar()->addMenu(QString::fromLocal8Bit("处理"));
processMenu->addAction(begineprocess);
processMenu->addAction(stopprocess);
picprove=new QAction(this);
picprove->setText(QString::fromLocal8Bit("违章证据"));
carlisence=new QAction(this);
carlisence->setText(QString::fromLocal8Bit("违章车牌"));
illegalprove=new QMenu(this);
illegalprove=menuBar()->addMenu(QString::fromLocal8Bit("违章查询"));
illegalprove->addAction(picprove);
illegalprove->addAction(carlisence);
ui->menuBar->addAction(QString::fromLocal8Bit("使用帮助"), this, SLOT(userguideinfo()));
ui->menuBar->addAction(QString::fromLocal8Bit("关于"), this, SLOT(aboutinfo()));
//以下两个菜单项没用,但是删除了会异常
userguide=new QMenu(this);
userguide=menuBar()->addMenu(QString::fromLocal8Bit(""));
about=new QMenu(this);
about=menuBar()->addMenu(QString::fromLocal8Bit(""));
/***************初始化lable内容,为黑色背景********************/
videolabel->setAlignment(Qt::AlignCenter);
videolabel->setStyleSheet("background-color:black");
/***************三个进程********************/
rightpicthread=new RightPicThread(this);
leftpicthread=new LeftPicThread(this);
ipcamerathread=new IPCameraThread(this);
}
void MainWindow::iniSignalSlots()
{
/***************菜单选项的相关关联********************/
connect(localfile, SIGNAL(triggered()), this, SLOT(openlocalfile()));
connect(netcam, SIGNAL(triggered()), this, SLOT(opennetcam()));
connect(begineprocess, SIGNAL(triggered()), this, SLOT(begindetect()));
connect(stopprocess, SIGNAL(triggered()), this, SLOT(stopdetect()));
connect(picprove, SIGNAL(triggered()), this, SLOT(openpicprove()));
connect(carlisence, SIGNAL(triggered()), this, SLOT(openlicencepic()));
/***************roi下拉选择框的相关关联********************/
connect(ui->roiChoice,SIGNAL(currentIndexChanged(QString)),this,SLOT(changeROIchoice()));
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
intUI();
iniSignalSlots();
}
MainWindow::~MainWindow()
{
ipcamerathread->stop();
leftpicthread->stop();
rightpicthread->stop();
ipcamerathread->wait();
leftpicthread->wait();
rightpicthread->wait();
delete ui;
}
/******************下拉菜单选中*****************/
void MainWindow::changeROIchoice()
{
switch (ui->roiChoice->currentIndex())
{
case 1:
videolabel->allowDraw=true;
ROIindex=1;
break;
case 2:
videolabel->allowDraw=true;
ROIindex=2;
break;
case 3:
videolabel->allowDraw=true;
ROIindex=3;
break;
case 4:
videolabel->allowDraw=true;
ROIindex=4;
break;
case 5:
videolabel->allowDraw=true;
ROIindex=5;
break;
case 6:
videolabel->allowDraw=true;
ROIindex=6;
break;
case 7:
videolabel->allowDraw=true;
ROIindex=7;
break;
case 8:
videolabel->allowDraw=true;
ROIindex=8;
break;
case 9:
videolabel->allowDraw=true;
ROIindex=9;
break;
case 10:
videolabel->allowDraw=true;
ROIindex=10;
break;
case 11:
videolabel->allowDraw=true;
ROIindex=11;
break;
default:
videolabel->allowDraw=false;
}
/* if(videolabel->RoiRect)
{
delete videolabel->RoiRect;
videolabel->RoiRect=NULL;
}*/
}
/******************打开本地文件*****************/
void MainWindow::openlocalfile()
{
ipcamerathread->stop();
QString filename =QFileDialog::getOpenFileName(this,tr("Open Video File"),".",tr("Video Files(*.avi *.mp4 *.flv *.mkv)"));
if(filename.length()<=0)
return;
img = capture.open(filename.toLocal8Bit().data());
if(!capture.isOpened())
{
qDebug() << QString::fromLocal8Bit("视频未成功打开!");
return;
}
rightpicthread->begin();
leftpicthread->begin();
rightpicthread->start();
leftpicthread->start();
}
/******************打开摄像头*****************/
void MainWindow::opennetcam()
{
leftpicthread->stop();
rightpicthread->stop();
ipcamerathread->begin();
ipcamerathread->start();
}
/****************开始检测*******************/
void MainWindow::begindetect()
{
key_to_detect =true ;
}
/****************停止检测*******************/
void MainWindow::stopdetect()
{
key_to_detect =false;
}
/****************停止检测*******************/
void MainWindow::openpicprove()
{
QString provepicname =QFileDialog::getOpenFileName(this,tr("Open Saved Picture"),".",tr("Image Files(*.jpg)"));
if(provepicname.length()<=0)
return;
cv::Mat imag=cv::imread(provepicname.toLocal8Bit().data(),1);
cv::imshow("car_pic",imag);
}
/****************打开违章证据照片*******************/
void MainWindow::openlicencepic()
{
QString licpicname =QFileDialog::getOpenFileName(this,tr("Open Saved Picture"),".",tr("Image Files(*.jpg)"));
if(licpicname.length()<=0)
return;
cv::Mat imag=cv::imread(licpicname.toLocal8Bit().data(),1);
cv::imshow("lisence_pic",imag);
}
/****************用户使用手册*******************/
void MainWindow::userguideinfo()
{
QString dlgTitlle="使用指导";
QString strInfo="详见用户使用手册";
QMessageBox::about(this,dlgTitlle,strInfo);
}
/****************版权信息*******************/
void MainWindow::aboutinfo()
{
QString dlgTitlle="关于";
QString strInfo="版本:v2.0.0 \n版权 飞鸟队 保留所有权利";
QMessageBox::about(this,dlgTitlle,strInfo);
}
/*void MainWindow::DelayMS(unsigned int ms)
{
QTime Timer = QTime::currentTime().addMSecs(ms);
while( QTime::currentTime() < Timer )
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。