From b4cb70a7cffc291ccb7cf072967163c829ab6d9a Mon Sep 17 00:00:00 2001 From: QuShuailong Date: Thu, 31 Mar 2022 16:37:19 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E8=BD=AE=E6=AF=82=E5=8F=AA=E6=8A=A0=E4=B8=80=E5=8D=8A?= =?UTF-8?q?=E7=9A=84bug=EF=BC=9B2=E3=80=81=E8=B0=83=E6=95=B4=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=9D=83=E9=99=90=E6=98=BE=E7=A4=BA=E7=9A=84=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9B3=E3=80=81=E6=B7=BB=E5=8A=A0=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E4=BF=AE=E6=94=B9=E5=A4=9A=E9=87=8D=E6=9B=9D=E5=85=89?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runner17/config/exposure.json | 10 + src/algorithm/ImageProcess.cpp | 6 +- src/tpMain/qworkmgrui.cpp | 18 +- tpvs17/tpMain/QAlgParamDlg.cpp | 23 +- tpvs17/tpMain/QAlgParamDlg.h | 12 +- tpvs17/tpMain/QAlgParamDlg.ui | 442 +++++++++++++++-------------- tpvs17/tpMain/QExposureTimeDlg.cpp | 111 ++++++++ tpvs17/tpMain/QExposureTimeDlg.h | 29 ++ tpvs17/tpMain/QExposureTimeDlg.ui | 276 ++++++++++++++++++ tpvs17/tpMain/lpMainWin.cpp | 14 +- tpvs17/tpMain/lpMainWin.h | 2 +- 11 files changed, 724 insertions(+), 219 deletions(-) create mode 100644 runner17/config/exposure.json create mode 100644 tpvs17/tpMain/QExposureTimeDlg.cpp create mode 100644 tpvs17/tpMain/QExposureTimeDlg.h create mode 100644 tpvs17/tpMain/QExposureTimeDlg.ui diff --git a/runner17/config/exposure.json b/runner17/config/exposure.json new file mode 100644 index 0000000..b234105 --- /dev/null +++ b/runner17/config/exposure.json @@ -0,0 +1,10 @@ +{ + "exposureTime": { + "time1": 500, + "time2": 600, + "time3": 700, + "time4": 800, + "time5": 900 + }, + "switch": 0 +} diff --git a/src/algorithm/ImageProcess.cpp b/src/algorithm/ImageProcess.cpp index 8da6382..abc621e 100644 --- a/src/algorithm/ImageProcess.cpp +++ b/src/algorithm/ImageProcess.cpp @@ -251,8 +251,10 @@ cv::Mat ImageProcess::findCircleByBackground(const Mat &srcImg, const Mat& backg return DetectCircle(srcImg, backgroundImg, center, radius, bEqual, cParam); } else { - center.x = centerX; - center.y = centerY; + //center.x = centerX; + //center.y = centerY; + center.x = 0; + center.y = 0; radius = 0; return DetectCircle(srcImg, backgroundImg, center, radius, bEqual, cParam); } diff --git a/src/tpMain/qworkmgrui.cpp b/src/tpMain/qworkmgrui.cpp index 59bc804..78fde69 100644 --- a/src/tpMain/qworkmgrui.cpp +++ b/src/tpMain/qworkmgrui.cpp @@ -274,22 +274,36 @@ void QWorkMgrUI::onStateChangedDiameter(int state) bool QWorkMgrUI::onUserRole() { int nLevel = m_pCtrl->getUserLevel(); + //9:根管理员权限;5:管理员权限;4:操作员权限;0:无权限 if (9 == nLevel) { m_UseDiameter->setVisible(true); m_UseThickness->setVisible(true); + m_UseDiameter->setEnabled(true); + m_UseThickness->setEnabled(true); } else if (5 == nLevel) { m_UseDiameter->setVisible(true); m_UseThickness->setVisible(true); + m_UseDiameter->setEnabled(true); + m_UseThickness->setEnabled(true); } else if (4 == nLevel) { - m_UseDiameter->setVisible(false); - m_UseThickness->setVisible(false); + m_UseDiameter->setVisible(true); + m_UseThickness->setVisible(true); + m_UseDiameter->setEnabled(true); + m_UseThickness->setEnabled(true); } else if (1 == nLevel){ m_UseDiameter->setVisible(false); m_UseThickness->setVisible(false); } + else if (0 == nLevel) + { + m_UseDiameter->setVisible(true); + m_UseThickness->setVisible(true); + m_UseDiameter->setEnabled(false); + m_UseThickness->setEnabled(false); + } else { return false; } diff --git a/tpvs17/tpMain/QAlgParamDlg.cpp b/tpvs17/tpMain/QAlgParamDlg.cpp index 4bc4551..309cb34 100644 --- a/tpvs17/tpMain/QAlgParamDlg.cpp +++ b/tpvs17/tpMain/QAlgParamDlg.cpp @@ -12,13 +12,24 @@ QAlgParamDlg::QAlgParamDlg(QWidget *parent) connect(ui.m_pbShowBackImage, SIGNAL(clicked()), this, SLOT(onButtonClicked())); connect(ui.m_pbApply, SIGNAL(clicked()), this, SLOT(onButtonClicked())); connect(ui.m_pbExit, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.m_setExposureTime, SIGNAL(clicked()), this, SLOT(onButtonClicked())); ui.label->setVisible(false); + m_pExposureTimeDlg = new QExposureTimeDlg(); + connect(m_pExposureTimeDlg, SIGNAL(sgExpsParamChange()), this, SLOT(onChangeExps())); } QAlgParamDlg::~QAlgParamDlg() { + if (m_pExposureTimeDlg) + { + delete m_pExposureTimeDlg; + m_pExposureTimeDlg = nullptr; + } +} +Q_SLOT void QAlgParamDlg::onChangeExps() +{ + emit sgExpsChange(); } - Q_SLOT void QAlgParamDlg::onButtonClicked() { QString strObj = sender()->objectName(); @@ -35,6 +46,16 @@ Q_SLOT void QAlgParamDlg::onButtonClicked() m_showImgDlg.setPicPath(DstPath); m_showImgDlg.exec(); } + else if (strObj == "m_setExposureTime") + { + if (m_pExposureTimeDlg) + { + m_pExposureTimeDlg->setParent(this); + m_pExposureTimeDlg->setWindowTitle(tr("多重曝光设置")); + m_pExposureTimeDlg->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + m_pExposureTimeDlg->show(); + } + } else if (strObj == "m_pbApply") { getParam(); diff --git a/tpvs17/tpMain/QAlgParamDlg.h b/tpvs17/tpMain/QAlgParamDlg.h index 85c94a7..c1648f7 100644 --- a/tpvs17/tpMain/QAlgParamDlg.h +++ b/tpvs17/tpMain/QAlgParamDlg.h @@ -2,8 +2,11 @@ #define _QALGPARAMDLG_H_ #include + +#include "QExposureTimeDlg.h" #include "ui_QAlgParamDlg.h" + class QAlgParamDlg : public QWidget { Q_OBJECT @@ -12,19 +15,26 @@ public: QAlgParamDlg(QWidget *parent = Q_NULLPTR); ~QAlgParamDlg(); Q_SLOT void onButtonClicked(); + signals: void sgParamChange(); + void sgExpsChange(); + protected: + Q_SLOT void onChangeBG(); + Q_SLOT void onChangeExps(); virtual void showEvent(QShowEvent *event); virtual void timerEvent(QTimerEvent *event); virtual void changeEvent(QEvent *event); void setParam(); void getParam(); - Q_SLOT void onChangeBG(); + private: Ui::QAlgParamDlg ui; int m_timeID{ 0 }; + QExposureTimeDlg* m_pExposureTimeDlg{ nullptr };//算法调参页面 + }; #endif diff --git a/tpvs17/tpMain/QAlgParamDlg.ui b/tpvs17/tpMain/QAlgParamDlg.ui index d8d59cb..ca2b286 100644 --- a/tpvs17/tpMain/QAlgParamDlg.ui +++ b/tpvs17/tpMain/QAlgParamDlg.ui @@ -6,253 +6,284 @@ 0 0 - 332 - 360 + 340 + 553 算法参数设置 - + + + + + + 12 + + + + 型号匹配: + + + + + + + 12 + + + + 是否使用偏距过滤模板 + + + + + + + + + + + 12 + + + + 二级圆定位: + + + + + + + 12 + + + + QAbstractSpinBox::NoButtons + + + + + + + + 12 + + + + 边缘宽度: + + + + + + + + 12 + + + + QAbstractSpinBox::NoButtons + + + + + + + + 12 + + + + + 从深到浅 + + + + + 从浅到深 + + + + + + + + + 12 + + + + 边缘对比度: + + + + + + + + 12 + + + + 边缘转换: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + - - - + + + 12 - - 二级圆定位: + + 多重曝光设置: - - - - - - 12 - - - - QAbstractSpinBox::NoButtons - - - - - - - - 12 - - - - 边缘宽度: - - - - - - - - 12 - - - - QAbstractSpinBox::NoButtons - - - - - - - - 12 - - - - - 从深到浅 - - - - - 从浅到深 - - - - - - - - - 12 - - - - 边缘对比度: - - - - - - - - 12 - - - - 边缘转换: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 12 - - - - 圆半径大小过滤: - - - - - - - - 100 - 0 - - - - - 12 - - - - QAbstractSpinBox::NoButtons - - - 999 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + + 12 + + + + 设置 + + - - - - - - - 12 - - - - 检测背景图更换: - - - - - - - - 12 - - - - 查看检测背景 - - - - + + + + + + + + + 12 + + + + 检测背景图更换: + + - - + + 12 - 是否使用图像增强 + 查看检测背景 - - + + + + + + 参数已生效!!! + + + + + + + + 12 + + + + 是否使用图像增强 + + + + + + + 12 - 是否使用背景图找圆算法 + 圆半径大小过滤: - - + + + + + 100 + 0 + + 12 - - 型号匹配: + + QAbstractSpinBox::NoButtons + + + 999 - - - - - - 12 - - - - 是否使用偏距过滤模板 - - - - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 12 + + + + 是否使用背景图找圆算法 + + + + @@ -293,13 +324,6 @@ - - - - 参数已生效!!! - - - diff --git a/tpvs17/tpMain/QExposureTimeDlg.cpp b/tpvs17/tpMain/QExposureTimeDlg.cpp new file mode 100644 index 0000000..51923df --- /dev/null +++ b/tpvs17/tpMain/QExposureTimeDlg.cpp @@ -0,0 +1,111 @@ +#include "QExposureTimeDlg.h" +#include + +#pragma execution_character_set("utf-8") + +QExposureTimeDlg::QExposureTimeDlg(QWidget* parent) : QWidget(parent) +{ + ui.setupUi(this); + ui.appliedLabel->setVisible(false); + connect(ui.m_pbApply, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.m_pbExit, SIGNAL(clicked()), this, SLOT(onButtonClicked())); +} +QExposureTimeDlg::~QExposureTimeDlg() +{ +} + +Q_SLOT void QExposureTimeDlg::onButtonClicked() +{ + QString strObj = sender()->objectName(); + if (strObj == "m_pbApply") + { + QString strPath = QApplication::applicationDirPath(); + savaParam(strPath); + ui.appliedLabel->setVisible(true); + m_timeID = startTimer(1000); + emit sgExpsParamChange(); + } + else if (strObj == "m_pbExit") + { + close(); + } +} + +void QExposureTimeDlg::showEvent(QShowEvent *event) +{ + QString strPath = QApplication::applicationDirPath(); + if (!showParam(strPath)) + { + } +} +void QExposureTimeDlg::timerEvent(QTimerEvent *event) +{ + if (m_timeID == event->timerId()) + { + killTimer(m_timeID); + m_timeID = 0; + ui.appliedLabel->setVisible(false); + } +} + +bool QExposureTimeDlg::showParam(const QString& strPath) +{ + QString filePath = strPath + "\\config\\exposure.json"; + QJsonObject jsonObj = QZkJsonParser::ReadJsonAuto(filePath); + if (jsonObj.empty()) + { + qDebug() << "Json file parsing failed!"; + return false; + } + + QJsonObject exposureObj = jsonObj.value("exposureTime").toObject(); + + QJsonObject::iterator objIterEnd = exposureObj.end(); + std::vector exposureTimeVec; + for (auto objIter = exposureObj.begin(); objIter != objIterEnd; objIter++) + { + int exposureTime = objIter.value().toInt(); + exposureTimeVec.emplace_back(exposureTime); + } + const unsigned int nSize = exposureTimeVec.size(); + if (nSize == 5) + { + ui.exposureTime1->setValue(exposureTimeVec[0]); + ui.exposureTime2->setValue(exposureTimeVec[1]); + ui.exposureTime3->setValue(exposureTimeVec[2]); + ui.exposureTime4->setValue(exposureTimeVec[3]); + ui.exposureTime5->setValue(exposureTimeVec[4]); + } + int switchFlag = jsonObj.value("switch").toInt(); + ui.multiExpSwitch->setChecked(switchFlag > 0 ? true : false); + return true; +} + +void QExposureTimeDlg::savaParam(const QString& strPath) +{ + QString filePath = strPath + "\\config\\exposure.json"; + QJsonObject jsonObj; + + //QJsonArray jsonArr; + QJsonObject expsObj; + int exposureTime1 = ui.exposureTime1->value(); + int exposureTime2 = ui.exposureTime2->value(); + int exposureTime3 = ui.exposureTime3->value(); + int exposureTime4 = ui.exposureTime4->value(); + int exposureTime5 = ui.exposureTime5->value(); + expsObj.insert("time1", exposureTime1); + expsObj.insert("time2", exposureTime2); + expsObj.insert("time3", exposureTime3); + expsObj.insert("time4", exposureTime4); + expsObj.insert("time5", exposureTime5); + + jsonObj.insert("exposureTime", expsObj); + int switchFlag = ui.multiExpSwitch->isChecked(); + jsonObj.insert("switch", switchFlag); + QJsonDocument jsonDoc(jsonObj); + QByteArray data = jsonDoc.toJson(); + QFile jsonFile(filePath); + jsonFile.open(QIODevice::WriteOnly); + jsonFile.write(data); + jsonFile.close(); +} \ No newline at end of file diff --git a/tpvs17/tpMain/QExposureTimeDlg.h b/tpvs17/tpMain/QExposureTimeDlg.h new file mode 100644 index 0000000..e625c5d --- /dev/null +++ b/tpvs17/tpMain/QExposureTimeDlg.h @@ -0,0 +1,29 @@ +#ifndef _H_QEXPOSURETIMEDLG_H_ +#define _H_QEXPOSURETIMEDLG_H_ +#include "ui_QExposureTimeDlg.h" +#include "QZkJsonParser.h" + +#include +#include +class QExposureTimeDlg : public QWidget +{ + Q_OBJECT +public: + QExposureTimeDlg(QWidget *parent = Q_NULLPTR); + ~QExposureTimeDlg(); + + Q_SLOT void onButtonClicked(); +signals: + void sgExpsParamChange(); +protected: + virtual void showEvent(QShowEvent *event); + virtual void timerEvent(QTimerEvent *event); + //virtual void changeEvent(QEvent *event); + +private: + Ui::QExposureTimeDlg ui; + bool showParam(const QString& strPath); + void savaParam(const QString& strPath); + int m_timeID{ 0 }; +}; +#endif // !_H_QEXPOSURETIMEDLG_H_ diff --git a/tpvs17/tpMain/QExposureTimeDlg.ui b/tpvs17/tpMain/QExposureTimeDlg.ui new file mode 100644 index 0000000..3655623 --- /dev/null +++ b/tpvs17/tpMain/QExposureTimeDlg.ui @@ -0,0 +1,276 @@ + + + QExposureTimeDlg + + + + 0 + 0 + 292 + 419 + + + + 曝光值设置 + + + + + + 曝光值 + + + + + + + + 二级曝光值: + + + + + + + 100000 + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + + + + 四级曝光值: + + + + + + + 100000 + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 12 + + + + 应用 + + + + + + + + 12 + + + + 退出 + + + + + + + + + + + 一级曝光值: + + + + + + + 100000 + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + + + + 三级曝光值: + + + + + + + 100000 + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + + + + 五级曝光值: + + + + + + + 100000 + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + + true + + + 参数已修改 + + + + + + + true + + + false + + + 多重曝光开关: + + + false + + + + + + 是否打开多重曝光功能 + + + + + + + + + + + + + + diff --git a/tpvs17/tpMain/lpMainWin.cpp b/tpvs17/tpMain/lpMainWin.cpp index ee21959..0c3aab8 100644 --- a/tpvs17/tpMain/lpMainWin.cpp +++ b/tpvs17/tpMain/lpMainWin.cpp @@ -188,6 +188,7 @@ lpMainWin::lpMainWin(QWidget *parent) m_pAlgParamDlg = new QAlgParamDlg();//算法参数设置页面 connect(m_pAlgParamDlg, SIGNAL(sgParamChange()), this, SLOT(onUpdateUI())); + connect(m_pAlgParamDlg, SIGNAL(sgExpsChange()), this, SLOT(onUpdateExposureSetting())); } { /*发送模板库线程*/ @@ -463,8 +464,9 @@ bool lpMainWin::onInitCoreCtrl() FuncCallBack_StrImg strImgfunc = std::bind(&lpMainWin::INewCameraImage, this, std::placeholders::_1, std::placeholders::_2); m_pCoreCtrl->IRegisterImageCallBack(strImgfunc); - - m_camKey = m_pCoreCtrl->ICameraKeys().first(); + QStringList s = m_pCoreCtrl->ICameraKeys(); + if(m_pCoreCtrl->ICameraKeys().size()>0) + m_camKey = m_pCoreCtrl->ICameraKeys().first(); return true; } @@ -1855,9 +1857,15 @@ Q_SLOT void lpMainWin::onwfPulseTimer() // frame.data8 = 50; // SendDataToCom(0x43, frame); } - +Q_SLOT void lpMainWin::onUpdateExposureSetting() +{ + QString strPath = QApplication::applicationDirPath(); + readExposureTimeConfig(strPath); +} bool lpMainWin::readExposureTimeConfig(const QString& strPath) { + if(!m_exposureTimeArray.empty()) + m_exposureTimeArray.clear(); QString filePath = strPath + "\\config\\exposure.json"; QJsonObject jsonObj = QZkJsonParser::ReadJsonAuto(filePath); if (jsonObj.empty()) diff --git a/tpvs17/tpMain/lpMainWin.h b/tpvs17/tpMain/lpMainWin.h index adda94c..b8eafde 100644 --- a/tpvs17/tpMain/lpMainWin.h +++ b/tpvs17/tpMain/lpMainWin.h @@ -73,7 +73,7 @@ private: Q_SLOT void onUpdateUI();//修改参数应用时,刷新UI显示内容 Q_SLOT void onShowRatioVal(double val); Q_SLOT void onLineseCheck(bool bFlag); - + Q_SLOT void onUpdateExposureSetting(); void onStrongButton(); protected: bool onInitCoreCtrl();