diff --git a/runner17/Release/smokeBox.exe b/runner17/Release/smokeBox.exe index 0facfd9..42c62e9 100644 Binary files a/runner17/Release/smokeBox.exe and b/runner17/Release/smokeBox.exe differ diff --git a/src/CategoryMatcher.cpp b/src/CategoryMatcher.cpp index feac845..c21022a 100644 --- a/src/CategoryMatcher.cpp +++ b/src/CategoryMatcher.cpp @@ -105,6 +105,13 @@ bool CategoryMatcher::smokeMatch(const QString& typeNo, const ILImagePtr ilImgPt { TemplateObject templateObj; QString templateImgFolderPath = TYPE_TEMPLATE_PATH; + + //可能存在问题:之前的模板设计。后缀带了别的数据。需验证 + // 模板文件格式:烟箱编码/烟箱编码-模板编码 + // 模板编码:模板类型+模板编号 + // 模板类型:1为大模板(模板和匹配图均放缩50%),2为小模板 + // 例如:1类模板的第1个模板:11 + // 中华硬310102的2类模板的第1个模板:310102-21 QString folderPath = QString("%1\\%2").arg(templateImgFolderPath).arg(typeNo); if (getTemplateImgFileInfo(folderPath, templateObj)) { @@ -249,18 +256,26 @@ bool CategoryMatcher::getTemplateImgFileInfo(const QString& folderPath, Template || fileName.endsWith(".jpg") || fileName.endsWith(".JPG")) { QStringList strList = imgFileInfo.baseName().split("_"); - if (strList.first() == "template" && strList.length() == 3) - { - int scoreThresh = strList.last().toInt(); - QString templateImgPath = imgFileInfo.filePath(); //相对路径,避免路径存在中文时读取失败 - std::pair imgScorePair(templateImgPath, scoreThresh); - QString serialNum = strList[1]; - if (serialNum.length() == 4) - { - int level = serialNum.mid(0, 2).toInt(); - templateObject[level].insert(templateImgPath, scoreThresh); - } - } + + QString templateImgPath = imgFileInfo.filePath(); //相对路径,避免路径存在中文时读取失败 + int level = strList.last().mid(0, 1).toInt(); + templateObject[level].insert(templateImgPath, 70); + + + + ////之前的模板格式,例如:templateImg/51520312/template_0101_65 + //if (strList.first() == "template" && strList.length() == 3) + //{ + // int scoreThresh = strList.last().toInt(); + // QString templateImgPath = imgFileInfo.filePath(); //相对路径,避免路径存在中文时读取失败 + // std::pair imgScorePair(templateImgPath, scoreThresh); + // QString serialNum = strList[1]; + // if (serialNum.length() == 4) + // { + // int level = serialNum.mid(0, 2).toInt(); + // templateObject[level].insert(templateImgPath, scoreThresh); + // } + //} } } if (templateObject.isEmpty()) @@ -280,10 +295,39 @@ void CategoryMatcher::drawImage(ILImagePtr image, std::pair vecMatchRlts = templateLevelAndvecMatchRltPtr.second; + QString rltStr; + cv::Scalar textColor(0, 255, 0); + if (!vecMatchRlts.isEmpty() && (vecMatchRlts.length() == templateLevel)) + { + rltStr = QString("Match successful! Total level: %1").arg(templateLevel); + } + else + { + textColor = cv::Scalar(0, 0, 255); + rltStr = QString("Match failed! Total level: %1").arg(templateLevel); + } + //在Display上绘制图像+结果 + m_display->SetImage(image); + m_display->AddObject(rltStr,0); + + rltStr.clear(); + for each(ILMatchResultPtr matchRltPtr in vecMatchRlts) + { + // 存在问题:如果不存在1级模板,直接是2级模板 + double score = matchRltPtr->GetScore(); + rltStr.append(QString(" Level %1 score: %2").arg(level++).arg(score)); + //存在的问题——大模板的时候匹配的得到的结果是放缩后的结果,需要对位置进行扩大 + m_display->AddObject(matchRltPtr, LPVPatDrawFlags::LPVPatDrawBoundingRect | LPVPatDrawFlags::LPVPatDrawCenter); + } + if (!rltStr.isEmpty()) + { + m_display->AddObject(rltStr, 0); + } } void CategoryMatcher::saveResultsImage(const QString& filePath) diff --git a/src/CategoryMatcher.h b/src/CategoryMatcher.h index 883bc2d..4a3e37b 100644 --- a/src/CategoryMatcher.h +++ b/src/CategoryMatcher.h @@ -28,6 +28,7 @@ typedef QMap > TemplateObject; //> +// 目前匹配分数是固定的,但保留int字节,为后续扩展——例如:图像匹配放缩比等 struct MatchParam {