|
|
|
@ -39,7 +39,6 @@ ImgCheckAnalysisy::ImgCheckAnalysisy()
|
|
|
|
m_strLastDate = "";
|
|
|
|
m_strLastDate = "";
|
|
|
|
m_strRootPath_TA_cls = "/home/aidlux/BOE/Cls/TA/";
|
|
|
|
m_strRootPath_TA_cls = "/home/aidlux/BOE/Cls/TA/";
|
|
|
|
m_strRootPath_CA_cls = "/home/aidlux/BOE/Cls/CA/";
|
|
|
|
m_strRootPath_CA_cls = "/home/aidlux/BOE/Cls/CA/";
|
|
|
|
m_strRootPath_Det = "/home/aidlux/BOE/CELL_AOI/AI_RESULT/";
|
|
|
|
|
|
|
|
creatsavedir();
|
|
|
|
creatsavedir();
|
|
|
|
m_pImageStorage = ImageStorage::getInstance();
|
|
|
|
m_pImageStorage = ImageStorage::getInstance();
|
|
|
|
m_nConfigIdx = -1;
|
|
|
|
m_nConfigIdx = -1;
|
|
|
|
@ -1651,7 +1650,7 @@ int ImgCheckAnalysisy::ConfigCheck(cv::Mat img)
|
|
|
|
return re;
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ImgCheckAnalysisy::AI_Detect_Thread(const cv::Mat &img, cv::Mat &ResultImg, bool bPushBlobQueue)
|
|
|
|
int ImgCheckAnalysisy::AI_Detect_Thread(const cv::Mat &img, cv::Mat &ResultImg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::shared_ptr<AIModel_Base> pAIDet;
|
|
|
|
std::shared_ptr<AIModel_Base> pAIDet;
|
|
|
|
// printf("=====>>>>AI_Detect_Thread m_strCurDetChannel %s \n", m_strCurDetChannel.c_str());
|
|
|
|
// printf("=====>>>>AI_Detect_Thread m_strCurDetChannel %s \n", m_strCurDetChannel.c_str());
|
|
|
|
@ -1742,7 +1741,6 @@ int ImgCheckAnalysisy::AI_Detect_Thread(const cv::Mat &img, cv::Mat &ResultImg,
|
|
|
|
if (runner->PopResult(result))
|
|
|
|
if (runner->PopResult(result))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (bPushBlobQueue)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(mtx_AIMaskImgBLobQueue);
|
|
|
|
std::lock_guard<std::mutex> lock(mtx_AIMaskImgBLobQueue);
|
|
|
|
m_AIMaskImgBLobQueue.push(result);
|
|
|
|
m_AIMaskImgBLobQueue.push(result);
|
|
|
|
@ -2131,28 +2129,7 @@ void ImgCheckAnalysisy::TaskFun_AIDet(std::shared_ptr<TaskInfo> task)
|
|
|
|
int rec;
|
|
|
|
int rec;
|
|
|
|
if(m_pbaseCheckFunction->traditionDet.bOpen)
|
|
|
|
if(m_pbaseCheckFunction->traditionDet.bOpen)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 传统检测与 AI 检测并行执行;
|
|
|
|
|
|
|
|
// 最终 NG 结果只由传统检测决定,AI 检测结果仅用于记录与展示。
|
|
|
|
|
|
|
|
int recAI = 0;
|
|
|
|
|
|
|
|
std::thread aiThread([this, &recAI]()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
recAI = AI_Detect_Thread(m_pImageAllResult->detImg, m_pImageAllResult->AIDetMaskImg, false);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rec = Traditional_Detect_Thread(m_pImageAllResult->detImg, m_pImageAllResult->AIMaskImg);
|
|
|
|
rec = Traditional_Detect_Thread(m_pImageAllResult->detImg, m_pImageAllResult->AIMaskImg);
|
|
|
|
|
|
|
|
|
|
|
|
if (aiThread.joinable())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
aiThread.join();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, DET_LOG_LEVEL_3, "TaskFun_AIDet", "traditional rec %d, AI rec %d", rec, recAI);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存 AI 检测结果,用于模型优化(需在配置 Det_Image_Save 下开启 Det_Save)
|
|
|
|
|
|
|
|
if (m_pbaseCheckFunction->saveImg.bSaveDetImg)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SaveAIDetResult();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -2165,61 +2142,6 @@ void ImgCheckAnalysisy::TaskFun_AIDet(std::shared_ptr<TaskInfo> task)
|
|
|
|
task->SetStatus(TaskStep_compate);
|
|
|
|
task->SetStatus(TaskStep_compate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ImgCheckAnalysisy::SaveAIDetResult()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 保存 AI 检测结果,用于模型优化
|
|
|
|
|
|
|
|
std::string strProductID = DetImgInfo_shareP->strImgProductID;
|
|
|
|
|
|
|
|
if (strProductID.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strProductID = "Default";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string strChannelDir;
|
|
|
|
|
|
|
|
if (m_strCurDetChannel.find("TA") != std::string::npos)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strChannelDir = "TA";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
strChannelDir = "CA";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 目录结构:/home/aidlux/BOE/Det/<产品ID>/<TA|CA>/<日期>/
|
|
|
|
|
|
|
|
std::string strRoot = m_strRootPath_Det + strProductID + "/" + strChannelDir + "/" + CheckUtil::getCurrentDate() + "/";
|
|
|
|
|
|
|
|
CheckUtil::CreateDir(strRoot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string strBase = strRoot + m_strCurDetChannel + "_" + std::to_string(DetImgInfo_shareP->img_id) + "_" + std::to_string(CheckUtil::getcurTime());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1、保存整幅 AI mask 与 检测输入图
|
|
|
|
|
|
|
|
if (!m_pImageAllResult->AIDetMaskImg.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_pImageStorage->addImage(strBase + "_AI_mask.png", m_pImageAllResult->AIDetMaskImg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_pImageAllResult->detImg.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_pImageStorage->addImage(strBase + "_src.png", m_pImageAllResult->detImg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2、保存每个 AI 检出缺陷的小图(输入 + mask),只存有残点的 ROI
|
|
|
|
|
|
|
|
int nSaveIdx = 0;
|
|
|
|
|
|
|
|
for (auto &pAIMask : m_pImageAllResult->AI_Qx_MaskList)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!pAIMask || pAIMask->AI_mask.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cv::countNonZero(pAIMask->AI_mask) == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pImageStorage->addImage(strBase + "_" + std::to_string(nSaveIdx) + "_in.png", pAIMask->AI_inImg);
|
|
|
|
|
|
|
|
m_pImageStorage->addImage(strBase + "_" + std::to_string(nSaveIdx) + "_mask.png", pAIMask->AI_mask);
|
|
|
|
|
|
|
|
nSaveIdx++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, DET_LOG_LEVEL_3, "SaveAIDetResult", "save %d AI defect imgs to %s", nSaveIdx, strRoot.c_str());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ImgCheckAnalysisy::TaskFun_QxClass(std::shared_ptr<TaskInfo> task)
|
|
|
|
void ImgCheckAnalysisy::TaskFun_QxClass(std::shared_ptr<TaskInfo> task)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
task->SetStatus(TaskStep_run);
|
|
|
|
task->SetStatus(TaskStep_run);
|
|
|
|
|