From f89d926fca90f925017a1f03612d890368fc743c Mon Sep 17 00:00:00 2001 From: zara Date: Thu, 10 Oct 2024 10:40:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=9B=9D=E5=85=89,=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=9B=B2=E5=85=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 5 +- CMakeLists.txt.user | 2 +- autoflash.cpp | 59 +++++++++++++++ autoflash.h | 34 +++++++++ mainwindow.cpp | 49 +++++++++++- mainwindow.h | 12 +++ mainwindow.ui | 178 +++++++++++++++++++++++++------------------- menu5.cpp | 20 +++++ menu5.h | 8 ++ menu5.ui | 63 ++++++++++------ multipoint.cpp | 81 +++++++++++++++++++- multipoint.h | 8 ++ 12 files changed, 414 insertions(+), 105 deletions(-) create mode 100644 autoflash.cpp create mode 100644 autoflash.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 454f076..a36e1c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -set(PROJECT_VERSION 1.4.2.14) +set(PROJECT_VERSION 1.4.2.17) add_definitions(-DProjectVersion=\"${PROJECT_VERSION}\") project(zxrcClient VERSION ${PROJECT_VERSION} LANGUAGES CXX) @@ -108,6 +108,9 @@ set(PROJECT_SOURCES menu6.cpp menu6.h menu6.ui passwd.cpp passwd.h passwd.ui devicelist.cpp devicelist.h devicelist.ui + + autoflash.cpp + autoflash.h ) ### diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 16a156d..a0aed12 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/autoflash.cpp b/autoflash.cpp new file mode 100644 index 0000000..946d7b5 --- /dev/null +++ b/autoflash.cpp @@ -0,0 +1,59 @@ +#include "autoflash.h" + + + + +autoFlash::autoFlash(QObject *parent) + : QObject{parent} +{ + thread = new QThread(); + thread->start(); + this->moveToThread(thread); + + b_sv = false; // + // lastlight; + count = 0; + + // double threshold; + + threshold = 6000; +} + +void autoFlash::slotprocimg(cv::Mat img) +{ + if(count>0){ + b_sv = false; + count -=1; + return; + } + + double avg = 0; + for(int i = 0;i(i,j); + } + } + avg = avg/int(img.rows/10)/int(img.cols/10)/4; + if(b_sv){ + lastlight = lastlight/20*19 +avg/20; + } + else{ + lastlight = avg; + b_sv = true; + } + if(lastlight-threshold<-1000){ + emit signalSetIT(-1); + count = 5; + } + if(lastlight-threshold>1000){ + emit signalSetIT(1); + count = 5; + } + + +} + +void autoFlash::slotsetshre(double thre) +{ + this->threshold = thre; +} diff --git a/autoflash.h b/autoflash.h new file mode 100644 index 0000000..a76c14a --- /dev/null +++ b/autoflash.h @@ -0,0 +1,34 @@ +#ifndef AUTOFLASH_H +#define AUTOFLASH_H + +#include +#include +#include + + + + +class autoFlash : public QObject +{ + Q_OBJECT +public: + explicit autoFlash(QObject *parent = nullptr); + + +public slots: + void slotprocimg(cv::Mat); + void slotsetshre(double); +signals: + void signalSetIT(double); + +private: + QThread* thread; + bool b_sv; // + double lastlight; + int count; + + double threshold; + +}; + +#endif // AUTOFLASH_H diff --git a/mainwindow.cpp b/mainwindow.cpp index cb2a096..8533731 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -37,6 +37,7 @@ MainWindow::~MainWindow() void MainWindow::initUI() { + b_af = false; b_stat = true; ui->pushButton_3->setChecked(true); imageX = -10; @@ -212,7 +213,19 @@ void MainWindow::initConnect() } }); - + connect(usb,SIGNAL(signalGetImage(cv::Mat)),m_af,SLOT(slotprocimg(cv::Mat))); + connect(m_af,&autoFlash::signalSetIT,[=](double it){ + if(b_af) + if(d_it -it >0 && d_it-it<=10){ + ucontrol->setIT(d_it-it); + d_it -=it; + if(m_mp!=nullptr){ +// ddd<deviceid<loaddata(this->deviceid,it); + m_mp->setit(d_it); + } + } + }); #if CLIENT == 0 || CLIENT==1 connect(usb,SIGNAL(signalGetImage(cv::Mat)),this,SLOT(slotShowImage(cv::Mat))); @@ -315,13 +328,18 @@ void MainWindow::initConnect() m_mp->savedata(path,d_it ); }); + connect(m5,SIGNAL(signalrmbld(bool)),m_mp,SLOT(setrmblk(bool))); + connect(m5,SIGNAL(signalthre(double)),m_mp,SLOT(slotSetThre(double))); + + connect(m_mp,SIGNAL(signalNewFrame(double)),m5,SLOT(slotRefresh(double))); // connect(m5,SIGNAL(signalloaddata(QString)),m_mp,SLOT(loaddata(QString))); connect(m5,&menu5::signalloaddata,[this](QString path){ // m_mp->loaddata(path,this->d_it); this->deviceid = path; - m_mp->setdevice(path); m_mp->enable = true; + m_mp->setdevice(path); + // m_mp->loaddata(); }); connect(m5,SIGNAL(signaloff()),m_mp,SLOT(off())); @@ -968,6 +986,7 @@ void MainWindow::initIns() usb = new usbthread(); ucontrol = new usbcontrol(); + m_af = new autoFlash(); QTimer* t = new QTimer(this); connect(t,&QTimer::timeout,[=](){ @@ -1100,7 +1119,7 @@ void MainWindow::on_pushButton_9_clicked() void MainWindow::on_pushButton_10_clicked() { QTimer *t = new QTimer(); - t->start(200); + t->start(90); connect(t,&QTimer::timeout,[=](){ double it = QRandomGenerator64::global()->generateDouble()*9+1; ucontrol->setIT(it); @@ -1147,3 +1166,27 @@ void MainWindow::on_comboBox_currentIndexChanged(int index) } } + +void MainWindow::on_spinBox_3_valueChanged(int arg1) +{ +} + + +void MainWindow::on_pushButton_11_clicked() +{ + m_af->slotsetshre(ui->spinBox_3->value()); + +} + + +void MainWindow::on_pushButton_12_clicked() +{ + b_af =!b_af; + if(b_af){ + slotlogtext(u8"开始自动曝光"); + } + else{ + slotlogtext(u8"关闭自动曝光"); + } +} + diff --git a/mainwindow.h b/mainwindow.h index e8fa3be..92b8748 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -26,6 +26,8 @@ #include "twopoint.h" #include "clhe.h" #include "multipoint.h" +#include "autoflash.h" + #include "qfluentwidgets" #include @@ -90,6 +92,12 @@ private slots: void on_comboBox_currentIndexChanged(int index); + void on_spinBox_3_valueChanged(int arg1); + + void on_pushButton_11_clicked(); + + void on_pushButton_12_clicked(); + private: void initIns(); void initUI(); @@ -120,6 +128,8 @@ private: usbcontrol* ucontrol; usbthread* usb; + autoFlash* m_af; + int type; int rows; int cols; @@ -183,5 +193,7 @@ private: cv::Mat bpimg;//盲元点 bool b_bp;//盲元替换 + bool b_af; + }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 915c51b..586c699 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 1388 - 648 + 685 @@ -71,7 +71,7 @@ 0 0 658 - 555 + 592 @@ -103,17 +103,20 @@ - - + + - 全局均方差 + 溢出点数 - - + + + + + - 截止点数 + 输出盲元图 @@ -124,53 +127,41 @@ - - - - - 400 - 16777215 - + + + + 区域平均值 - - - - Qt::Horizontal + + + + 设置目标灰度 - - + + + + + - 输出盲元图 + 区域均方差 - - - - - - - - - - - - - - + + - 标记为盲元 + 加载盲元图 - - + + - 中心点纵坐标 + 取消标记 @@ -181,81 +172,114 @@ - - + + + + + - 区域均方差 + test - - - - - - - - - - 溢出点数 + + + + + 400 + 16777215 + + + + + + + - - - - - + + - 中心点横坐标 + 暂停统计 - - + + + + 16384 + + + 6000 + + - - + + - 取消标记 + 全局均方差 - - + + - 暂停统计 + 中心点纵坐标 - - + + + + + - 加载盲元图 + 标记为盲元 - - + + + + + - 区域平均值 + 截止点数 - + 全局平均值 - - + + + + Qt::Horizontal + + + + + + + + - test + 中心点横坐标 + + + + + + + 开关自动曝光 diff --git a/menu5.cpp b/menu5.cpp index 9b4982b..abd9bb9 100644 --- a/menu5.cpp +++ b/menu5.cpp @@ -25,6 +25,7 @@ menu5::menu5(QWidget *parent) : } }); hideui(); + b_rmbld = false; } menu5::~menu5() @@ -39,6 +40,7 @@ void menu5::hideui() ui->pushButton_3->hide(); ui->tableWidget->hide(); ui->pushButton_6->hide(); + ui->doubleSpinBox->hide(); } void menu5::showui() @@ -48,6 +50,7 @@ void menu5::showui() ui->pushButton_3->show(); ui->tableWidget->show(); ui->pushButton_6->show(); + ui->doubleSpinBox->show(); } void menu5::slotRefresh(double gray) @@ -143,3 +146,20 @@ void menu5::on_pushButton_6_clicked() } } + +void menu5::on_pushButton_7_clicked() +{ + b_rmbld = !b_rmbld; + emit signalrmbld(b_rmbld); + if(b_rmbld) + ui->pushButton_7->setText(u8"关闭自动去盲元"); + else + ui->pushButton_7->setText(u8"开启自动去盲元"); +} + + +void menu5::on_doubleSpinBox_valueChanged(double arg1) +{ + emit signalthre(arg1); +} + diff --git a/menu5.h b/menu5.h index a4e1be9..aa043d3 100644 --- a/menu5.h +++ b/menu5.h @@ -33,15 +33,23 @@ private slots: void on_pushButton_6_clicked(); + void on_pushButton_7_clicked(); + + void on_doubleSpinBox_valueChanged(double arg1); + signals: void signalsave(); void signalcalc(QVector ); void signalsavedata(QString); void signalloaddata(QString); void signaloff(); + void signalrmbld(bool); + void signalthre(double); private: Ui::menu5 *ui; QVector grays; + + bool b_rmbld; }; #endif // MENU5_H diff --git a/menu5.ui b/menu5.ui index 6b90aab..e7d9531 100644 --- a/menu5.ui +++ b/menu5.ui @@ -14,31 +14,24 @@ Form - - - - 关闭校正 - - - - - + + - 存32帧亮度 + 保存数据 - - + + - 加载数据 + 开始计算 - - + + - 开始计算 + 清空列表 @@ -62,17 +55,38 @@ - - + + - 保存数据 + 关闭校正 - - + + - 清空列表 + 加载数据 + + + + + + + 自动去盲元 + + + + + + + 存32帧亮度 + + + + + + + 4.000000000000000 @@ -84,6 +98,11 @@ QTableWidget
qfluentwidgets
+ + DoubleSpinBox + QDoubleSpinBox +
qfluentwidgets
+
diff --git a/multipoint.cpp b/multipoint.cpp index 2e33533..77368ba 100644 --- a/multipoint.cpp +++ b/multipoint.cpp @@ -16,6 +16,8 @@ MultiPoint::MultiPoint(QObject *parent) stagecount =0; ittime = 5; enable = false; + b_rmbld = false; + b_thre = 4; } void MultiPoint::saveData(cv::Mat img) @@ -38,6 +40,16 @@ void MultiPoint::calcData(QVector vct) if(stagecount<2) return; +// cv::Mat mask(rows,cols,CV_8UC1); +// for(int i = 0;i(i,j) == 1){ + int n = 8- (msk.at(i+1,j)+ + msk.at(i-1,j)+ + msk.at(i+1,j-1)+ + msk.at(i-1,j-1)+ + msk.at(i+1,j+1)+ + msk.at(i-1,j+1)+ + msk.at(i,j+1)+ + msk.at(i,j-1)); + int sum = (1-msk.at(i+1,j))*dst.at(i+1,j)+ + (1-msk.at(i-1,j))*dst.at(i-1,j)+ + (1-msk.at(i+1,j+1))*dst.at(i+1,j+1)+ + (1-msk.at(i-1,j+1))*dst.at(i-1,j+1)+ + (1-msk.at(i+1,j-1))*dst.at(i+1,j-1)+ + (1-msk.at(i-1,j-1))*dst.at(i-1,j-1)+ + (1-msk.at(i,j+1))*dst.at(i,j+1)+ + (1-msk.at(i,j-1))*dst.at(i,j-1); + if(n>0) + dst.at(i,j) = sum/n; + else dst.at(i,j) = 0; + } + } + } + } emit signalsendimg(dst); } else{ @@ -196,7 +236,7 @@ void MultiPoint::savedata(QString path, double ittime) { QDir d; d.mkdir("datas/"+path); - + deviceid = path; QFile afs("datas/"+path+"/"+QString::number(ittime,'f',2)+".tgz"); afs.open(QIODevice::ReadWrite); @@ -239,6 +279,16 @@ void MultiPoint::loaddata() memcpy(kstages,data.data()+sizeof(double)*rows*cols*(stagecount+1),sizeof(double)*rows*cols*(stagecount+1)); memcpy(bstages,data.data()+2*sizeof(double)*rows*cols*(stagecount+1),sizeof(double)*(stagecount+1)); + msk = cv::Mat(rows,cols,CV_8UC1); + for(int i = 0;i(i,j) = 0; + for(int k = 0;kb_thre ) + msk.at(i,j) = 1; + } + } + } // qDebug()<<"stagecount"<(i,j) = 0; + for(int k = 0;kb_thre ) + msk.at(i,j) = 1; + } + } + } + + QString log = u8"总共有"+QString::number(cv::sum(msk).val[0])+u8"个盲元点"; + emit signalLog(log); + // qDebug()<<"stagecount"<