feat density计算

dev_lsy
liusiyang 6 days ago
parent 4c36c7534c
commit 8c5bcd7c9f

@ -73,6 +73,9 @@ public:
// 获取检测库 状态信息 返回CHECK_THREAD_RUN_STATUS // 获取检测库 状态信息 返回CHECK_THREAD_RUN_STATUS
int GetStatus(); int GetStatus();
// 计算blob的密度
int CalBlobDensity_QX();
// 更新参数 pconfig 参数指针nConfigType 需要更新的参数类型 返回0 成功 其他异常 // 更新参数 pconfig 参数指针nConfigType 需要更新的参数类型 返回0 成功 其他异常
int UpdateConfig(void *pconfig, int nConfigType); int UpdateConfig(void *pconfig, int nConfigType);

@ -170,7 +170,7 @@ int ImgCheckAnalysisy::GetStatus()
std::string ImgCheckAnalysisy::GetVersion() std::string ImgCheckAnalysisy::GetVersion()
{ {
return std::string("BOE_1.2.3_" + std::string(__DATE__) + "_" + std::string(__TIME__)); return std::string("BOE_1.2.4_" + std::string(__DATE__) + "_" + std::string(__TIME__));
} }
std::string ImgCheckAnalysisy::GetErrorInfo() std::string ImgCheckAnalysisy::GetErrorInfo()
@ -1449,6 +1449,9 @@ int ImgCheckAnalysisy::GetCheckResultBLob()
BLobToDetResult(); BLobToDetResult();
// 计算缺陷密度
CalBlobDensity_QX();
return 0; return 0;
} }
@ -4438,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)); 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; 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;
}

Loading…
Cancel
Save