Compare commits

...

3 Commits

@ -206,6 +206,17 @@ int AI_Edge_QX_Det::Detect(const cv::Mat &img, cv::Mat &detmask, DetConfig *pDet
continue;
}
if (bdege || nRuntype != 0)
{
std::string strSaveDir = "/home/aidlux/BOE/FOG/AI_Edge_Detect/";
CheckUtil::CreateDir(strSaveDir);
std::string roi_ext = "[" + std::to_string(r.x) + "," + std::to_string(r.y) + "]";
std::string strSavePath_in = strSaveDir + pDetConfig->strCamChannel + "_" + roi_ext + "_edge_in.png";
std::string strSavePath_out = strSaveDir + pDetConfig->strCamChannel + "_" + roi_ext + "_edge_out.png";
cv::imwrite(strSavePath_in, detimg);
cv::imwrite(strSavePath_out, outMask);
}
// 边缘检测存图
bool isAllZero = true;
if (cv::countNonZero(outMask) > 0)
{

@ -476,6 +476,8 @@ int ALLImgCheckAnalysisy::InitData()
int ALLImgCheckAnalysisy::Det_Product(std::shared_ptr<Product> &product)
{
string cur_times = CheckUtil::getCurTimeHMS();
printf("[%s]>>>>>>>>>>>>>>>Det_Product****************det Start************\n", cur_times.c_str());
// m_pQX_Merge_Analysis->InitData();
// 处理每个相机
while (true)
@ -505,7 +507,8 @@ int ALLImgCheckAnalysisy::Det_Product(std::shared_ptr<Product> &product)
// AnalysiyAll(0);
MergeShowImg(product);
SetProductResult(product);
// printf(">>>>>>>>>>>>>>>Det_Product****************det End************\n");
string cur_timee = CheckUtil::getCurTimeHMS();
printf("[%s]>>>>>>>>>>>>>>>Det_Product****************det End************\n", cur_timee.c_str());
return 0;
}

@ -2835,6 +2835,24 @@ int ImgCheckAnalysisy::AI_Detect_QX()
pDetAIResult->blobDetParam->AIMaskImgBLobQueue.push(temAIresult);
}
}
// AI检测残点图存图
if (DetImgInfo_shareP->bDebugsaveImg)
{
bool bNeedSave = false;
std::string roi_ext = "[" + std::to_string(result->roi.x) + "," + std::to_string(result->roi.y) + "]";
bNeedSave = true;
if (bNeedSave && !AIresult.empty())
{
std::string strSaveDir = "/home/aidlux/BOE/FOG/AI_Detect/" + DetImgInfo_shareP->strImgProductID + "/";
CheckUtil::CreateDir(strSaveDir);
std::string strSavePath_in = strSaveDir + m_strCurDetChannel +"_"+ roi_ext + "_"+ "in" + ".png";
std::string strSavePath_out = strSaveDir + m_strCurDetChannel +"_"+ roi_ext + "_"+ "out" + ".png";
cv::imwrite(strSavePath_in, result->input);
cv::imwrite(strSavePath_out, AIresult);
}
}
}
completed++;
}
@ -2845,7 +2863,9 @@ int ImgCheckAnalysisy::AI_Detect_QX()
}
te = CheckUtil::getcurTime();
float mean_AI = (te - t2) / SmallRoiList.size();
m_pdetlog->bPrintStr = true;
m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "============= End; AI Run Time: sum %ld pre %ld Run %ld mean One Small Img %f", te - ts, t2 - ts, te - t2, mean_AI);
m_pdetlog->bPrintStr = false;
// 临时存图
if (DetImgInfo_shareP->bDebugsaveImg)

@ -197,6 +197,10 @@ deal::deal()
m_nProductReadThreadNum = READ_PRODUCT_THREAD_NUM;
m_nProductQueueMaxSize = PRODUCT_QUEUE_MAX_SIZE;
m_nCheckNotifiedCount = 0;
// ✅ 图片尺寸一致性保护
m_nExpectedImgWidth = -1;
m_nExpectedImgHeight = -1;
}
deal::~deal()
@ -1486,6 +1490,10 @@ int deal::CheckProduct(const LoadProductImages &product)
m_ProductFailedList.clear();
m_nCheckNotifiedCount = 0;
// ✅ 重置图片期望尺寸(每个产品批次独立)
m_nExpectedImgWidth = -1;
m_nExpectedImgHeight = -1;
// ✅ 修复内存泄漏清理上一个产品累积的原始图像数据cv::Mat
// 注意m_DetResult 是统计结果(轻量字符串/数字),不清除,跨产品累积
m_ImageInfoList.clear();
@ -1667,6 +1675,42 @@ int deal::SendCheckImg(const CheckImgNotifyInfo &info, IN_IMG_Status_ status, bo
m_nProductSuccessCount.fetch_add(1);
// ✅ 图片尺寸一致性保护:获取当前图片的有效图像
cv::Mat curImg;
if (!info.left_img.empty())
{
curImg = info.left_img;
}
else if (!info.right_img.empty())
{
curImg = info.right_img;
}
if (!curImg.empty())
{
// 首次设置期望尺寸
if (m_nExpectedImgWidth < 0 || m_nExpectedImgHeight < 0)
{
m_nExpectedImgWidth = curImg.cols;
m_nExpectedImgHeight = curImg.rows;
printf("[尺寸基准] 产品 %s 首张图片尺寸: %dx%d (channel: %s)\n",
info.productId.c_str(), m_nExpectedImgWidth, m_nExpectedImgHeight,
info.channelName.c_str());
}
// 尺寸不一致时resize 到期望尺寸
else if (curImg.cols != m_nExpectedImgWidth || curImg.rows != m_nExpectedImgHeight)
{
printf("[尺寸修正] 产品 %s 图片尺寸不一致: 期望 %dx%d, 实际 %dx%d (channel: %s)正在resize...\n",
info.productId.c_str(),
m_nExpectedImgWidth, m_nExpectedImgHeight,
curImg.cols, curImg.rows,
info.channelName.c_str());
cv::Mat resizedImg;
cv::resize(curImg, resizedImg, cv::Size(m_nExpectedImgWidth, m_nExpectedImgHeight));
curImg = resizedImg;
}
}
std::shared_ptr<shareImage> tem = std::make_shared<shareImage>();
tem->strChannel = info.channelName;
@ -1701,13 +1745,9 @@ int deal::SendCheckImg(const CheckImgNotifyInfo &info, IN_IMG_Status_ status, bo
{
if (!info.left_img.empty())
{
tem->img = info.left_img;
}
else if (!info.right_img.empty())
if (!curImg.empty())
{
tem->img = info.right_img;
tem->img = curImg;
}
}

@ -803,6 +803,10 @@ public:
std::condition_variable m_productResultCV; // 产品结果保存通知CV每次save后notify
std::set<std::string> m_productIdList; // 产品ID列表
// ============ 图片尺寸一致性保护 ============
int m_nExpectedImgWidth; // 当前产品批次期望的图片宽度(-1 表示未设置)
int m_nExpectedImgHeight; // 当前产品批次期望的图片高度(-1 表示未设置)
};
#endif //_CORELOGICFACTORY_HPP_
Loading…
Cancel
Save