|
|
|
|
@ -91,6 +91,21 @@ bool CategoryMatcher::smokeMatch(const QString& typeNo, ILImagePtr image, int id
|
|
|
|
|
return bRlt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CategoryMatcher::smokeMatchTask(const QString& typeNo,int del) {
|
|
|
|
|
|
|
|
|
|
ILImagePtr image(__uuidof(LImage));
|
|
|
|
|
|
|
|
|
|
std::string str;
|
|
|
|
|
str.append("./task/");
|
|
|
|
|
str.append(std::to_string(del));
|
|
|
|
|
str.append(".PNG");
|
|
|
|
|
image->Load(str.c_str());
|
|
|
|
|
|
|
|
|
|
QMap<int, ILMatchResultPtr> resultsPair;
|
|
|
|
|
bool bRlt = smokeMatch(typeNo, image, resultsPair, 0);
|
|
|
|
|
return bRlt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CategoryMatcher::smokeMatch(const QString& typeNo, const ILImagePtr ilImgPtr,
|
|
|
|
|
QMap<int, ILMatchResultPtr>& resultsMap, int id)
|
|
|
|
|
{
|
|
|
|
|
@ -166,7 +181,6 @@ bool CategoryMatcher::smokeMatch(const QString& typeNo, const ILImagePtr ilImgPt
|
|
|
|
|
qDebug() << str;
|
|
|
|
|
continue; // match failed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int objCount = matchResults->Count() + matchResultsF->Count();
|
|
|
|
|
if (objCount > 0)
|
|
|
|
|
{
|
|
|
|
|
@ -175,6 +189,9 @@ bool CategoryMatcher::smokeMatch(const QString& typeNo, const ILImagePtr ilImgPt
|
|
|
|
|
int indexMaxScore = 0;
|
|
|
|
|
QVector<double> matchSrore;
|
|
|
|
|
|
|
|
|
|
str = QString("[%1]:Match success;templateImgPath = %2").arg(id).arg(templateImgPath);
|
|
|
|
|
qDebug() << str;
|
|
|
|
|
|
|
|
|
|
// 模板方向的匹配结果——旋转180度匹配结果,组成一个完整的匹配结果值
|
|
|
|
|
for (int i = 0; i < matchResults->Count(); i++)
|
|
|
|
|
{
|
|
|
|
|
@ -190,6 +207,9 @@ bool CategoryMatcher::smokeMatch(const QString& typeNo, const ILImagePtr ilImgPt
|
|
|
|
|
valueMaxScore = *maxPos;
|
|
|
|
|
indexMaxScore = maxPos - matchSrore.begin();
|
|
|
|
|
|
|
|
|
|
str = QString("[%1]:Level: %1 match failed!").arg(id).arg(level);
|
|
|
|
|
qDebug() << str;
|
|
|
|
|
|
|
|
|
|
vecMatchSrore.push_back(valueMaxScore);
|
|
|
|
|
if (indexMaxScore < matchResults->Count())
|
|
|
|
|
{
|
|
|
|
|
@ -199,6 +219,11 @@ bool CategoryMatcher::smokeMatch(const QString& typeNo, const ILImagePtr ilImgPt
|
|
|
|
|
{
|
|
|
|
|
vecMatchRlts.push_back(matchResultsF->Item(indexMaxScore - matchResults->Count()));
|
|
|
|
|
}
|
|
|
|
|
} {
|
|
|
|
|
|
|
|
|
|
str = QString("[%1]:Match failed;templateImgPath = %2").arg(id).arg(templateImgPath);
|
|
|
|
|
qDebug() << str;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -227,56 +252,56 @@ bool CategoryMatcher::smokeMatch(const QString& typeNo, const ILImagePtr ilImgPt
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 此函数用于从给定的文件夹中获取模板图像文件信息,并将信息填充到TemplateObject结构体中
|
|
|
|
|
// 如果文件夹不存在或没有找到任何匹配的图像文件,函数返回false
|
|
|
|
|
// 否则,返回true
|
|
|
|
|
bool CategoryMatcher::getTemplateImgFileInfo(const QString& folderPath, TemplateObject& templateObject)
|
|
|
|
|
{
|
|
|
|
|
// 清空输入的TemplateObject
|
|
|
|
|
templateObject.clear();
|
|
|
|
|
|
|
|
|
|
// 创建QDir对象,检查文件夹是否存在
|
|
|
|
|
QDir fileDir(folderPath);
|
|
|
|
|
if (!fileDir.exists())
|
|
|
|
|
{
|
|
|
|
|
// 输出警告并返回false,因为文件夹不存在
|
|
|
|
|
qWarning() << folderPath << " is not exist";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
for each(QFileInfo imgFileInfo in fileDir.entryInfoList(QDir::Filter::Files | QDir::NoDotAndDotDot))
|
|
|
|
|
|
|
|
|
|
// 遍历文件夹中的所有文件,过滤掉"."和".."以及非图像文件
|
|
|
|
|
foreach(QFileInfo imgFileInfo, fileDir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot))
|
|
|
|
|
{
|
|
|
|
|
QString fileName = imgFileInfo.fileName();
|
|
|
|
|
|
|
|
|
|
// 检查文件名是否以特定图像扩展名结尾
|
|
|
|
|
if (fileName.endsWith(".png") || fileName.endsWith(".PNG")
|
|
|
|
|
|| fileName.endsWith(".BMP") || fileName.endsWith(".bmp")
|
|
|
|
|
|| fileName.endsWith(".jpeg") || fileName.endsWith(".JPEG")
|
|
|
|
|
|| fileName.endsWith(".jpg") || fileName.endsWith(".JPG"))
|
|
|
|
|
{
|
|
|
|
|
// 分割文件名,获取基名部分
|
|
|
|
|
QStringList strList = imgFileInfo.baseName().split("-");
|
|
|
|
|
|
|
|
|
|
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<QString, int> imgScorePair(templateImgPath, scoreThresh);
|
|
|
|
|
// QString serialNum = strList[1];
|
|
|
|
|
// if (serialNum.length() == 4)
|
|
|
|
|
// {
|
|
|
|
|
// int level = serialNum.mid(0, 2).toInt();
|
|
|
|
|
// templateObject[level].insert(templateImgPath, scoreThresh);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
// 将文件路径(相对路径)和其对应的级别添加到TemplateObject中
|
|
|
|
|
templateObject[level].insert(imgFileInfo.filePath(), 70);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果TemplateObject仍然为空,说明没有找到匹配的图像文件,返回false
|
|
|
|
|
if (templateObject.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 找到了至少一个匹配的图像文件,返回true
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CategoryMatcher::drawImage(ILImagePtr image, QMap<int, ILMatchResultPtr> resultsMap)
|
|
|
|
|
{
|
|
|
|
|
if (image->Void())
|
|
|
|
|
@ -296,6 +321,8 @@ void CategoryMatcher::drawImage(ILImagePtr image, QMap<int, ILMatchResultPtr> re
|
|
|
|
|
ILMatchResultPtr matchRlt = iter.value();
|
|
|
|
|
if (matchRlt == nullptr)
|
|
|
|
|
{
|
|
|
|
|
bRlt = false;
|
|
|
|
|
rltStr.append(QString("\n Level %1 score: %2").arg(iter.key()).arg("null"));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|