From cb341860411135eed60e7aacf39caa12303466ee Mon Sep 17 00:00:00 2001 From: "bob.pan" Date: Tue, 14 Sep 2021 10:29:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=8C=E7=BA=A7=E6=89=BE?= =?UTF-8?q?=E5=9C=86=E7=AE=97=E6=B3=95=EF=BC=8C=E6=8F=90=E9=AB=98=E5=9C=86?= =?UTF-8?q?=E6=8A=A0=E5=9B=BE=E5=87=86=E7=A1=AE=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/algorithm/AlgorithmFluorescence.cpp | 21 +- src/algorithm/ImageProcess.cpp | 112 +++++++ src/algorithm/ImageProcess.h | 4 + tpvs17/lpReport/lpReport.vcxproj | 8 +- tpvs17/tpMain/QModelMgrDlg.cpp | 2 +- tpvs17/tpMain/QModelMgrDlg.ui | 384 ++++++++++++++---------- tpvs17/tpMain/lpMainWin.cpp | 8 +- 7 files changed, 360 insertions(+), 179 deletions(-) diff --git a/src/algorithm/AlgorithmFluorescence.cpp b/src/algorithm/AlgorithmFluorescence.cpp index 07b520b..941b92c 100644 --- a/src/algorithm/AlgorithmFluorescence.cpp +++ b/src/algorithm/AlgorithmFluorescence.cpp @@ -291,7 +291,19 @@ int CAlgorithmFluorescence::IImageAnalysis(class IImageObject* pImgObj, TP_ALGOR bReload = false; } //imageSegementation(matSrc); - matMatch = ImageProcess::findCircleObject(matSrc, matBack, bUseBackground, nthreshold/*15*/, &lCircle/* NULL*/); + //matMatch = ImageProcess::findCircleObject(matSrc, matBack, bUseBackground, nthreshold/*15*/, &lCircle/* NULL*/); + Point2f centerPoint; + double radius = 0; + matMatch = ImageProcess::findCircle(matSrc, centerPoint, radius, bUseBackground); + lCircle.ptCenter = centerPoint; + lCircle.fRadius = radius; + + if (matMatch.cols >= 900 || matMatch.rows >= 900) + { + + cv::resize(matMatch, matMatch, cv::Size(matMatch.cols / 2, matMatch.rows / 2)); + lCircle.fRadius = lCircle.fRadius / 2; + } } else{ matMatch = matSrc; @@ -307,12 +319,11 @@ int CAlgorithmFluorescence::IImageAnalysis(class IImageObject* pImgObj, TP_ALGOR pImgObj->IVariantMapToUI(rltMap); return 0; } - //Mat matMatch = ImageProcess::findCircleObject(matSrc, matBack, 15, NULL/* &lCircle*/); - //double dDiameter = dD2H * matMatch.rows; + double dDiameter = dD2H * lCircle.fRadius * 2; CLocalWheel wheelLocal; - wheelLocal.defectList = strModelList;// *getDefectListPtr(pImgObj); + wheelLocal.defectList = strModelList; wheelLocal.img = matMatch.clone(); wheelLocal.height = th; wheelLocal.diameter = dDiameter; @@ -333,8 +344,6 @@ int CAlgorithmFluorescence::IImageAnalysis(class IImageObject* pImgObj, TP_ALGOR pResult->m_dScore = dValue; } } - //else { - //} else if (matMatch.empty()) { diff --git a/src/algorithm/ImageProcess.cpp b/src/algorithm/ImageProcess.cpp index da4420b..d6f24fc 100644 --- a/src/algorithm/ImageProcess.cpp +++ b/src/algorithm/ImageProcess.cpp @@ -4,6 +4,9 @@ #include "ED.h" #include "EDLines.h" #include "EDCircles.h" + +#include "CircleDetector.h" + //摩轮宏定义 表示该算法用于摩轮型号识别检测 #define MOTO_DETECT @@ -129,6 +132,8 @@ cv::Mat ImageProcess::findCircleObject(const Mat &src, const Mat& backgroundImg, cv::resize(src, imgTmp, cSize); Mat foregroundImg = getForeImage(imgTmp, backgroundImg);// 0421 +// cv::resize(foregroundImg, foregroundImg, cv::Size(src.cols / REAIZE, src.rows / REAIZE)); + using namespace luffy_base; luffy_threshold::Threshold(foregroundImg, imgBinary, nThres);//0421 @@ -581,3 +586,110 @@ cv::Mat ImageProcess::getForeImage(const Mat & src, const Mat &backgroundImg) return (src - resizedBackgroundImg); } +//输入一张灰度图,输出抠出的圆小图和半径,圆心坐标 +cv::Mat ImageProcess::findCircle(const Mat &srcImg, Point2f& center, double &radius, bool bEqual, int filterSize) +{ + Mat detectImg; + Mat src = srcImg; + + cv::resize(src, detectImg, cv::Size(src.cols / REAIZE, src.rows / REAIZE)); + int bBaseX = detectImg.cols; + int bBaseY = detectImg.rows; + if(bEqual == true) + equalizeHist(detectImg, detectImg); + detectImg = _EnhanImg_sharpen(detectImg); + + EDCircles edcircles(detectImg); + vector EDCircle = edcircles.getCircles(); + double maxR = 0; + int nIndex = -1; + for (int i = 0; i < EDCircle.size(); i++) + { + int startX = EDCircle[i].center.x - EDCircle[i].r; + int startY = EDCircle[i].center.y - EDCircle[i].r; + if (startX < 0 || startY < 0) + continue; + if (EDCircle[i].center.x + EDCircle[i].r > bBaseX || EDCircle[i].center.y + EDCircle[i].r > bBaseY) + continue; + if((EDCircle[i].r * REAIZE) < filterSize)//过滤半径小于指定宽度的圆 + continue; + + if (EDCircle[i].r > maxR) + { + maxR = EDCircle[i].r; + nIndex = i; + } + } + if (nIndex != -1) + { + int startX = EDCircle[nIndex].center.x * REAIZE - EDCircle[nIndex].r * REAIZE; + int startY = EDCircle[nIndex].center.y * REAIZE - EDCircle[nIndex].r* REAIZE; + radius = EDCircle[nIndex].r; + int hight = 2 * radius * REAIZE; + + center.x = (EDCircle[nIndex].center.x * REAIZE); + center.y = (EDCircle[nIndex].center.y * REAIZE); + radius = radius * REAIZE; + return DetectCircle(srcImg, center, radius, bEqual); + } + else { + center.x = srcImg.cols/2; + center.y = srcImg.rows/2; + radius = 0; + return DetectCircle(srcImg,center,radius,bEqual); + } +} + +Mat ImageProcess::DetectCircle(Mat img, Point2f& center, double& radius, bool bEqual) +{ + Mat detectImg; + if (bEqual == true) + { + equalizeHist(img, detectImg); + } + else + { + detectImg = img; + } + + CircleDetector cd; + cd.setAlgoType(CircleDetector::PeakCircle); + cd.setEdgeWidth(3); + cd.setPolarity(Polarity::White2Black); + cd.setFindBy(FindBy::Best); + double difRadiusMin = radius - 100; + double difRadiusMax = radius + 150; + if (difRadiusMin < 0) + { + difRadiusMin = 0; + difRadiusMax = abs(center.y - (img.cols / 2)) - 50; + } + + cd.setRadii(difRadiusMin, difRadiusMax); + cd.setACThres(3); + 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 = img(rect); + center = cen; + radius = r; + return s; +} \ No newline at end of file diff --git a/src/algorithm/ImageProcess.h b/src/algorithm/ImageProcess.h index ecc3fbe..dd81fd9 100644 --- a/src/algorithm/ImageProcess.h +++ b/src/algorithm/ImageProcess.h @@ -23,6 +23,10 @@ public: static cv::Mat findCircleObject(const Mat &src, const Mat& backgroundImg, bool useBackgroundFlag, int nThres = 20, luffy_base::luffyCircle *pCircle = NULL); static cv::Mat getForeImage(const Mat & src, const Mat &backgroundImg); + + static cv::Mat findCircle(const Mat &srcImg, Point2f& center, double &radius, bool bEqual, int filterSize=50);//找圆 + static cv::Mat DetectCircle(Mat img, Point2f& center, double& radius, bool bEqual);//精细找圆 + }; #endif diff --git a/tpvs17/lpReport/lpReport.vcxproj b/tpvs17/lpReport/lpReport.vcxproj index 70f51d3..cb97b76 100644 --- a/tpvs17/lpReport/lpReport.vcxproj +++ b/tpvs17/lpReport/lpReport.vcxproj @@ -52,7 +52,7 @@ true - UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + UNICODE;_UNICODE;WIN32;WIN64;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;%(AdditionalIncludeDirectories) Disabled ProgramDatabase @@ -70,7 +70,7 @@ .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp Moc'ing %(Identity)... .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;%(AdditionalIncludeDirectories) - UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + UNICODE;_UNICODE;WIN32;WIN64;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) Uic'ing %(Identity)... @@ -84,7 +84,7 @@ true - UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + UNICODE;_UNICODE;WIN32;WIN64;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;%(AdditionalIncludeDirectories) MultiThreadedDLL @@ -101,7 +101,7 @@ .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp Moc'ing %(Identity)... .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;%(AdditionalIncludeDirectories) - UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + UNICODE;_UNICODE;WIN32;WIN64;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) Uic'ing %(Identity)... diff --git a/tpvs17/tpMain/QModelMgrDlg.cpp b/tpvs17/tpMain/QModelMgrDlg.cpp index ea1a620..3882c0b 100644 --- a/tpvs17/tpMain/QModelMgrDlg.cpp +++ b/tpvs17/tpMain/QModelMgrDlg.cpp @@ -69,7 +69,7 @@ QModelMgrDlg::QModelMgrDlg(IWheelCtrl *ptr, QWidget *parent) m_pModelLists = new ModelsView(ui.ModelMgr_Models_tableView, m_pModelMgr->getAllModelMapPtr()); m_pModelLists->setHideItems(QStringList() << "NG"); connect(m_pModelLists, SIGNAL(sgSelectModel(QString)), this, SLOT(onShowModelInfo(QString))); - //connect(m_pModelLists, SIGNAL(sgSelectModel(QString)), this, SLOT(onShowModelPic(QString))); + connect(m_pModelLists, SIGNAL(sgSelectModel(QString)), this, SLOT(onShowModelPic(QString))); connect(this, SIGNAL(sgTrainShowInfo(QString)), this, SLOT(onShowModelInfo(QString))); connect(m_pShowImgList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(onItemDoubleClicked(QListWidgetItem*))); diff --git a/tpvs17/tpMain/QModelMgrDlg.ui b/tpvs17/tpMain/QModelMgrDlg.ui index 1866a35..f37b235 100644 --- a/tpvs17/tpMain/QModelMgrDlg.ui +++ b/tpvs17/tpMain/QModelMgrDlg.ui @@ -6,15 +6,22 @@ 0 0 - 985 - 691 + 1031 + 657 QModelMgrDlg - - + + + + + + + + + @@ -104,99 +111,8 @@ - + - - - - - 11 - - - - 图片显示: - - - - - - - - - - - - - - - - - - - 0 - 0 - - - - - 41 - 41 - - - - 添加已裁剪的轮毂图片 - - - 添加已裁剪的轮毂图片 - - - 追加 - - - false - - - false - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 0 - 0 - - - - 删除所有模板 - - - 删除所有模板 - - - - - - - - - - - @@ -205,6 +121,12 @@ 0 + + + 0 + 0 + + 11 @@ -219,7 +141,7 @@ false - + @@ -351,6 +273,106 @@ + + + + + + + 129 + 129 + + + + true + + + + + + Qt::PlainText + + + :/image/none.jpg + + + false + + + Qt::AlignCenter + + + false + + + + + + + + 11 + + + + 缩略图 + + + Qt::AlignCenter + + + + + + + + + + + 最小系数 + + + + + + + + 0 + 0 + + + + + 100 + 16777215 + + + + + + + + 最大系数 + + + + + + + + 0 + 0 + + + + + 100 + 16777215 + + + + + + @@ -439,51 +461,92 @@ - - - - - + + + + + + + + 11 + + + + 图片显示: + + + + + + + + + + + + + + + + + + + 0 + 0 + + + - 129 - 129 + 41 + 41 - - true - - - + + 添加已裁剪的轮毂图片 - - Qt::PlainText + + 添加已裁剪的轮毂图片 - - :/image/none.jpg + + 追加 - + false - - Qt::AlignCenter - - + false - - - - - 11 - + + + + Qt::Vertical - - 缩略图 + + + 20 + 40 + - - Qt::AlignCenter + + + + + + + 0 + 0 + + + + 删除所有模板 + + + 删除所有模板 + + + @@ -508,20 +571,29 @@ 基本操作 - - - + + + 0 0 + + + 61 + 51 + + - 训练所有模板,消耗时间会较长 + 添加新的模板 - 训练全部 + 新建模板 + + + true @@ -557,57 +629,48 @@ - - + + 0 0 - - - 61 - 51 - - - 添加新的模板 + 确认修改,每次修改模板的参数后都要确认修改才有效 - 新建模板 - - - true + 修改确认 - - + + - + 0 0 - - 确认修改,每次修改模板的参数后都要确认修改才有效 - - 修改确认 + 修改型号名 - - + + - + 0 0 + + 训练所有模板,消耗时间会较长 + - 修改型号名 + 训练全部 @@ -616,13 +679,6 @@ - - - - - - - diff --git a/tpvs17/tpMain/lpMainWin.cpp b/tpvs17/tpMain/lpMainWin.cpp index 2d65f11..c402095 100644 --- a/tpvs17/tpMain/lpMainWin.cpp +++ b/tpvs17/tpMain/lpMainWin.cpp @@ -22,9 +22,9 @@ #include "QZkJsonParser.h" #include -#define VERSION_HUB "3.0.0.2" -#define VERSION_ALG "3.0.0.2" -#define UPDATE_TIME "2021-05-08" +#define VERSION_HUB "3.0.0.3" +#define VERSION_ALG "3.0.0.3" +#define UPDATE_TIME "2021-09-07" #pragma execution_character_set("utf-8") lpMainWin::lpMainWin(QWidget *parent) @@ -532,7 +532,7 @@ void lpMainWin::INewCameraImage(const QString& camKey, QImage img) m_CamSettingDlg->onShowImage(img); } } -` + /*多线程发送算法结果*/ void lpMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap) {