From 2ee33b7efcc559eafc30dc92bd0c0825f18f8148 Mon Sep 17 00:00:00 2001 From: "zhou.mengjia" Date: Mon, 8 Jan 2024 21:32:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E5=83=8F=E8=BD=AC=E6=8D=A2=E8=B7=B3?= =?UTF-8?q?=E8=BF=87=E9=BB=91=E7=99=BD=E5=9B=BE=E3=80=81=E5=9B=BE=E5=83=8F?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E7=94=A8LPV?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 ++++++++++++++++ src/CategoryMatcher.cpp | 31 +++++++++++++++++++++++++++++ src/CategoryMatcher.h | 11 +++++++++++ src/SmokeBoxIdentification.cpp | 36 ++++++++++++++++++++++++++++++++++ src/SmokeBoxIdentification.h | 4 ++++ src/lpv/LPVCalib.h | 8 ++++++++ src/lpv/LPVDisplay.h | 7 +++++++ 7 files changed, 114 insertions(+) create mode 100644 src/lpv/LPVCalib.h create mode 100644 src/lpv/LPVDisplay.h diff --git a/README.md b/README.md index 3300ffd..e4cf284 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,20 @@ Identify the types and quantities of smoke boxes +SmokeBoxIdentification.cpp中根据STOCK_CHECK_HEAD等关键词,选择哪个相机进行拍照。 + +所以需要跟通讯对一下,什么信号可以说明是哪个方向的相机进行拍摄。 + +之前是captureSide和captureTop,顶部和侧面拍摄。 + + + +相机载入的时候,读入矫正文件: + +m_calib->Load(strFileName.toStdString().c_str()); + + + +图片矫正: + +m_calib->FixImage(m_imgOrigin, m_imgFixed); diff --git a/src/CategoryMatcher.cpp b/src/CategoryMatcher.cpp index d8fff55..feac845 100644 --- a/src/CategoryMatcher.cpp +++ b/src/CategoryMatcher.cpp @@ -6,6 +6,7 @@ CategoryMatcher::CategoryMatcher(QObject *parent) { m_ilmatch = ILMatchPtr(__uuidof(LMatch)); m_ilmatchF = ILMatchPtr(__uuidof(LMatch)); + m_display = ILDisplayPtr(__uuidof(LDisplay)); initILMatchParam(QCoreApplication::applicationDirPath() + MATCHER_CONFIG); setILMatch(m_matchParam); qDebug() << "init CategoryMatcher successed"; @@ -72,6 +73,14 @@ void CategoryMatcher::setILMatch(const MatchParam& matchParam) } +bool CategoryMatcher::smokeMatch(const QString& typeNo, ILImagePtr image) +{ + std::pair> templateLevelAndvecMatchRltPtr; + bool bRlt = smokeMatch(typeNo, image, templateLevelAndvecMatchRltPtr); + drawImage(image, templateLevelAndvecMatchRltPtr); + return bRlt; +} + bool CategoryMatcher::smokeMatch(const QString& typeNo, const cv::Mat& inputMat, cv::Mat& rltMat) { if (inputMat.empty()) @@ -261,6 +270,28 @@ bool CategoryMatcher::getTemplateImgFileInfo(const QString& folderPath, Template return true; } + +void CategoryMatcher::drawImage(ILImagePtr image, std::pair> templateLevelAndvecMatchRltPtr) +{ + if (image->Height == 0 || image->Width == 0) + { + return; + } + int level = 1; + int templateLevel = templateLevelAndvecMatchRltPtr.first; + + //Displayϻͼ+ + + + +} + +void CategoryMatcher::saveResultsImage(const QString& filePath) +{ + std::wstring str = filePath.toStdWString(); + m_display->SaveSceneToFile(str.c_str(), 1, 1); +} + void CategoryMatcher::drawImage(const cv::Mat& imgMatSrc, cv::Mat& rltCvImg, std::pair> templateLevelAndvecMatchRltPtr) { diff --git a/src/CategoryMatcher.h b/src/CategoryMatcher.h index 0719e94..883bc2d 100644 --- a/src/CategoryMatcher.h +++ b/src/CategoryMatcher.h @@ -20,6 +20,8 @@ #include "LPVPat.h" #include "LPVImgProc.h" #include "DisplayHelper.h" +#include "LPVCalib.h" +#include "LPVDisplay.h" #include "commonDefine.h" @@ -51,7 +53,10 @@ class CategoryMatcher : public QObject public: CategoryMatcher(QObject *parent = nullptr); ~CategoryMatcher(); + bool smokeMatch(const QString& typeNo, ILImagePtr image); + void saveResultsImage(const QString& filePath); bool smokeMatch(const QString& typeNo, const cv::Mat& inputMat, cv::Mat& rltMat); + //signals: // void sgMatchRlt(bool bRlt, cv::Mat imgRltMat); private: @@ -60,13 +65,19 @@ private: bool getTemplateImgFileInfo(const QString& folderPath, TemplateObject& templateObject); bool smokeMatch(const QString& type, const ILImagePtr ilImgPtr, std::pair >& templateLevelAndvecMatchRltPtr); + void drawImage(const cv::Mat& imgMatSrc, cv::Mat& resulQImg, std::pair> templateLevelAndvecMatchRltPtr); + void drawImage(ILImagePtr image, std::pair> templateLevelAndvecMatchRltPtr); + + MatchParam m_matchParam; ILMatchPtr m_ilmatch; ILMatchPtr m_ilmatchF; + ILDisplayPtr m_display; QMutex m_mutex; + bool m_bUseTotalThresh{ false }; }; bool ensureGrayImg(const cv::Mat& img, cv::Mat& gray); diff --git a/src/SmokeBoxIdentification.cpp b/src/SmokeBoxIdentification.cpp index 69d411a..15a45ab 100644 --- a/src/SmokeBoxIdentification.cpp +++ b/src/SmokeBoxIdentification.cpp @@ -222,6 +222,41 @@ Q_SLOT void SmokeBoxIdentification::onCapturedImage(const QVector& ve cv::Mat imgRltMat; QString dataSaveFolder = QString("%1\\%2\\%3").arg(FILE_STORAGE_PATH) .arg(m_currtStockCheckInfo.stockNum).arg(m_currtStockCheckInfo.taskNum); + + +#if IMAGEDRAWING == LPV + for each (const ImageInfo& imgInfo in vecImageInfo) + { + QString str = QString("Camera %1 Match Start ...").arg(imgInfo.cameraSn); + qDebug() << str; + + if (!imgInfo.image.empty()) + { + ILImagePtr image(__uuidof(LImage)); + image->SetImageData(imgInfo.image.cols, imgInfo.image.rows, (void*)imgInfo.image.data, imgInfo.image.step, 0); + + if (m_pCategoryMatcher->smokeMatch(typeNum, image)) + { + str = QString("Camera %1 Match successful!").arg(imgInfo.cameraSn); + qDebug() << str; + bRlt = true; + FileInfo fileInfo = imgInfo.saveImgInfo; + QString fileName = QString("%1_%2_rlt%3").arg(fileInfo.strId) + .arg(m_currtStockCheckInfo.smokeTypeNum).arg(fileInfo.suffix); + QString filePath = QString("%1\\%2").arg(dataSaveFolder).arg(fileName); + m_pCategoryMatcher->saveResultsImage(filePath); + break; + } + + } + else + { + qDebug() << "imgInfo.image is Empty!"; + } + } + + +#elif IMAGEDRAWING == OPENCV for each (const ImageInfo& imgInfo in vecImageInfo) { QString str = QString("Camera %1 Match Start ...").arg(imgInfo.cameraSn); @@ -260,6 +295,7 @@ Q_SLOT void SmokeBoxIdentification::onCapturedImage(const QVector& ve // QImage resultQImg((const unsigned char*)imgRltMat.data, imgRltMat.cols, imgRltMat.rows, imgRltMat.step, QImage::Format_RGB888); // emit sgShowImage(m_pShowRltImgLabel, resultQImg); //} +#endif }); } } diff --git a/src/SmokeBoxIdentification.h b/src/SmokeBoxIdentification.h index 2d46299..c003ef4 100644 --- a/src/SmokeBoxIdentification.h +++ b/src/SmokeBoxIdentification.h @@ -23,6 +23,10 @@ #include "QNumTemplateBuild.h" #include "ui_SmokeBoxIdentification.h" +//#define IMAGEDRAWING OPENCV +#define IMAGEDRAWING LPV + + enum MsgType { EmptyCheckResult = 0, diff --git a/src/lpv/LPVCalib.h b/src/lpv/LPVCalib.h new file mode 100644 index 0000000..e34e331 --- /dev/null +++ b/src/lpv/LPVCalib.h @@ -0,0 +1,8 @@ +#pragma once +// the must-have LPVCoreLib +#import "libid:c34b3e9e-6dea-4aa9-b500-0266f90dc15f" no_namespace +// the must-have LPVGeomLib +#import "libid:8955aafb-4602-4d6a-a888-69d1437c4d2b" no_namespace +// import LPVCalibLib +#import "libid:faa32948-bf4e-4482-9216-70412f34bb66" no_namespace + diff --git a/src/lpv/LPVDisplay.h b/src/lpv/LPVDisplay.h new file mode 100644 index 0000000..8c736df --- /dev/null +++ b/src/lpv/LPVDisplay.h @@ -0,0 +1,7 @@ +#pragma once +// the must-have LPVCoreLib +#import "libid:c34b3e9e-6dea-4aa9-b500-0266f90dc15f" no_namespace +// the must-have LPVGeomLib +#import "libid:8955aafb-4602-4d6a-a888-69d1437c4d2b" no_namespace +// import LPVDisplayLib +#import "libid:5b289f4f-ebc9-4a41-bd94-07f4a4e4e5f6" no_namespace