diff --git a/runner17/Enchanter.exe b/runner17/Enchanter.exe index 59a6e62..6025ee8 100644 Binary files a/runner17/Enchanter.exe and b/runner17/Enchanter.exe differ diff --git a/runner17/Enchanterd.exe b/runner17/Enchanterd.exe index 54cfd4a..dea5b4f 100644 Binary files a/runner17/Enchanterd.exe and b/runner17/Enchanterd.exe differ diff --git a/src/algorithm/AlgorithmFluorescence.cpp b/src/algorithm/AlgorithmFluorescence.cpp index 407af7f..1b1ff18 100644 --- a/src/algorithm/AlgorithmFluorescence.cpp +++ b/src/algorithm/AlgorithmFluorescence.cpp @@ -81,7 +81,7 @@ int CAlgorithmFluorescence::IImageAnalysis(class IImageObject* pImgObj, TP_ALGOR int ratioType = vMap.value("RatioType").toInt();//偏距检测模式 启用方式 double ratioVal = vMap.value("Ratio").toDouble();//偏距系数 - bool bEqual = vMap.value("bEqual").toBool();//使用使用图像增强 + bool bEqual = vMap.value("bEqual").toBool();//是否使用图像增强 int filterSize = vMap.value("filterSize").toInt();//过滤圆大小 cParam.CirclePolarity = vMap.value("Circle_Polarity",0).toInt(); cParam.CircleACThres = vMap.value("Circle_ACThres",3).toInt(); @@ -240,9 +240,9 @@ QString CAlgorithmFluorescence::bestMatch(const QMap* mod double minRatio = pWheel->getMinRotia(); double maxRatio = pWheel->getMaxRotia(); - if (curRatioVal > 0 && minRatio > 0 && maxRatio > 0) + if (curRatioVal != 0) { - if (curRatioVal < minRatio || curRatioVal > maxRatio) + if ((curRatioVal < minRatio || curRatioVal > maxRatio) && maxRatio > minRatio) { nIndex++; continue; diff --git a/src/algorithm/ImageProcess.cpp b/src/algorithm/ImageProcess.cpp index abc621e..a37eb55 100644 --- a/src/algorithm/ImageProcess.cpp +++ b/src/algorithm/ImageProcess.cpp @@ -14,7 +14,6 @@ ImageProcess::ImageProcess() { } - ImageProcess::~ImageProcess() { } @@ -63,9 +62,11 @@ cv::Mat ImageProcess::findCircle(const Mat &srcImg, Point2f& center, double &rad cv::resize(src, detectImg, cv::Size(src.cols / REAIZE, src.rows / REAIZE)); int bBaseX = detectImg.cols; int bBaseY = detectImg.rows; - if(bEqual == true) + if (bEqual == true) + { equalizeHist(detectImg, detectImg); - detectImg = _EnhanImg_sharpen(detectImg); + detectImg = _EnhanImg_sharpen(detectImg); + } EDCircles edcircles(detectImg); vector EDCircle = edcircles.getCircles(); @@ -108,16 +109,98 @@ cv::Mat ImageProcess::findCircle(const Mat &srcImg, Point2f& center, double &rad return DetectCircle(srcImg, Mat(), center, radius, bEqual, cParam); } else { - center.x = centerX; - center.y = centerY; + center.x = 0; + center.y = 0; radius = 0; return DetectCircle(srcImg, Mat(), center, radius, bEqual, cParam); } } -Mat ImageProcess::DetectCircle(Mat srcImg, Mat background, Point2f& center, double& radius, bool bEqual, const CircleParam& cParam) +//Mat ImageProcess::DetectCircle(Mat srcImg, Mat background, Point2f& center, double& radius, bool bEqual, const CircleParam& cParam) +//{ +// Mat img; +// if (!background.empty()) { +// img = getForeImage(srcImg, background); +// } +// else { +// img = srcImg; +// } +// Mat detectImg; +// if (bEqual == true) { +// equalizeHist(img, detectImg); +// } +// else { +// detectImg = img; +// } +// +// CircleDetector cd; +// cd.setAlgoType(CircleDetector::PeakCircle); +// cd.setEdgeWidth(cParam.CircleEdgeWidth); +// if(cParam.CirclePolarity == 0) +// cd.setPolarity(Polarity::Black2White); +// else +// cd.setPolarity(Polarity::White2Black); +// +// cd.setFindBy(FindBy::Best); +// if (center.x == 0 || center.y == 0) +// { +// center.x = img.cols / 2; +// center.y = img.rows / 2; +// } +// int rY = img.rows - center.y; +// int rX = img.cols - center.x; +// int min_dify = center.y > rY ? rY : center.y; +// int min_difx = center.x > rX ? rX : center.x; +// int maxRadius = abs(abs(min_difx > min_dify ? min_dify : min_difx)-50); +// double difRadiusMin = radius - 150; +// double difRadiusMax = radius + 250; +// if (difRadiusMin <= 0) +// { +// difRadiusMin = cParam.filterSize; +// difRadiusMax = maxRadius; +// } +// +// //控制范围,不让检测越界 +// //if (difRadiusMin < cParam.filterSize) +// difRadiusMin = cParam.filterSize; +// //if (difRadiusMax > maxRadius) +// difRadiusMax = maxRadius; +// if (difRadiusMin > difRadiusMax) +// difRadiusMin = 0; +// +// cd.setRadii(difRadiusMin, difRadiusMax); +// cd.setACThres(cParam.CircleACThres); +// vector allScores; +// Vec3f bestCircle; +// float bestScore = cd.detectBest(detectImg, Point2f(center.x, center.y), bestCircle, &allScores); +// if (abs(bestScore) <= FLT_EPSILON || bestCircle == Vec3f::zeros()) { +// center.x = 0; +// center.y = 0; +// radius = 0; +// return Mat(); +// } +// +// Point2f cen(bestCircle[0], bestCircle[1]); +// double r = bestCircle[2]; +// Rect rect; +// rect.x = cen.x - r; +// rect.y = cen.y - r; +// if (rect.x < 0) +// rect.x = 0; +// if (rect.y < 0) +// rect.y = 0; +// rect.width = 2 * r; +// rect.height = 2 * r; +// Mat s = srcImg(rect); +// center = cen; +// radius = r; +// return s; +//} + +//分别使用从深到浅和从浅到深检测圆,取效果较好的作为结果 +cv::Mat ImageProcess::DetectCircle(Mat srcImg, Mat background, Point2f& center, double& radius, bool bEqual, const CircleParam& cParam) { - Mat img; + cv::Mat img; if (!background.empty()) { img = getForeImage(srcImg, background); } @@ -127,19 +210,15 @@ Mat ImageProcess::DetectCircle(Mat srcImg, Mat background, Point2f& center, doub Mat detectImg; if (bEqual == true) { equalizeHist(img, detectImg); + detectImg = _EnhanImg_sharpen(detectImg); } else { detectImg = img; } - CircleDetector cd; cd.setAlgoType(CircleDetector::PeakCircle); cd.setEdgeWidth(cParam.CircleEdgeWidth); - if(cParam.CirclePolarity == 0) - cd.setPolarity(Polarity::Black2White); - else - cd.setPolarity(Polarity::White2Black); - + cd.setPolarity(Polarity::Black2White); cd.setFindBy(FindBy::Best); if (center.x == 0 || center.y == 0) { @@ -150,7 +229,7 @@ Mat ImageProcess::DetectCircle(Mat srcImg, Mat background, Point2f& center, doub int rX = img.cols - center.x; int min_dify = center.y > rY ? rY : center.y; int min_difx = center.x > rX ? rX : center.x; - int maxRadius = abs(abs(min_difx > min_dify ? min_dify : min_difx)-50); + int maxRadius = abs(abs(min_difx > min_dify ? min_dify : min_difx) - 50); double difRadiusMin = radius - 150; double difRadiusMax = radius + 250; if (difRadiusMin <= 0) @@ -158,26 +237,56 @@ Mat ImageProcess::DetectCircle(Mat srcImg, Mat background, Point2f& center, doub difRadiusMin = cParam.filterSize; difRadiusMax = maxRadius; } - //控制范围,不让检测越界 //if (difRadiusMin < cParam.filterSize) - difRadiusMin = cParam.filterSize; + difRadiusMin = cParam.filterSize; //if (difRadiusMax > maxRadius) - difRadiusMax = maxRadius; + difRadiusMax = maxRadius; if (difRadiusMin > difRadiusMax) difRadiusMin = 0; cd.setRadii(difRadiusMin, difRadiusMax); cd.setACThres(cParam.CircleACThres); vector allScores; - Vec3f bestCircle; - float bestScore = cd.detectBest(detectImg, Point2f(center.x, center.y), bestCircle, &allScores); - if (abs(bestScore) <= FLT_EPSILON || bestCircle == Vec3f::zeros()) { + cv::Vec3f bestCircleB2W; + float bestScoreB2W = cd.detectBest(detectImg, Point2f(center.x, center.y), bestCircleB2W, &allScores); + bool b2wFlag = true; + if (abs(bestScoreB2W) <= FLT_EPSILON || bestCircleB2W == Vec3f::zeros()) { + center.x = 0; + center.y = 0; + radius = 0; + b2wFlag = false; + } + + cd.setPolarity(Polarity::White2Black); + cv::Vec3f bestCircleW2B; + float bestScoreW2B = cd.detectBest(detectImg, cv::Point2f(center.x, center.y), bestCircleW2B, &allScores); + bool w2bFlag = true; + if (abs(bestScoreW2B) <= FLT_EPSILON || bestCircleW2B == Vec3f::zeros()) { center.x = 0; center.y = 0; radius = 0; - return Mat(); + w2bFlag = false; } + if (!b2wFlag && !w2bFlag) + return cv::Mat(); + + float radiusB2W = bestCircleB2W[2]; + float radiusW2B = bestCircleW2B[2]; + cv::Vec3f bestCircle; + //避免出现半径大的,中心偏差较大的现象 + if (std::abs(radiusB2W - radiusW2B) < 5) + { + double xDisB2W = bestCircleB2W[0] - center.x; + double yDisB2W = bestCircleB2W[1] - center.y; + double centerDisB2W = xDisB2W * xDisB2W + yDisB2W * yDisB2W; + double xDisW2B = bestCircleW2B[0] - center.x; + double yDisW2B = bestCircleB2W[0] - center.y; + double centerDisW2B = xDisW2B * xDisW2B + yDisW2B * yDisW2B; + bestCircle = centerDisB2W < centerDisW2B ? bestCircleB2W : bestCircleW2B; + } + else + bestCircle = radiusB2W > radiusW2B ? bestCircleB2W : bestCircleW2B; Point2f cen(bestCircle[0], bestCircle[1]); double r = bestCircle[2]; @@ -195,7 +304,6 @@ Mat ImageProcess::DetectCircle(Mat srcImg, Mat background, Point2f& center, doub radius = r; return s; } - //使用背景图做减法扣圆 cv::Mat ImageProcess::findCircleByBackground(const Mat &srcImg, const Mat& backgroundImg, Point2f& center, double &radius, bool bEqual, int filterSize, const CircleParam& cParam) { diff --git a/src/tpMain/CamConfig.cpp b/src/tpMain/CamConfig.cpp index d0d2821..129dbec 100644 --- a/src/tpMain/CamConfig.cpp +++ b/src/tpMain/CamConfig.cpp @@ -8,7 +8,6 @@ CamConfig::CamConfig(QString strPath) init(); } - CamConfig::~CamConfig() { } diff --git a/src/tpMain/NetProtocol.cpp b/src/tpMain/NetProtocol.cpp index 5e1f11b..ba021a3 100644 --- a/src/tpMain/NetProtocol.cpp +++ b/src/tpMain/NetProtocol.cpp @@ -91,7 +91,9 @@ QByteArray NetProtocol::parseData(const QByteArray dataSrc, int &nCmd, QList QAbstractSpinBox::NoButtons + + -9999.000000000000000 + 9999.989999999999782 @@ -378,6 +381,9 @@ QAbstractSpinBox::NoButtons + + -9999.899999999999636 + 9999.989999999999782 diff --git a/tpvs17/tpMain/lpMainWin.cpp b/tpvs17/tpMain/lpMainWin.cpp index 118d5e2..f94725b 100644 --- a/tpvs17/tpMain/lpMainWin.cpp +++ b/tpvs17/tpMain/lpMainWin.cpp @@ -23,12 +23,12 @@ #include #include "lpCryptokey.h" -#define VERSION_HUB "3.0.3.4" -#define VERSION_ALG "3.0.1.6" -#define UPDATE_TIME "2022-06-20" +#define VERSION_HUB "3.0.3.4.1" +#define VERSION_ALG "3.0.1.7" +#define UPDATE_TIME "2022-08-29" #define WHEELHIGHTTHRESH 250.0 //轮毂高度阈值(10英寸),当轮毂高度大于这个值时,启用相机升高的直径算法 -#define CAMERAUPHEIGHT 112.0 //相机上升高度,默认11.2cm +#define CAMERAUPHEIGHT 115.0 //相机上升高度,默认11.5 #pragma execution_character_set("utf-8") lpMainWin::lpMainWin(QWidget *parent) @@ -596,9 +596,6 @@ void lpMainWin::INewCameraImage(const QString& camKey, QImage img) void lpMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap) { try { - - - m_glbalRatio = 0; emit(sgShowImgState(tr("显示识别结果"))); Result2Ui *pResult = (Result2Ui*)vMap.value("result").toLongLong(); double vRatioVal = vMap.value("ratioVal").toDouble(); @@ -717,7 +714,7 @@ void lpMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap) SendResultChannel2PLC(pResult);//发送检测结果通道到PLC m_pCtrl->saveResult(pResult); - + m_glbalRatio = 0; delete pResult; } catch(...) @@ -1143,17 +1140,17 @@ void lpMainWin::timerEvent(QTimerEvent *event) void lpMainWin::closeEvent(QCloseEvent *event) { - QMessageBox info(this); - info.setWindowIcon(QIcon(":/image/leaper")); - info.setWindowTitle(QObject::tr("警告")); - info.setText(QObject::tr("本检测系统正在运行,您真的要关闭?")); - info.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - info.setButtonText(QMessageBox::Ok, QObject::tr("确定")); - info.setButtonText(QMessageBox::Cancel, QObject::tr("取消")); - if (info.exec() != QMessageBox::Ok) - { - return event->ignore(); - } + //QMessageBox info(this); + //info.setWindowIcon(QIcon(":/image/leaper")); + //info.setWindowTitle(QObject::tr("警告")); + //info.setText(QObject::tr("本检测系统正在运行,您真的要关闭?")); + //info.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + //info.setButtonText(QMessageBox::Ok, QObject::tr("确定")); + //info.setButtonText(QMessageBox::Cancel, QObject::tr("取消")); + //if (info.exec() != QMessageBox::Ok) + //{ + // return event->ignore(); + //} if (m_pDebugDlg) { if (!m_pDebugDlg->isHidden()) @@ -1651,8 +1648,8 @@ void lpMainWin::onShowResult(Result2Ui* pRlt) ui.main_lb_res_ng_num->setText(QString::number(DetectState::instance()->totalUnDetectNum)); ui.main_lb_res_ok_num->setText(QString::number(DetectState::instance()->totalDetectNum)); ui.main_lb_res_model_time->setText(QString::number(pRlt->m_dRunTime, 'f', 2)); - ui.main_lb_res_model_thickness->setText(QString::number((int)pRlt->m_dThickness)); - ui.main_lb_res_model_diameter->setText(QString::number((int)pRlt->m_dDiameter)); + //ui.main_lb_res_model_thickness->setText(QString::number((int)pRlt->m_dThickness)); + //ui.main_lb_res_model_diameter->setText(QString::number((int)pRlt->m_dDiameter)); ui.main_lb_res_model_id->setText(pRlt->m_strModel); ui.main_lb_res_model_score->setText(QString::number(pRlt->m_dScore * 100, 'f', 1) + "%"); diff --git a/tpvs17/tpMain/lpMainWin.ui b/tpvs17/tpMain/lpMainWin.ui index 1272e98..6f89f72 100644 --- a/tpvs17/tpMain/lpMainWin.ui +++ b/tpvs17/tpMain/lpMainWin.ui @@ -288,7 +288,28 @@ 0 - + + + + + 12 + + + + + + + QFrame::Sunken + + + 通道 + + + true + + + + @@ -314,27 +335,6 @@ - - - - - 12 - - - - - - - QFrame::Sunken - - - 通道 - - - true - - - @@ -363,33 +363,7 @@ - - - - - 0 - 0 - - - - - 12 - 75 - true - - - - background-color: rgb(170, 170, 127); - - - 0 - - - Qt::AlignCenter - - - - + @@ -440,66 +414,23 @@ - - - - - 0 - 0 - - - - - 12 - 75 - true - - - - background-color: rgb(170, 170, 127); - - - - 0 - - - Qt::AlignCenter - - - - - + + 0 - 0 + 35 - - - 12 - - - - true - - - false - - - - - QFrame::NoFrame + background-color: rgb(200, 255, 100); +font: 75 24pt "Consolas"; - 已检测(个) - - - Qt::AutoText + None - - true + + Qt::AlignCenter @@ -530,27 +461,33 @@ - - - - - 0 - 35 - + + + + + 0 + 0 + + + + + 12 + 75 + true + - background-color: rgb(200, 255, 100); -font: 75 24pt "Consolas"; + background-color: rgb(170, 170, 127); - None + 0 Qt::AlignCenter - + @@ -583,33 +520,12 @@ font: 75 24pt "Consolas"; - - - - - 82 - 16777215 - - - - - 12 - - - - - - - 匹配值 - - - - - + + - 70 - 19 + 82 + 0 @@ -627,11 +543,11 @@ font: 75 24pt "Consolas"; - 直径(mm) + 时间(s) - + @@ -671,41 +587,56 @@ font: 75 24pt "Consolas"; - - + + + + + 12 + + + + 偏距 + + + + + - 82 + 0 0 - - - 82 - 16777215 - - 12 + + true + + + false + + + QFrame::NoFrame + - 时间(s) + 已检测(个) + + + Qt::AutoText + + + true - - - - - 0 - 0 - - + + 12 @@ -724,8 +655,8 @@ font: 75 24pt "Consolas"; - - + + 82 @@ -741,39 +672,7 @@ font: 75 24pt "Consolas"; - 厚度(mm) - - - - - - - - 12 - - - - 偏距 - - - - - - - - 12 - 75 - true - - - - background-color: rgb(170, 170, 127); - - - 0 - - - Qt::AlignCenter + 匹配值