|
|
|
|
@ -170,7 +170,7 @@ int ImgCheckAnalysisy::GetStatus()
|
|
|
|
|
|
|
|
|
|
std::string ImgCheckAnalysisy::GetVersion()
|
|
|
|
|
{
|
|
|
|
|
return std::string("BOE_1.2.0");
|
|
|
|
|
return std::string("BOE_1.2.4_" + std::string(__DATE__) + "_" + std::string(__TIME__));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string ImgCheckAnalysisy::GetErrorInfo()
|
|
|
|
|
@ -332,7 +332,7 @@ cv::Scalar ImgCheckAnalysisy::calc_blob_info_withstats(cv::Mat &img, const cv::M
|
|
|
|
|
|
|
|
|
|
// 计算 hj(差异图像大于0的像素均值)
|
|
|
|
|
// double hj = std::abs(fbk - fdet);
|
|
|
|
|
double hj = CheckUtil::CalHj(cimg, cmask, mean_bk.val[0]);
|
|
|
|
|
double hj = CheckUtil::CalHjWeighted(cimg, cmask, fbk, 2.0f);
|
|
|
|
|
|
|
|
|
|
int worb = 0;
|
|
|
|
|
if (fdet >= fbk)
|
|
|
|
|
@ -381,7 +381,7 @@ double ImgCheckAnalysisy::CalBlobHJ(cv::Mat &img, const cv::Mat &mask, cv::Rect
|
|
|
|
|
|
|
|
|
|
// 计算 hj(差异图像大于0的像素均值)
|
|
|
|
|
// double hj = std::abs(fbk - fdet);
|
|
|
|
|
double hj = CheckUtil::CalHj(cimg, cmask, fbk);
|
|
|
|
|
double hj = CheckUtil::CalHjWeighted(cimg, cmask, fbk, 2.0f);
|
|
|
|
|
static int kkk = 0;
|
|
|
|
|
|
|
|
|
|
unsigned char *pErrordata = (unsigned char *)cimg.data;
|
|
|
|
|
@ -589,6 +589,7 @@ int ImgCheckAnalysisy::SetNewConfig()
|
|
|
|
|
m_pRegionAnalysisyParam = &m_pCommonAnalysisyConfig->regionConfigArr.at(0);
|
|
|
|
|
GetParamidx();
|
|
|
|
|
UpdateImgageScale();
|
|
|
|
|
UPdateLDConfig();
|
|
|
|
|
if (true)
|
|
|
|
|
{
|
|
|
|
|
printf("SetNewConfig m_nConfigIdx %d m_CheckConfig.strSkuName %s \n", m_nConfigIdx, m_AnalysisyConfig.strSkuName.c_str());
|
|
|
|
|
@ -1448,6 +1449,9 @@ int ImgCheckAnalysisy::GetCheckResultBLob()
|
|
|
|
|
|
|
|
|
|
BLobToDetResult();
|
|
|
|
|
|
|
|
|
|
// 计算缺陷密度
|
|
|
|
|
CalBlobDensity_QX();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -2482,6 +2486,11 @@ int ImgCheckAnalysisy::AI_Detect_QX()
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, strBaseLog, "=======model use Chess");
|
|
|
|
|
pAI_Model = AI_Factory->AI_defect_Chess;
|
|
|
|
|
}
|
|
|
|
|
else if (m_pFuntion->function.f_BaseDet.strAIMode == "RGB-HGRAY")
|
|
|
|
|
{
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, strBaseLog, "=======model use RE_RGBHGRAY");
|
|
|
|
|
pAI_Model = AI_Factory->AI_defect_RE_RGBHGRAY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, strBaseLog, "=======model use base");
|
|
|
|
|
@ -3356,17 +3365,17 @@ int ImgCheckAnalysisy::BLobToDetResult()
|
|
|
|
|
config_qx_type == CONFIG_QX_NAME_Other ||
|
|
|
|
|
config_qx_type == CONFIG_QX_NAME_LD)
|
|
|
|
|
{
|
|
|
|
|
std::string qx_name = CONFIG_QX_NAME_Names[config_qx_type];
|
|
|
|
|
qx_name = CONFIG_QX_NAME_Names[config_qx_type];
|
|
|
|
|
// m_TemCheck.AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "LD", "stsrt config_qx_type %s ", qx_name.c_str());
|
|
|
|
|
int dbresult = LDJudge(config_qx_type, roi, JudgArea, blobs.blobTab[i].maxValue, blobs.blobTab[i].grayDis, pQxlog);
|
|
|
|
|
int detre = 1;
|
|
|
|
|
//int detre = 1;
|
|
|
|
|
// 表示L0 和 DP 都有的 亮的
|
|
|
|
|
if (dbresult == 1)
|
|
|
|
|
{
|
|
|
|
|
config_qx_type = CONFIG_QX_NAME_LD;
|
|
|
|
|
qx_name = CONFIG_QX_NAME_Names[config_qx_type];
|
|
|
|
|
}
|
|
|
|
|
pQxlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, " LD Judge ", "%s qx %s ", Re_TO_STR_False(detre), qx_name.c_str());
|
|
|
|
|
pQxlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, " LD Judge ", "%s qx %s ", Re_TO_STR_Pass_1(dbresult), qx_name.c_str());
|
|
|
|
|
}
|
|
|
|
|
// 如果是chess 画面,缺陷类型直接是chess异常。
|
|
|
|
|
if (m_pFuntion->function.f_AIQX.bAllToChess)
|
|
|
|
|
@ -3450,7 +3459,7 @@ int ImgCheckAnalysisy::BLobToDetResult()
|
|
|
|
|
bool ban = JudgeQXAnalysis(config_qx_type, pQxlog);
|
|
|
|
|
if (!ban)
|
|
|
|
|
{
|
|
|
|
|
std::string qx_name = CONFIG_QX_NAME_Names[config_qx_type];
|
|
|
|
|
qx_name = CONFIG_QX_NAME_Names[config_qx_type];
|
|
|
|
|
pQxlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, "Judge QX", "qx function close, config_qx_type %s Not Det",
|
|
|
|
|
qx_name.c_str());
|
|
|
|
|
|
|
|
|
|
@ -3467,7 +3476,7 @@ int ImgCheckAnalysisy::BLobToDetResult()
|
|
|
|
|
isMarksheildQX = Judge_MarkLine_QX(config_qx_type, roi, pQxlog);
|
|
|
|
|
if (isMarksheildQX)
|
|
|
|
|
{
|
|
|
|
|
std::string qx_name = CONFIG_QX_NAME_Names[config_qx_type];
|
|
|
|
|
qx_name = CONFIG_QX_NAME_Names[config_qx_type];
|
|
|
|
|
pQxlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, "MarkLine_QX", "MarkLine_QX close, config_qx_type %s Not Det",
|
|
|
|
|
qx_name.c_str());
|
|
|
|
|
|
|
|
|
|
@ -4432,4 +4441,105 @@ bool ImgCheckAnalysisy::JudgeQXAnalysis(int nqx_configType, std::shared_ptr<DetL
|
|
|
|
|
pQxlog->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "Judge QX ", "det qx %s -> Funtion qx %s open = %s ", qx_name.c_str(), det_qx.c_str(), BOOL_TO_STR(re));
|
|
|
|
|
|
|
|
|
|
return re;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ImgCheckAnalysisy::CalBlobDensity_QX()
|
|
|
|
|
{
|
|
|
|
|
float fs_x = m_fImgage_Scale_X;
|
|
|
|
|
float fs_y = m_fImgage_Scale_Y;
|
|
|
|
|
double dis_T = m_pBasicConfig->density_R_mm;
|
|
|
|
|
if (dis_T <= 0 || dis_T > 99999)
|
|
|
|
|
{
|
|
|
|
|
dis_T = 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_pDetResult || !m_pDetResult->pQx_ErrorList || m_pDetResult->pQx_ErrorList->size() <= 0)
|
|
|
|
|
{
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_1, "Density_QX", "pQx_ErrorList is empty, skip density calc");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_1, "Density_QX", "Start: dis_T=%.1fmm qx_count=%zu", dis_T, m_pDetResult->pQx_ErrorList->size());
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_pDetResult->pQx_ErrorList->size(); i++)
|
|
|
|
|
{
|
|
|
|
|
m_pDetResult->pQx_ErrorList->at(i).density = 1;
|
|
|
|
|
|
|
|
|
|
if (m_pDetResult->pQx_ErrorList->at(i).nconfig_qx_type == CONFIG_QX_NAME_MTX ||
|
|
|
|
|
m_pDetResult->pQx_ErrorList->at(i).nconfig_qx_type == CONFIG_QX_NAME_POL_Cell ||
|
|
|
|
|
m_pDetResult->pQx_ErrorList->at(i).nconfig_qx_type == CONFIG_QX_NAME_LD ||
|
|
|
|
|
m_pDetResult->pQx_ErrorList->at(i).nconfig_qx_type == CONFIG_QX_NAME_AD)
|
|
|
|
|
{
|
|
|
|
|
/* code */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::Rect roi = m_pDetResult->pQx_ErrorList->at(i).roi;
|
|
|
|
|
|
|
|
|
|
cv::Point p;
|
|
|
|
|
p.x = roi.x + roi.width * 0.5;
|
|
|
|
|
p.y = roi.y + roi.height * 0.5;
|
|
|
|
|
|
|
|
|
|
int num = 1;
|
|
|
|
|
double sum_dis = 0;
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < m_pDetResult->pQx_ErrorList->size(); j++)
|
|
|
|
|
{
|
|
|
|
|
if (i == j)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (m_pDetResult->pQx_ErrorList->at(j).nconfig_qx_type == CONFIG_QX_NAME_MTX ||
|
|
|
|
|
m_pDetResult->pQx_ErrorList->at(j).nconfig_qx_type == CONFIG_QX_NAME_POL_Cell ||
|
|
|
|
|
m_pDetResult->pQx_ErrorList->at(j).nconfig_qx_type == CONFIG_QX_NAME_LD ||
|
|
|
|
|
m_pDetResult->pQx_ErrorList->at(j).nconfig_qx_type == CONFIG_QX_NAME_AD)
|
|
|
|
|
{
|
|
|
|
|
/* code */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
cv::Rect roi123 = m_pDetResult->pQx_ErrorList->at(j).roi;
|
|
|
|
|
|
|
|
|
|
cv::Point p123;
|
|
|
|
|
p123.x = roi123.x + roi123.width * 0.5;
|
|
|
|
|
p123.y = roi123.y + roi123.height * 0.5;
|
|
|
|
|
|
|
|
|
|
double dis_x = std::abs(p123.x - p.x) * fs_x;
|
|
|
|
|
double dis_y = std::abs(p123.y - p.y) * fs_y;
|
|
|
|
|
double dis = std::sqrt(dis_x * dis_x + dis_y * dis_y);
|
|
|
|
|
if (dis > dis_T)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
num++;
|
|
|
|
|
sum_dis += dis;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float avdis = dis_T;
|
|
|
|
|
if (num > 1)
|
|
|
|
|
{
|
|
|
|
|
avdis = sum_dis / (num - 1);
|
|
|
|
|
}
|
|
|
|
|
float fScore = (dis_T - avdis) / dis_T;
|
|
|
|
|
|
|
|
|
|
double fD = num + fScore;
|
|
|
|
|
m_pDetResult->pQx_ErrorList->at(i).density = fD;
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_2, "Density_QX", " idx=%d type=%d(%s) roi[%d,%d,%d,%d] near_num=%d avgDis=%.2f score=%.3f density=%.2f",
|
|
|
|
|
i,
|
|
|
|
|
m_pDetResult->pQx_ErrorList->at(i).nconfig_qx_type,
|
|
|
|
|
m_pDetResult->pQx_ErrorList->at(i).qx_name.c_str(),
|
|
|
|
|
roi.x, roi.y, roi.width, roi.height,
|
|
|
|
|
num, avdis, fScore, fD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_1, "Density_QX", "End: processed %zu defects", m_pDetResult->pQx_ErrorList->size());
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|