| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #pragma execution_character_set("utf-8")
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "grabframethread.h"
- #include <QCameraInfo>
- #include <QThread>
- #include <QTimer>
- #include <QCursor>
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- ui->label_ShowImage->setBackgroundRole(QPalette::Dark);
- on_action_FindCamera_triggered();
- initParm();
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::closeEvent(QCloseEvent *event)
- {
- if(m_thread->isRunning()){
- m_grabFrameThread->closeCamera();
- m_thread->quit();
- m_thread->wait();
- }
- }
- void MainWindow::on_action_FindCamera_triggered()
- {
- ui->comboBox_CameraList->clear();
- m_cameraList.clear();
- m_cameraList = QCameraInfo::availableCameras();
- for(int i=0;i<m_cameraList.size();++i){
- ui->comboBox_CameraList->addItem(m_cameraList.at(i).description());
- }
- }
- void MainWindow::on_action_OpenCamera_triggered()
- {
- if(ui->action_OpenCamera->text() == tr("打开摄像头")){
- if(ui->comboBox_CameraList->count() > 0){
- if(!m_timerShowFrame->isActive())
- m_timerShowFrame->start();
- ui->action_OpenCamera->setText(tr("关闭摄像头"));
- // 打开相机
- m_grabFrameThread->openCamera(ui->comboBox_CameraList->currentIndex());
- // 设置分辨率
- on_pushButton_SetResolution_clicked();
- //设置检测参数
- on_pushButton_SetParam_clicked();
- //设置计算精度
- on_checkBox_fp16_clicked();
- on_checkBox_int8_clicked();
- QApplication::setOverrideCursor(Qt::WaitCursor);
- } else {
- qDebug() << tr("当前设备没有摄像头");
- }
- } else {
- ui->action_OpenCamera->setText(tr("打开摄像头"));
- m_grabFrameThread->closeCamera();
- m_timerShowFrame->stop();
- ui->label_ShowImage->clear();
- // Destroy the engine
- m_grabFrameThread->destroyEngine();
- }
- }
- void MainWindow::refreshFrame(const QImage &image)
- {
- if(Qt::ArrowCursor != QApplication::overrideCursor()->shape())
- QApplication::setOverrideCursor(Qt::ArrowCursor);
- ui->label_ShowImage->setPixmap(QPixmap::fromImage(image));
- // ui->label_ShowImage->adjustSize();
- }
- void MainWindow::initParm()
- {
- m_thread = new QThread;
- m_grabFrameThread = new GrabFrameThread;
- m_timerShowFrame = new QTimer(this);
- m_grabFrameThread->moveToThread(m_thread);
- connect(m_thread,&QThread::finished,m_thread,&QThread::deleteLater);
- connect(m_thread,&QThread::finished,m_grabFrameThread,&GrabFrameThread::deleteLater);
- connect(m_thread,&QThread::finished,m_grabFrameThread,&GrabFrameThread::init);
- connect(m_timerShowFrame,&QTimer::timeout,m_grabFrameThread,&GrabFrameThread::refreshFrame);
- connect(m_grabFrameThread,&GrabFrameThread::signal_refreshFrame,this,&MainWindow::refreshFrame);
- m_timerShowFrame->setInterval(33);
- m_thread->start();
- }
- void MainWindow::on_pushButton_SetResolution_clicked()
- {
- ui->spinBox_FrameWidth->interpretText();
- ui->spinBox_FrameHeight->interpretText();
- const int frameWidth = ui->spinBox_FrameWidth->value();
- const int frameHeight = ui->spinBox_FrameHeight->value();
- m_grabFrameThread->setFrameResolution(frameWidth,frameHeight);
- }
- void MainWindow::on_pushButton_SetParam_clicked()
- {
- ui->doubleSpinBox_conf->interpretText();
- ui->doubleSpinBox_nms->interpretText();
- const float conf_threshold = ui->doubleSpinBox_conf->value();
- const float nms_threshold = ui->doubleSpinBox_nms->value();
- m_grabFrameThread->setParameter(conf_threshold,nms_threshold);
- }
- void MainWindow::on_pushButton_StartDetec_clicked()
- {
- m_grabFrameThread->startDetect();
- }
- void MainWindow::on_pushButton_EndDetec_clicked()
- {
- m_grabFrameThread->closeDetect();
- }
- void MainWindow::on_checkBox_fp16_clicked()
- {
- m_grabFrameThread->setfp16(ui->checkBox_fp16->isChecked());
- }
- void MainWindow::on_checkBox_int8_clicked()
- {
- m_grabFrameThread->setint8(ui->checkBox_int8->isChecked());
- }
|