增加测试逻辑

master
LAPTOP-S9HJSOEB\昊天 2 years ago
parent ea82b6708c
commit ae27a7760c

File diff suppressed because it is too large Load Diff

@ -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++)
{
@ -189,6 +206,9 @@ bool CategoryMatcher::smokeMatch(const QString& typeNo, const ILImagePtr ilImgPt
auto maxPos = std::max_element(matchSrore.begin(), matchSrore.end());
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;
}

@ -47,6 +47,7 @@ public:
CategoryMatcher(QObject *parent = nullptr);
~CategoryMatcher();
bool smokeMatch(const QString& typeNo, ILImagePtr image, int id);
bool smokeMatchTask(const QString& typeNo, int image);
void saveResultsImage(const QString& filePath);

@ -62,7 +62,7 @@ bool LXCamera::openCamera()
if (LX_SUCCESS == lx_state) {
break;
}
qDebug() << "TofCamera Open Failed重启次数="<<i<<"相机id"<< m_handle.c_str();;
qDebug() << "TofCamera Open Failed ="<<i<<"id£º"<< m_handle.c_str();;
lx_state = DcOpenDevice(LX_OPEN_MODE::OPEN_BY_SN, m_handle.c_str(), handlePtr, &device_info);
}
handle = *handlePtr;
@ -89,7 +89,12 @@ bool LXCamera::startCamera()
checkTC(DcGetBoolValue(handle, LX_BOOL_ENABLE_2D_STREAM, &test_rgb));
//开启数据流
checkTC(DcStartStream(handle));
for (int i = 0; i <= 5; i++) {
if (LX_SUCCESS == DcStartStream(handle)) {
checkTC(LX_SUCCESS);
break;
}
}
std::thread pthread = std::thread();
//pthread.detach();

@ -457,6 +457,23 @@ Q_SLOT void SmokeBoxIdentification::onDecodeMsg(const QString& msg)
m_stocketList.insert(m_currtStockCheckInfo.id.toInt(), m_currtStockCheckInfo);
calculate(m_currtStockCheckInfo.id.toInt());
}
else if (strList.at(0) == TAST_CALCULATE)
{
qDebug() << "品规计数开始";
//m_workMode = WorkMode::StockCheck;
bool i = m_pCategoryMatcher->smokeMatchTask(strList.at(1), strList.at(2).toInt());
QString resultInfoMsg;
resultInfoMsg.append(TAST_CALCULATE).append(SPLIT_RULE).append(i?"1":"0").append(END_SYMBOL);
sgSendMsg(resultInfoMsg);
}
}
}
break;

@ -56,6 +56,7 @@
#define END_SYMBOL ">"
#define START_CAPTURE "GPS" // 到位取图开始
#define END_CAPTURE "GPE" // 到位取图结束
#define TAST_CALCULATE "TAST" // 开始品规和数量计算
#define START_CALCULATE "RTS" // 开始品规和数量计算
#define RETURN_CALCULATE "RTE" // 品规计算结果返回

Loading…
Cancel
Save