diff --git a/AIEngineModule/include_base/AI_Factory.h b/AIEngineModule/include_base/AI_Factory.h index 9ac9243..5ee4d77 100644 --- a/AIEngineModule/include_base/AI_Factory.h +++ b/AIEngineModule/include_base/AI_Factory.h @@ -192,6 +192,8 @@ public: std::shared_ptr AI_defect_MarkLine; // 缺pol检测 std::shared_ptr AI_defect_Edge_QX; // 边缘缺陷检测 + std::shared_ptr AI_defect_RLine_512; // 弱线检测模型 512*512 + private: // 模型是否都加载完成了。 bool m_bInitSucc = false; diff --git a/AIEngineModule/src/AI_Factory.cpp b/AIEngineModule/src/AI_Factory.cpp index f1da06f..ffe814c 100644 --- a/AIEngineModule/src/AI_Factory.cpp +++ b/AIEngineModule/src/AI_Factory.cpp @@ -264,6 +264,17 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig) boe_config.inputType = AIModel_Base::Input_CHW; boe_config.strName = "Edge_QX"; AI_defect_Edge_QX->Init(boe_config); + } + // 弱线检测模型 512*512 + if (!AI_defect_RLine_512) + { + AI_defect_RLine_512 = AIModel_Base::GetInstance(); + AIModel_Base::AIModelRun_Config boe_config; + boe_config.gpuconfig.copy(gupconfig); + boe_config.strPath = "/home/aidlux/BOE/UseModel_FOG/FOG_L127line.engine"; + boe_config.strName = "RLine_512"; + boe_config.inputType = AIModel_Base::Input_CHW; + AI_defect_RLine_512->Init(boe_config); } m_bInitSucc = true; return 0; diff --git a/AlgorithmModule/include/ImageAllResult.h b/AlgorithmModule/include/ImageAllResult.h index 8e89f97..da831b6 100644 --- a/AlgorithmModule/include/ImageAllResult.h +++ b/AlgorithmModule/include/ImageAllResult.h @@ -45,9 +45,9 @@ public: }; struct Config_Update { - bool bUpdate = false; - bool wait_DP= false; - bool wait_UP= false; + bool bUpdate = false; + bool wait_DP = false; + bool wait_UP = false; }; // AI MaskImg 的相关使用的参数信息。 @@ -174,6 +174,7 @@ public: std::shared_ptr qx_DetAIResult; // BLob 检测要用到的一些 参数 。 std::shared_ptr cell127_DetAIResult; // 127 cell 检测要用到的一些 参数 。 std::shared_ptr bq_DetAIResult; // BQ标签检测要用到的一些 参数 。 + std::shared_ptr RLine_512_DetAIResult; // 弱线512模型 检测要用到的一些 参数 。 // 结果图片 cv::Mat resultImg; @@ -205,7 +206,6 @@ public: Config_Update config_update; - public: DetStep m_step = DetStep_NotDet; std::string strBaseInfo = ""; diff --git a/AlgorithmModule/include/ImgCheckAnalysisy.hpp b/AlgorithmModule/include/ImgCheckAnalysisy.hpp index fc4ff95..874f9c9 100644 --- a/AlgorithmModule/include/ImgCheckAnalysisy.hpp +++ b/AlgorithmModule/include/ImgCheckAnalysisy.hpp @@ -193,7 +193,8 @@ private: int GetBlob_QX(); // 获得 127cell blob int GetBlob_127cell(); - + // 获得 RLine_512 blob + int GetBlob_RLine_512(); // 获得 BQ标签 blob int GetBlob_BQ(); @@ -220,6 +221,8 @@ private: int AI_Detect_QX(); // 127cell int AI_Detect_127Cell(); + // 弱线检测-512模型 + int AI_Detect_RLine_512(); // 缺陷分类 int AI_QX_Class_Thread(); @@ -240,7 +243,7 @@ private: // 更新 检测区域 int Update_DetRoiList(); - // 边缘检测 + // 边缘检测 int Edge_Det(); // 临时绘制结果 diff --git a/AlgorithmModule/src/ImageResultJudge.cpp b/AlgorithmModule/src/ImageResultJudge.cpp index cc3ae72..18a0ced 100644 --- a/AlgorithmModule/src/ImageResultJudge.cpp +++ b/AlgorithmModule/src/ImageResultJudge.cpp @@ -387,9 +387,9 @@ int ImageResultJudge::ResultJudge(std::shared_ptr pImageResult) BOOL_TO_STR(flen >= Len), flen, BOOL_TO_ThanLess(flen > Len), Len); } - if( config_qx_type == CONFIG_QX_NAME_POL_Cell && area_max > 0) + if (config_qx_type == CONFIG_QX_NAME_POL_Cell && area_max > 0) { - if(detArea > area_max) + if (detArea > area_max) { nerrortype = 0; result = true; @@ -397,7 +397,7 @@ int ImageResultJudge::ResultJudge(std::shared_ptr pImageResult) bYS_Status = false; } pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, "PolCell_Area_Max", "%s -> %f %s %f ", - BOOL_TO_STR(detArea > area_max), detArea, BOOL_TO_ThanLess(detArea > area_max), area_max); + BOOL_TO_STR(detArea > area_max), detArea, BOOL_TO_ThanLess(detArea > area_max), area_max); } // AD根据配置检测:未配置通道的AD缺陷不判NG if (config_qx_type == CONFIG_QX_NAME_AD && m_pbaseCheckFunction && ict == ANALYSIS_TYPE_TF && @@ -453,7 +453,7 @@ int ImageResultJudge::ResultJudge(std::shared_ptr pImageResult) m_pbaseCheckFunction->ad_check.analysis_s.NG_3s && bpreSucc) { bool b3sChannel = false; - if(std::find(m_pbaseCheckFunction->ad_check.analysis_sf.s_sf.begin(), m_pbaseCheckFunction->ad_check.analysis_sf.s_sf.end(), strChannel) != m_pbaseCheckFunction->ad_check.analysis_sf.s_sf.end()) + if (std::find(m_pbaseCheckFunction->ad_check.analysis_sf.s_sf.begin(), m_pbaseCheckFunction->ad_check.analysis_sf.s_sf.end(), strChannel) != m_pbaseCheckFunction->ad_check.analysis_sf.s_sf.end()) { b3sChannel = true; } @@ -610,7 +610,7 @@ int ImageResultJudge::ResultJudge(std::shared_ptr pImageResult) // CheckUtil::printROI(CutRoi, "CutRoi"); cv::Size sz = cv::Size(QX_SAMLLIMG_WIDTH, QX_SAMLLIMG_HEIGHT); - #ifdef SAVE_RESIMG +#ifdef SAVE_RESIMG if (pImageResult->detImg.channels() == 1) { cv::cvtColor(pImageResult->detImg(CutRoi), tem.srcImg, cv::COLOR_GRAY2BGR); @@ -620,7 +620,7 @@ int ImageResultJudge::ResultJudge(std::shared_ptr pImageResult) tem.srcImg = pImageResult->detImg(CutRoi).clone(); } cv::resize(tem.srcImg, tem.resizeImg, sz); - #endif +#endif int nqx_type = ConfigTypeToResultType(config_qx_type); tem.type = nqx_type; @@ -665,9 +665,9 @@ int ImageResultJudge::ResultJudge(std::shared_ptr pImageResult) m_CheckResult_shareP->nresult = nqx_type; } - #ifdef SAVE_RESIMG +#ifdef SAVE_RESIMG GetAIDetImg(pImageResult, pCenter, tem.AI_in_Img, tem.AI_out_img); - #endif +#endif m_CheckResult_shareP->qxImageResult.push_back(tem); } else @@ -678,15 +678,14 @@ int ImageResultJudge::ResultJudge(std::shared_ptr pImageResult) m_CheckResult_shareP->nYS_result = nqx_type; } - #ifdef SAVE_RESIMG +#ifdef SAVE_RESIMG GetAIDetImg(pImageResult, pCenter, tem.AI_in_Img, tem.AI_out_img); - #endif +#endif m_CheckResult_shareP->YS_ImageResult.push_back(tem); } - - pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, " result ", " name %s ---code %s", tem.strTypeName.c_str(), tem.qx_Code.c_str()); + pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, " result ", " name %s ---code %s", tem.strTypeName.c_str(), tem.qx_Code.c_str()); } // 对于大面积 的zara和 异显NG ,可以不接着分析后续的数据了。应为后续估计有很多错误类别。 @@ -909,9 +908,9 @@ int ImageResultJudge::FilterCorrelatedDirtyNG(std::shared_ptr pI if (m_pQX_Merge_Analysis->m_pMergedetlog) { m_pQX_Merge_Analysis->m_pMergedetlog->AddCheckstr(PrintLevel_1, 3, "DirtyCorrelatedFilter", - "img %s cam %s blob %d qx %s roi %s : 关联通道存在重叠的过滤源缺陷, 过滤该暗点NG", - pImageResult->strChannel.c_str(), pImageResult->cameraBaseResult->strCameraName.c_str(), - qxidx, QX_info->qx_name.c_str(), CheckUtil::GetRectString(product_roi).c_str()); + "img %s cam %s blob %d qx %s roi %s : 关联通道存在重叠的过滤源缺陷, 过滤该暗点NG", + pImageResult->strChannel.c_str(), pImageResult->cameraBaseResult->strCameraName.c_str(), + qxidx, QX_info->qx_name.c_str(), CheckUtil::GetRectString(product_roi).c_str()); } } @@ -988,7 +987,7 @@ int ImageResultJudge::MergeResult(std::shared_ptr pImageResult, cv::Rect CutRoi = GetCutRoi(roi, pImageResult->detImg); cv::Size sz = cv::Size(QX_SAMLLIMG_WIDTH, QX_SAMLLIMG_HEIGHT); - #ifdef SAVE_RESIMG +#ifdef SAVE_RESIMG if (pImageResult->detImg.channels() == 1) { cv::cvtColor(pImageResult->detImg(CutRoi), tem.srcImg, cv::COLOR_GRAY2BGR); @@ -998,7 +997,7 @@ int ImageResultJudge::MergeResult(std::shared_ptr pImageResult, tem.srcImg = pImageResult->detImg(CutRoi).clone(); } cv::resize(tem.srcImg, tem.resizeImg, sz); - #endif +#endif int nerrortype = 1; int checkFlage = ANALYSIS_TYPE_TF; @@ -1059,9 +1058,9 @@ int ImageResultJudge::MergeResult(std::shared_ptr pImageResult, { m_CheckResult_shareP->nresult = nqx_type; } - #ifdef SAVE_RESIMG +#ifdef SAVE_RESIMG GetAIDetImg(pImageResult, pCenter, tem.AI_in_Img, tem.AI_out_img); - #endif +#endif m_CheckResult_shareP->qxImageResult.push_back(tem); } } @@ -1433,24 +1432,24 @@ int ImageResultJudge::ConfigTypeToResultType(int nconfigType) { bool bdesc = false; int resultError_type = ERROR_TYPE_OK; - if(nconfigType < CONFIG_QX_NAME_Names.size()) + if (nconfigType < CONFIG_QX_NAME_Names.size()) { string cqn = CONFIG_QX_NAME_Names[nconfigType]; - for(int i = 0; i < m_FlawCodeList.size(); i++) + for (int i = 0; i < m_FlawCodeList.size(); i++) { - for(int j = 0; j < m_FlawCodeList.at(i).config_flaw_name.size(); j++) + for (int j = 0; j < m_FlawCodeList.at(i).config_flaw_name.size(); j++) { - if(cqn == m_FlawCodeList.at(i).config_flaw_name[j]) + if (cqn == m_FlawCodeList.at(i).config_flaw_name[j]) { resultError_type = i; bdesc = true; break; } - } + } } } // 如果描述没有配置,用默认值 - if(!bdesc) + if (!bdesc) { switch (nconfigType) { @@ -1535,6 +1534,12 @@ int ImageResultJudge::ConfigTypeToResultType(int nconfigType) case CONFIG_QX_NAME_LackPOL: resultError_type = ERROR_TYPE_LackPol; break; + case CONFIG_QX_NAME_RLine_X: + resultError_type = ERROR_TYPE_Line_X; + break; + case CONFIG_QX_NAME_RLine_Y: + resultError_type = ERROR_TYPE_Line_Y; + break; default: break; } diff --git a/AlgorithmModule/src/ImgCheckAnalysisy.cpp b/AlgorithmModule/src/ImgCheckAnalysisy.cpp index 39ee0de..d086c47 100644 --- a/AlgorithmModule/src/ImgCheckAnalysisy.cpp +++ b/AlgorithmModule/src/ImgCheckAnalysisy.cpp @@ -751,6 +751,10 @@ int ImgCheckAnalysisy::CalBlob_Other() { pDetAIResult = m_pImageAllResult->cell127_DetAIResult; } + else if (config_qx_type == CONFIG_QX_NAME_RLine_X || config_qx_type == CONFIG_QX_NAME_RLine_Y) + { + pDetAIResult = m_pImageAllResult->RLine_512_DetAIResult; + } cv::Mat maskImg = pDetAIResult->AI_MaskImg; if (maskImg.empty()) @@ -1092,6 +1096,10 @@ int ImgCheckAnalysisy::CalBLobMean_GrayDis() { pDetAIResult = m_pImageAllResult->cell127_DetAIResult; } + else if (config_qx_type == CONFIG_QX_NAME_RLine_X || config_qx_type == CONFIG_QX_NAME_RLine_Y) + { + pDetAIResult = m_pImageAllResult->RLine_512_DetAIResult; + } cv::Mat maskImg = pDetAIResult->AI_MaskImg; if (maskImg.empty()) @@ -1726,6 +1734,7 @@ int ImgCheckAnalysisy::GetALLBlob() long t4 = CheckUtil::getcurTime(); re = GetBlob_127cell(); long t5 = CheckUtil::getcurTime(); + re = GetBlob_RLine_512(); re = GetBlob_BQ(); if (blobs.blobCount > 1000) @@ -2187,6 +2196,135 @@ int ImgCheckAnalysisy::GetBlob_127cell() return 0; } +int ImgCheckAnalysisy::GetBlob_RLine_512() +{ + + std::string strBaseLog = "GetBlob_RLine_512"; + if (m_pFuntion && + m_pFuntion->function.f_RLineDet.bOpen && + m_pFuntion->function.f_RLineDet.bOpen_512) + { + } + else + { // 未开启检测 + return 0; + } + + std::shared_ptr pDetAIResult = m_pImageAllResult->RLine_512_DetAIResult; + + cv::Mat maskimg = pDetAIResult->AI_MaskImg; + if (maskimg.empty()) + { + return 1; + } + unsigned char *imgBlobHFlagData = pDetAIResult->blobDetParam->imgBlobHFlagData; + if (imgBlobHFlagData == NULL) + { + return 1; + } + + unsigned char *pGrayErrordata = (unsigned char *)maskimg.data; + int width = maskimg.cols; + int height = maskimg.rows; + + long t1 = CheckUtil::getcurTime(); + ERROR_DOTS_BLOBS blobs_all; + memset(&blobs_all, 0x00, sizeof(ERROR_DOTS_BLOBS)); + + ERROR_DOTS_BLOBS blobs_v1; + memset(&blobs_v1, 0x00, sizeof(ERROR_DOTS_BLOBS)); + ERROR_DOTS_BLOBS blobs_big; + memset(&blobs_big, 0x00, sizeof(ERROR_DOTS_BLOBS)); + ERROR_DOTS_BLOBS blobs_big_2; + memset(&blobs_big_2, 0x00, sizeof(ERROR_DOTS_BLOBS)); + + GetBlobs_oneLabe(&blobs_v1, pGrayErrordata, imgBlobHFlagData, width, height, 15); + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "blob 1 num %d", blobs_v1.blobCount); + + if (blobs_v1.srcBlobCount >= _MAX_ERROR_DOT_BLOB) + { + + GetBlobs_oneLabe(&blobs_big, pGrayErrordata, m_pImageAllResult->qx_DetAIResult->blobDetParam->imgBlobHFlagData, width, height, 200); + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "blob 2 num %d", blobs_big.blobCount); + + if (blobs_big.srcBlobCount >= _MAX_ERROR_DOT_BLOB) + { + + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "blob 3 num %d", blobs_big_2.blobCount); + GetBlobs_oneLabe(&blobs_big_2, pGrayErrordata, m_pImageAllResult->qx_DetAIResult->blobDetParam->imgBlobHFlagData, width, height, 500); + } + } + + long t2 = CheckUtil::getcurTime(); + PushBlob(&blobs_all, &blobs_big_2); + PushBlob(&blobs_all, &blobs_big); + PushBlob(&blobs_all, &blobs_v1); + for (int i = 0; i < blobs_all.blobCount; i++) + { + blobs_all.blobTab[i].ErrType = CONFIG_QX_NAME_RLine_X; + cv::Rect roi; + roi.x = blobs_all.blobTab[i].minx; + roi.y = blobs_all.blobTab[i].miny; + roi.width = blobs_all.blobTab[i].maxx - blobs_all.blobTab[i].minx + 1; + roi.height = blobs_all.blobTab[i].maxy - blobs_all.blobTab[i].miny + 1; + + if (roi.width > roi.height) + { + //m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "CONFIG_QX_NAME_RLine_X %d %d --%s \n",roi.width , roi.height,CONFIG_QX_NAME_Names[CONFIG_QX_NAME_RLine_X].c_str()); + blobs_all.blobTab[i].ErrType = CONFIG_QX_NAME_RLine_X; + } + else + { + //m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "CONFIG_QX_NAME_RLine_Y %d %d -- %s\n",roi.width , roi.height,CONFIG_QX_NAME_Names[CONFIG_QX_NAME_RLine_Y].c_str()); + blobs_all.blobTab[i].ErrType = CONFIG_QX_NAME_RLine_Y; + } + } + + PushBlob(&blobs, &blobs_all); + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "blob ALL num %d", blobs_all.blobCount); + if (DetImgInfo_shareP->bDebugsaveImg) + { + int font_face = cv::FONT_HERSHEY_SIMPLEX; + double font_scale = 0.5; + int thickness = 1; + + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "Save Tem Img"); + cv::Mat tm; + cv::cvtColor(maskimg, tm, cv::COLOR_GRAY2RGB); // 彩色 可选项 + for (int i = 0; i < blobs_all.blobCount; i++) + { + cv::Rect roi; + roi.x = blobs_all.blobTab[i].minx; + roi.y = blobs_all.blobTab[i].miny; + roi.width = blobs_all.blobTab[i].maxx - blobs_all.blobTab[i].minx + 1; + roi.height = blobs_all.blobTab[i].maxy - blobs_all.blobTab[i].miny + 1; + + if (blobs_all.blobTab[i].ErrType == 0) + { + cv::rectangle(tm, roi, cv::Scalar(0, 0, 255)); + } + else + { + cv::rectangle(tm, roi, cv::Scalar(0, 255, 255)); + } + + char buffer[128]; + sprintf(buffer, " type:%d m %0.1f", blobs.blobTab[i].ErrType, blobs.blobTab[i].density); + std::string text = buffer; + cv::Point origin = cv::Point(roi.x, roi.y); + cv::putText(tm, text, origin, font_face, font_scale, cv::Scalar(0, 255, 0), thickness, 1, 0); + + // printf("type: %d %d %d %d %d %d %d\n", blobs.blobTab[i].ErrType, blobs.blobTab[i].area, blobs.blobTab[i].energy, roi.x, roi.y, roi.width, roi.height); + } + cv::imwrite(m_strCurDetCamChannel + "_RLine_image_resize_blob.png", tm); + } + + long te = CheckUtil::getcurTime(); + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "image Blob Analysis End use time %ld blob %ld ms", te - t1, t2 - t1); + + return 0; +} + // BQAI检测 int ImgCheckAnalysisy::AI_Detect_BQ() { @@ -2211,7 +2349,7 @@ int ImgCheckAnalysisy::AI_Detect_BQ() m_pdetlog->AddCheckstr(PrintLevel_1, strBaseLog, "============= Start, BQ num = %d", bqNum); long ts = CheckUtil::getcurTime(); - std::string BQ_save_path = "/home/aidlux/BOE/FOG/BQ_AI_Det/"+ m_pImageAllResult->productBaseResult->strproductName + "/"; + std::string BQ_save_path = "/home/aidlux/BOE/FOG/BQ_AI_Det/" + m_pImageAllResult->productBaseResult->strproductName + "/"; CheckUtil::CreateDir(BQ_save_path); // 初始化BQ AI检测结果 @@ -2249,7 +2387,8 @@ int ImgCheckAnalysisy::AI_Detect_BQ() { cv::Rect bqRoi = m_pImageAllResult->cameraBaseResult->pBQ_Result->pBQ_expandedRoiList.at(i); cv::Rect validRoi = bqRoi & cv::Rect(0, 0, AI_detImage.cols, AI_detImage.rows); - if (validRoi.width <= 0 || validRoi.height <= 0) continue; + if (validRoi.width <= 0 || validRoi.height <= 0) + continue; // 如果BQ区域大于等于模型输入尺寸,切分成小块 if (validRoi.width >= AIInputImg_width && validRoi.height >= AIInputImg_height) @@ -2258,7 +2397,7 @@ int ImgCheckAnalysisy::AI_Detect_BQ() int re = CheckUtil::cutSmallImg(AI_detImage, smallList, validRoi, AIInputImg_width, AIInputImg_height, 0, 0); if (re == 0) { - for (const auto& roi : smallList) + for (const auto &roi : smallList) { BQ_SmallRoiList.push_back(roi); } @@ -2275,12 +2414,24 @@ int ImgCheckAnalysisy::AI_Detect_BQ() newRoi.width = AIInputImg_width; newRoi.height = AIInputImg_height; // 裁剪到图像边界 - if (newRoi.x < 0) newRoi.x = 0; - if (newRoi.y < 0) newRoi.y = 0; - if (newRoi.x + newRoi.width > AI_detImage.cols) newRoi.x = AI_detImage.cols - newRoi.width; - if (newRoi.y + newRoi.height > AI_detImage.rows) newRoi.y = AI_detImage.rows - newRoi.height; - if (newRoi.x < 0) { newRoi.x = 0; newRoi.width = AI_detImage.cols; } - if (newRoi.y < 0) { newRoi.y = 0; newRoi.height = AI_detImage.rows; } + if (newRoi.x < 0) + newRoi.x = 0; + if (newRoi.y < 0) + newRoi.y = 0; + if (newRoi.x + newRoi.width > AI_detImage.cols) + newRoi.x = AI_detImage.cols - newRoi.width; + if (newRoi.y + newRoi.height > AI_detImage.rows) + newRoi.y = AI_detImage.rows - newRoi.height; + if (newRoi.x < 0) + { + newRoi.x = 0; + newRoi.width = AI_detImage.cols; + } + if (newRoi.y < 0) + { + newRoi.y = 0; + newRoi.height = AI_detImage.rows; + } BQ_SmallRoiList.push_back(newRoi); } } @@ -2325,9 +2476,7 @@ int ImgCheckAnalysisy::AI_Detect_BQ() while (completed < totalTasks) { // 提交任务:满足并发限制和待处理限制 - if (submitted < totalTasks - && runner->GetProcessingCount() < MAX_CONCURRENT - && (submitted - completed) < MAX_PENDING) + if (submitted < totalTasks && runner->GetProcessingCount() < MAX_CONCURRENT && (submitted - completed) < MAX_PENDING) { std::shared_ptr task = std::make_shared(); task->id = submitted; @@ -2339,7 +2488,7 @@ int ImgCheckAnalysisy::AI_Detect_BQ() // 调试存图:保存每个小块 if (m_pFuntion->function.f_Det_BQ.bsaveAll) { - cv::imwrite(BQ_save_path +m_strCurDetCamChannel + "_" + std::to_string(submitted) + "_BQ_crop_in.png", task->input); + cv::imwrite(BQ_save_path + m_strCurDetCamChannel + "_" + std::to_string(submitted) + "_BQ_crop_in.png", task->input); } runner->SubmitTask(task); @@ -2356,7 +2505,7 @@ int ImgCheckAnalysisy::AI_Detect_BQ() // 调试存图:保存模型原始输出mask if (m_pFuntion->function.f_Det_BQ.bsaveAll) { - cv::imwrite(BQ_save_path + m_strCurDetCamChannel+ "_" + std::to_string(result->id) + "_BQ_crop_out.png", outimg); + cv::imwrite(BQ_save_path + m_strCurDetCamChannel + "_" + std::to_string(result->id) + "_BQ_crop_out.png", outimg); } cv::Mat AIresult; @@ -2459,9 +2608,9 @@ int ImgCheckAnalysisy::GetBlob_BQ() PushBlob(&blobs, &blobs_bq); long te = CheckUtil::getcurTime(); - m_pdetlog->AddCheckstr(PrintLevel_1, strBaseLog, - "BQ blob num = %d, merged to main blobs (total=%d), time=%ld ms", - blobs_bq.blobCount, blobs.blobCount, te - t1); + m_pdetlog->AddCheckstr(PrintLevel_1, strBaseLog, + "BQ blob num = %d, merged to main blobs (total=%d), time=%ld ms", + blobs_bq.blobCount, blobs.blobCount, te - t1); // 调试存图 if (DetImgInfo_shareP->bDebugsaveImg && blobs_bq.blobCount > 0) @@ -2619,6 +2768,72 @@ int ImgCheckAnalysisy::AIMaskDet() } } m_pdetlog->AddCheckstr(PrintLevel_1, "AIMaskDet", "=======cell127_DetAIResult end"); + // RLine_512 检测 + while (true) + { + + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + if (!m_pImageAllResult->RLine_512_DetAIResult) + { + // 等待初始化 + continue; + } + blobDetParam = m_pImageAllResult->RLine_512_DetAIResult->blobDetParam; + + std::shared_ptr AImaskResult; + { + std::lock_guard lock(blobDetParam->mtx_AIMaskImgBLobQueue); + if (blobDetParam->AIMaskImgBLobQueue.size() > 0) + { + AImaskResult = std::move(blobDetParam->AIMaskImgBLobQueue.front()); + blobDetParam->AIMaskImgBLobQueue.pop(); + // printf("size ============== %ld\n", m_AIMaskImgBLobQueue.size()); + } + } + + // 有AI mask 的结果 + if (AImaskResult) + { + // static int ss = 0; + cv::Mat outimg = AImaskResult->AI_mask; + // cv::imwrite(std::to_string(ss++) + ".png", outimg); + + unsigned char *pGrayErrordata = (unsigned char *)outimg.data; + int width = outimg.cols; + int height = outimg.rows; + int start_Y = AImaskResult->roi.y; + if (cv::countNonZero(outimg != 0) != 0) + { + // #pragma omp parallel for + for (int y = 0; y < height; y++) + { + if ((y + start_Y) < blobDetParam->ndatalen && blobDetParam->imgBlobHFlagData[y + start_Y] == 0) + { + unsigned char *p = pGrayErrordata + y * width; + for (int x = 0; x < width; x++) + { + if (p[x] != 0) + { + // printf("===============cell127_DetAIResult ====m_ImgBlobHFlagData %d===%d = %d=======0 \n", blobDetParam->ndatalen, y + start_Y, outimg.rows); + blobDetParam->imgBlobHFlagData[y + start_Y] = 1; + break; + } + } + } + } + } + } + else + { + /* code */ + + if (m_AItask->isComplate()) + { + break; + } + } + } + m_pdetlog->AddCheckstr(PrintLevel_1, "AIMaskDet", "=======RLine_512_DetAIResult end"); m_AItask->waitComplate(); int rec = m_AItask->nresult; @@ -2760,6 +2975,9 @@ int ImgCheckAnalysisy::AI_Detect_Thread() // 127cell re = AI_Detect_127Cell(); + // RLine_512 + re = AI_Detect_RLine_512(); + t3 = CheckUtil::getcurTime(); m_pdetlog->AddCheckstr(PrintLevel_0, DET_LOG_LEVEL_3, strBaseLog, "****** AI_Detect End; AI Run Time: sum %ld", t3 - t1); @@ -2839,7 +3057,7 @@ int ImgCheckAnalysisy::AI_Detect_QX() } int nSaveCnt = 0; - + int AIInputImg_width = pAI_Model->input_0.width; int AIInputImg_height = pAI_Model->input_0.height; @@ -2890,17 +3108,15 @@ int ImgCheckAnalysisy::AI_Detect_QX() cv::Mat AIresultMask = pDetAIResult->AI_MaskImg; // 资源控制:限制最大并发数和最大待处理数,防止GPU/CPU内存压力导致推理异常 - const int MAX_CONCURRENT = 5; // 最大同时在推理中的任务数(降低GPU并发压力) - const int MAX_PENDING = 5; // submitted - completed 最大差值(限制内存中待处理结果数) + const int MAX_CONCURRENT = 5; // 最大同时在推理中的任务数(降低GPU并发压力) + const int MAX_PENDING = 5; // submitted - completed 最大差值(限制内存中待处理结果数) t2 = CheckUtil::getcurTime(); while (completed < totalTasks) { // 如果任务还没提交完,且满足并发限制和待处理限制,提交新任务 - if (submitted < totalTasks - && runner->GetProcessingCount() < MAX_CONCURRENT - && (submitted - completed) < MAX_PENDING) + if (submitted < totalTasks && runner->GetProcessingCount() < MAX_CONCURRENT && (submitted - completed) < MAX_PENDING) { std::shared_ptr task = std::make_shared(); @@ -2981,9 +3197,9 @@ int ImgCheckAnalysisy::AI_Detect_QX() std::string roi_ext = "[" + std::to_string(result->roi.x) + "," + std::to_string(result->roi.y) + "]"; 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"; - std::string strSavePath_out_raw = strSaveDir + m_strCurDetChannel +"_"+ roi_ext + "_"+ "out_raw" + ".png"; + std::string strSavePath_in = strSaveDir + m_strCurDetChannel + "_" + roi_ext + "_" + "in" + ".png"; + std::string strSavePath_out = strSaveDir + m_strCurDetChannel + "_" + roi_ext + "_" + "out" + ".png"; + std::string strSavePath_out_raw = strSaveDir + m_strCurDetChannel + "_" + roi_ext + "_" + "out_raw" + ".png"; cv::imwrite(strSavePath_in, result->input); cv::imwrite(strSavePath_out, AIresult); cv::imwrite(strSavePath_out_raw, AIresult_raw); @@ -3086,9 +3302,7 @@ int ImgCheckAnalysisy::AI_Detect_127Cell() while (completed < totalTasks) { // 如果任务还没提交完,且满足并发限制和待处理限制,提交新任务 - if (submitted < totalTasks - && runner->GetProcessingCount() < MAX_CONCURRENT - && (submitted - completed) < MAX_PENDING) + if (submitted < totalTasks && runner->GetProcessingCount() < MAX_CONCURRENT && (submitted - completed) < MAX_PENDING) { std::shared_ptr task = std::make_shared(); @@ -3170,8 +3384,8 @@ int ImgCheckAnalysisy::AI_Detect_127Cell() { std::string strSaveDir = "/home/aidlux/BOE/FOG/AI_Detect_127/" + 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"; + 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); } @@ -3196,6 +3410,199 @@ int ImgCheckAnalysisy::AI_Detect_127Cell() return 0; } +int ImgCheckAnalysisy::AI_Detect_RLine_512() +{ + + std::string strBaseLog = "AI_Detect_RLine_512"; + m_pImageAllResult->RLine_512_DetAIResult = std::make_shared(); + + if (m_pFuntion && m_pFuntion->function.f_RLineDet.bOpen) + { + } + else + { // 未开启检测 + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, " f_RLineDet close"); + return 0; + } + if (m_pFuntion && m_pFuntion->function.f_RLineDet.bOpen_512) + { + } + else + { // 未开启检测 + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, " f_RLineDet 512 Model close"); + return 0; + } + long ts, t2, te; + ts = CheckUtil::getcurTime(); + + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "============= Start"); + std::shared_ptr pDetAIResult = m_pImageAllResult->RLine_512_DetAIResult; + cv::Mat AI_detImage = m_pImageAllResult->AI_detImg; + + std::shared_ptr pAI_Model = AI_Factory->AI_defect_RLine_512; + + int AIInputImg_width = pAI_Model->input_0.width; + int AIInputImg_height = pAI_Model->input_0.height; + + int AIOutputImg_width = pAI_Model->output_0.width; + int AIOutputImg_height = pAI_Model->output_0.height; + pDetAIResult->InitBLobHData(AI_detImage.rows); + // 是否需要 resize到输入图大小进行后续处理。 + bool bResizeToSrc = false; + if (AIOutputImg_width != AIInputImg_width || AIOutputImg_height != AIInputImg_height) + { + bResizeToSrc = true; + } + + // 如果尺寸不合适,要重新计算 smll roi.一般情况来说,small roi 都是相同的对不同的AI 模型。在模型设计时要做到统一,降低调用复杂度。 + if (SmallRoiList.size() > 0) + { + int roi_width = SmallRoiList.at(0).width; + int roi_height = SmallRoiList.at(0).height; + if (roi_width != AIInputImg_width || roi_height != AIInputImg_height) + { + int re = CreatAIDetSmallRoi(AI_detImage, pAI_Model, SmallRoiList); + if (re != 0) + { + m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, strBaseLog, "error small roi"); + return 1; + } + } + } + const int totalTasks = SmallRoiList.size(); + if (totalTasks <= 0) + { + m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, strBaseLog, "error small roi = 0"); + return 0; + } + + int submitted = 0; + int completed = 0; + + cv::Size src_sz; + src_sz.width = AIInputImg_width; + src_sz.height = AIInputImg_height; + + pDetAIResult->AI_MaskImg = cv::Mat::zeros(AI_detImage.size(), CV_8UC1); + cv::Mat shieldImg = m_pImageAllResult->AI_shieldImg; + cv::Mat AIresultMask = pDetAIResult->AI_MaskImg; + + // 资源控制:限制最大并发数和最大待处理数 + const int MAX_CONCURRENT = 5; + const int MAX_PENDING = 5; + + t2 = CheckUtil::getcurTime(); + while (completed < totalTasks) + { + // 如果任务还没提交完,且满足并发限制和待处理限制,提交新任务 + if (submitted < totalTasks && runner->GetProcessingCount() < MAX_CONCURRENT && (submitted - completed) < MAX_PENDING) + { + + std::shared_ptr task = std::make_shared(); + task->id = completed; + task->roi = SmallRoiList.at(submitted); + task->input = AI_detImage(task->roi).clone(); + task->output = std::make_shared(); + task->engine = pAI_Model; + if (submitted >= det_SmallImgNum) + { + task->userflag = 9; + } + + runner->SubmitTask(task); + submitted++; + } + + // 尝试取结果 + std::shared_ptr result; + if (runner->PopResult(result)) + { + cv::Mat &outimg = *(result->output); + if (!outimg.empty()) + { + cv::Mat AIresult; + if (bResizeToSrc) + { + // 1、 resize 到原始大小。 + cv::resize(outimg, AIresult, src_sz, 0, 0, 0); + } + else + { + AIresult = outimg; + } + + cv::Rect srcsize_roi = result->roi; + + // 2、 屏蔽 缺陷 + AIresult.setTo(0, shieldImg(result->roi)); + + // 如果是字符区域,则 全部替换 + if (result->userflag == 9) + { + AIresult.copyTo(AIresultMask(result->roi)); + } + else + { + AIresult.copyTo(AIresultMask(result->roi), AIresult); + } + +#ifdef SAVE_RESIMG + { + std::shared_ptr temAIresult = std::make_shared(); + temAIresult->roi = result->roi; + temAIresult->AI_inImg = result->input; + temAIresult->AI_mask = outimg; + pDetAIResult->AI_Qx_MaskList.push_back(temAIresult); + } +#endif + + { + std::shared_ptr temAIresult = std::make_shared(); + temAIresult->roi = result->roi; + temAIresult->AI_mask = AIresult; + { + std::lock_guard lock(pDetAIResult->blobDetParam->mtx_AIMaskImgBLobQueue); + 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_RLine_512/" + 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++; + } + else + { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + } + // 临时存图 + if (DetImgInfo_shareP->bDebugsaveImg) + { + cv::imwrite(m_strCurDetCamChannel + "_AI_RLine_512_mask.png", AIresultMask); + } + te = CheckUtil::getcurTime(); + float mean_AI = (te - t2) / SmallRoiList.size(); + 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); + + return 0; +} + int ImgCheckAnalysisy::AI_QX_Class_Thread() { @@ -3206,7 +3613,10 @@ int ImgCheckAnalysisy::AI_QX_Class_Thread() for (int i = 0; i < blobs.blobCount; i++) { - if (blobs.blobTab[i].ErrType == CONFIG_QX_NAME_white_Cell || blobs.blobTab[i].ErrType == CONFIG_QX_NAME_black_Cell) + if (blobs.blobTab[i].ErrType == CONFIG_QX_NAME_white_Cell || + blobs.blobTab[i].ErrType == CONFIG_QX_NAME_black_Cell || + blobs.blobTab[i].ErrType == CONFIG_QX_NAME_RLine_X || + blobs.blobTab[i].ErrType == CONFIG_QX_NAME_RLine_Y) { } else @@ -3775,34 +4185,35 @@ int ImgCheckAnalysisy::BLobToDetResult() config_qx_type == CONFIG_QX_NAME_Other || config_qx_type == CONFIG_QX_NAME_LD) { - 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 = -1; - if(m_pFuntion->function.f_LDConfig.bOpen && m_pFuntion->function.f_LDConfig.bUseLD_Standard) + if (m_pFuntion->function.f_LDConfig.bOpen && m_pFuntion->function.f_LDConfig.bUseLD_Standard) { - if(blobs.blobTab[i].JudgArea >= m_pFuntion->function.f_LDConfig.fLD_Area && - blobs.blobTab[i].grayDis >= m_pFuntion->function.f_LDConfig.fLD_HJ && - blobs.blobTab[i].energy >= m_pFuntion->function.f_LDConfig.fLD_En && - blobs.blobTab[i].len >= m_pFuntion->function.f_LDConfig.fLD_Len) + if (blobs.blobTab[i].JudgArea >= m_pFuntion->function.f_LDConfig.fLD_Area && + blobs.blobTab[i].grayDis >= m_pFuntion->function.f_LDConfig.fLD_HJ && + blobs.blobTab[i].energy >= m_pFuntion->function.f_LDConfig.fLD_En && + blobs.blobTab[i].len >= m_pFuntion->function.f_LDConfig.fLD_Len) { dbresult = 1; bLD_Standard = true; } - pQxlog->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "LD Analysis", "Area %0.2f > %0.2f , hj %0.2f > %0.2f , Energy %0.2f > %0.2f , len %0.2f > %0.2f", - blobs.blobTab[i].JudgArea, m_pFuntion->function.f_LDConfig.fLD_Area, blobs.blobTab[i].grayDis, m_pFuntion->function.f_LDConfig.fLD_HJ, blobs.blobTab[i].energy, m_pFuntion->function.f_LDConfig.fLD_En, blobs.blobTab[i].len, m_pFuntion->function.f_LDConfig.fLD_Len); + pQxlog->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "LD Analysis", "Area %0.2f > %0.2f , hj %0.2f > %0.2f , Energy %0.2f > %0.2f , len %0.2f > %0.2f", + blobs.blobTab[i].JudgArea, m_pFuntion->function.f_LDConfig.fLD_Area, blobs.blobTab[i].grayDis, m_pFuntion->function.f_LDConfig.fLD_HJ, blobs.blobTab[i].energy, m_pFuntion->function.f_LDConfig.fLD_En, blobs.blobTab[i].len, m_pFuntion->function.f_LDConfig.fLD_Len); } - if(dbresult != 1) + if (dbresult != 1) { dbresult = LDJudge(config_qx_type, roi, JudgArea, blobs.blobTab[i].maxValue, blobs.blobTab[i].grayDis, pQxlog); } - //int detre = 1; - // 表示L0 和 DP 都有的 亮的 + // 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_Pass_1(dbresult), 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) { @@ -4375,7 +4786,7 @@ int ImgCheckAnalysisy::AI_Classify_New(const cv::Mat &src_Img, cv::Rect qx_roi, // bIsLine = true; // } - //长宽比满足,判断为线 + // 长宽比满足,判断为线 if (flenr > 10) { // printf("\n\n\n\n\n\n\n\n\n--------- flenr %f len %d,widt %d,fjustarea %f\n", flenr,len,widt,fjustarea); @@ -4384,7 +4795,7 @@ int ImgCheckAnalysisy::AI_Classify_New(const cv::Mat &src_Img, cv::Rect qx_roi, strclassName = "line"; bIsLine = true; } - m_pdetlog->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AI_Classify_line", "bIsLine %d, flenr %f len %d,widt %d,fjustarea %f", bIsLine, flenr,len,widt,fjustarea); + m_pdetlog->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AI_Classify_line", "bIsLine %d, flenr %f len %d,widt %d,fjustarea %f", bIsLine, flenr, len, widt, fjustarea); } } @@ -4509,7 +4920,7 @@ int ImgCheckAnalysisy::ImgPreDet() } #ifdef SAVE_RESIMG - m_CheckResult_shareP->cutSrcimg = m_pImageAllResult->detImg; + m_CheckResult_shareP->cutSrcimg = m_pImageAllResult->detImg; ResizeImg(); m_pImageAllResult->fscale_detToresult_x = m_pImageAllResult->resultImg.cols * 1.0f / m_pImageAllResult->detImg.cols; m_pImageAllResult->fscale_detToresult_y = m_pImageAllResult->resultImg.rows * 1.0f / m_pImageAllResult->detImg.rows; @@ -4683,9 +5094,9 @@ int ImgCheckAnalysisy::UpdateSheildMask(std::string strChannel, cv::Rect roi) } else { - if(!m_pFuntion->function.f_ShieldRegion.bOpen) + if (!m_pFuntion->function.f_ShieldRegion.bOpen) m_pdetlog->AddCheckstr(PrintLevel_1, "UpdateSheildMask", "strChannel %s m_pFuntion bOpen is false ", strChannel.c_str()); - if(m_pFuntion == NULL) + if (m_pFuntion == NULL) m_pdetlog->AddCheckstr(PrintLevel_1, "UpdateSheildMask", "strChannel %s m_pFuntion is NULL error ", strChannel.c_str()); } // 是否要存图 @@ -4873,6 +5284,12 @@ std::string ImgCheckAnalysisy::ConfigTypeToWebDetType(int nconfigType) case CONFIG_QX_NAME_black_Cell: strqx = Function_CONFIG_QX_NAME_Names[Function_CONFIG_QX_NAME_Cell]; break; + case CONFIG_QX_NAME_RLine_X: + strqx = Function_CONFIG_QX_NAME_Names[Function_CONFIG_QX_NAME_line]; + break; + case CONFIG_QX_NAME_RLine_Y: + strqx = Function_CONFIG_QX_NAME_Names[Function_CONFIG_QX_NAME_line]; + break; break; default: break; @@ -4987,15 +5404,14 @@ int ImgCheckAnalysisy::CalBlobDensity_QX() 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); + 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; } - diff --git a/ConfigModule/include/CheckConfigDefine.h b/ConfigModule/include/CheckConfigDefine.h index f9d50a4..8a4fabb 100644 --- a/ConfigModule/include/CheckConfigDefine.h +++ b/ConfigModule/include/CheckConfigDefine.h @@ -71,6 +71,8 @@ enum CONFIG_QX_NAME_ CONFIG_QX_NAME_black_Cell, // 白cell CONFIG_QX_NAME_LD_HS, // 黑闪类画面的亮点 CONFIG_QX_NAME_LackPOL, // 缺失pol检测 + CONFIG_QX_NAME_RLine_X, // 弱线 X + CONFIG_QX_NAME_RLine_Y, // 弱线 Y CONFIG_QX_NAME_count, }; // 缺陷项对应在参数中的名称 @@ -105,7 +107,9 @@ static std::vector CONFIG_QX_NAME_Names = "white_Cell", "black_Cell", "LD_HS", - "LackPOL"}; + "LackPOL", + "RLine_X", + "RLine_Y"}; // web控制检测的缺陷类型, enum Function_CONFIG_QX_NAME_ @@ -205,8 +209,7 @@ static const std::string IMG_CHANNEL_NAME[] = "RGB-HGRAY", "SCANR", "SCANG", - "SCANB" - }; + "SCANB"}; // 分析类型 enum ANALYSIS_TYPE_ { @@ -453,7 +456,7 @@ struct BasicConfig float fImage_Scale_y; // 成像精度 float fProduct_Off_X_mm; // 产品偏移量 std::string strCamName; // - std::string strConfigVersion; // 配置版本 + std::string strConfigVersion; // 配置版本 float density_R_mm; // 密度计算半径 像素 BasicConfig() @@ -854,7 +857,7 @@ struct Function_AI_QX void print(std::string str) { // printf("%s>>bOpen %d POLToWhitePOL %d AllToChess %d 127WhitePOl_UseDP %d 127WhitePOl_DP_IOU %f\n", - // str.c_str(), bOpen, bPOLToWhitePOL, bAllToChess, b127WhitePOl_UseDP, f127WhitePOl_DP_IOU); + // str.c_str(), bOpen, bPOLToWhitePOL, bAllToChess, b127WhitePOl_UseDP, f127WhitePOl_DP_IOU); } std::string GetInfo(std::string str) { @@ -875,10 +878,10 @@ struct Function_AI_LD float fDP_IOU; // DP的IOU bool bUseLD_Standard; // 是否使用亮点标准化参数 - float fLD_Area; // 亮点面积 - float fLD_En; // 亮点的能量 - float fLD_HJ; // 亮点灰阶 - float fLD_Len; // 亮点长度 + float fLD_Area; // 亮点面积 + float fLD_En; // 亮点的能量 + float fLD_HJ; // 亮点灰阶 + float fLD_Len; // 亮点长度 Function_AI_LD() { Init(); @@ -1554,8 +1557,8 @@ struct AD_Analysisy_S // 暗点同位置判断(IOU) struct AD_Analysisy_IOU { - float AD_IOU; // IOU 阈值 - float AD_Expand; // 扩张阈值 + float AD_IOU; // IOU 阈值 + float AD_Expand; // 扩张阈值 AD_Analysisy_IOU() { Init(); @@ -1605,7 +1608,7 @@ struct AD_Analysisy_Bind correlated_channels.clear(); correlated_types.clear(); } - void copy (AD_Analysisy_Bind tem) + void copy(AD_Analysisy_Bind tem) { this->bUse = tem.bUse; this->main_channel_2s = tem.main_channel_2s; @@ -1639,23 +1642,23 @@ struct AD_Analysisy_SF s_sf.clear(); region_sf.clear(); } - void copy (AD_Analysisy_SF tem) + void copy(AD_Analysisy_SF tem) { this->s_sf = tem.s_sf; this->region_sf = tem.region_sf; } std::string GetInfo(std::string str) { - std::string str123; - for (int i = 0; i < s_sf.size(); i++) - { - str123 += str + ":s_sf " + s_sf[i] + ";"; - } - for (int i = 0; i < region_sf.size(); i++) - { - str123 += str + ":region_sf " + region_sf[i] + ";"; - } - return str123; + std::string str123; + for (int i = 0; i < s_sf.size(); i++) + { + str123 += str + ":s_sf " + s_sf[i] + ";"; + } + for (int i = 0; i < region_sf.size(); i++) + { + str123 += str + ":region_sf " + region_sf[i] + ";"; + } + return str123; } }; // 异物检测功能 @@ -1747,8 +1750,8 @@ struct Function_Edge_Det } }; struct Function_Det_BQ -{ - bool bBQ_AI_Det; // 是否启用标签独立AI检测 +{ + bool bBQ_AI_Det; // 是否启用标签独立AI检测 int BQ_expand; bool bsaveAll; @@ -1781,9 +1784,39 @@ struct Function_Det_BQ std::string str123 = buffer; return str123; } - }; +// 启用127cell 独立检测 +struct Function_Det_RLine +{ + bool bOpen; // 是否开启 + bool bOpen_512; // 512模型是否开启。 + Function_Det_RLine() + { + Init(); + } + void Init() + { + bOpen = false; + bOpen_512 = false; + } + void copy(Function_Det_RLine tem) + { + this->bOpen = tem.bOpen; + this->bOpen_512 = tem.bOpen_512; + } + void print(std::string str) + { + printf("%s>>bOpen %d bOpen_512 %d \n", str.c_str(), bOpen, bOpen_512); + } + std::string GetInfo(std::string str) + { + char buffer[64]; + sprintf(buffer, "%s>>bOpen %d bOpen_512 %d \n", str.c_str(), bOpen, bOpen_512); + std::string str123 = buffer; + return str123; + } +}; // 检测功能 struct CheckFunction { @@ -1803,6 +1836,7 @@ struct CheckFunction Function_POL_Check f_POL_Check; // 异物的检测功能 Function_Edge_Det f_dege_Det; Function_Det_BQ f_Det_BQ; + Function_Det_RLine f_RLineDet; // 弱线检测参数 CheckFunction() { Init(); @@ -1825,6 +1859,7 @@ struct CheckFunction f_POL_Check.Init(); f_dege_Det.Init(); f_Det_BQ.Init(); + f_RLineDet.Init(); } void copy(CheckFunction tem) { @@ -1845,6 +1880,7 @@ struct CheckFunction this->f_POL_Check.copy(tem.f_POL_Check); this->f_dege_Det.copy(tem.f_dege_Det); this->f_Det_BQ.copy(tem.f_Det_BQ); + this->f_RLineDet.copy(tem.f_RLineDet); } void print(std::string str) { @@ -1865,6 +1901,7 @@ struct CheckFunction f_POL_Check.print("f_POL_Check"); f_dege_Det.print("f_dege_Det"); f_Det_BQ.print("f_Det_BQ"); + f_RLineDet.print("f_RLineDet"); } std::string GetInfo(std::string str) { @@ -1886,6 +1923,7 @@ struct CheckFunction str123 += f_POL_Check.GetInfo("f_POL_Check"); str123 += f_dege_Det.GetInfo("f_dege_Det"); str123 += f_Det_BQ.GetInfo("f_Det_BQ"); + str123 += f_RLineDet.GetInfo("f_RLineDet"); return str123; } }; @@ -2262,17 +2300,16 @@ struct Base_Function_Edge_Det struct Base_Function_AD_Check { - bool bOpen; // 是否开启 - AD_S_Standard S_standard_3s; // 3s 标准 - AD_S_Standard S_standard_2s; // 2s 标准 - AD_S_Standard S_standard_1s; // 1s 标准 - AD_Analysisy_Num analysis_num; // 数量分析 - AD_Analysisy_Dis analysis_dis; // 距离分析 - AD_Analysisy_S analysis_s; // s 标准分析 - AD_Analysisy_IOU analysis_iou; // IOU 分析 + bool bOpen; // 是否开启 + AD_S_Standard S_standard_3s; // 3s 标准 + AD_S_Standard S_standard_2s; // 2s 标准 + AD_S_Standard S_standard_1s; // 1s 标准 + AD_Analysisy_Num analysis_num; // 数量分析 + AD_Analysisy_Dis analysis_dis; // 距离分析 + AD_Analysisy_S analysis_s; // s 标准分析 + AD_Analysisy_IOU analysis_iou; // IOU 分析 AD_Analysisy_Bind analysis_bind; // 绑定分析 - AD_Analysisy_SF analysis_sf; // 同画面参数分析 - + AD_Analysisy_SF analysis_sf; // 同画面参数分析 Base_Function_AD_Check() { @@ -2316,7 +2353,7 @@ struct Base_Function_AD_Check analysis_s.GetInfo("analysis_s").c_str(), analysis_iou.GetInfo("analysis_iou").c_str(), analysis_bind.GetInfo("analysis_bind").c_str(), - analysis_sf.GetInfo("analysis_sf").c_str()); + analysis_sf.GetInfo("analysis_sf").c_str()); } std::string GetInfo(std::string str) { diff --git a/ConfigModule/src/JsonConfig.cpp b/ConfigModule/src/JsonConfig.cpp index d09f1b0..156b5f4 100644 --- a/ConfigModule/src/JsonConfig.cpp +++ b/ConfigModule/src/JsonConfig.cpp @@ -48,11 +48,11 @@ void CommonParamToCheckConfigJson::toObjectFromValue(Json::Value root) if (value.isObject()) { _config.baseConfig.strConfigVersion = value["version"].asString(); - if ( _config.baseConfig.strConfigVersion == "") + if (_config.baseConfig.strConfigVersion == "") { - _config.baseConfig.strConfigVersion = "NULL"; - } - + _config.baseConfig.strConfigVersion = "NULL"; + } + _config.baseConfig.image_widht = value["image_widht"].asInt(); _config.baseConfig.Image_height = value["Image_height"].asInt(); _config.baseConfig.bDrawShieldRoi = value["bDrawShieldRoi"].asBool(); @@ -567,7 +567,7 @@ int ChannelFuntonConfigJson::GetFunction(Json::Value value, CheckFunction &funct { function.f_LDConfig.fDP_IOU = value_f["form"]["LD_Det"]["DP_IOU"].asFloat(); } - + if (value_f["form"]["LD_Standard"]["LD_Area"]) { function.f_LDConfig.fLD_Area = value_f["form"]["LD_Standard"]["LD_Area"].asFloat(); @@ -1060,6 +1060,25 @@ int ChannelFuntonConfigJson::GetFunction(Json::Value value, CheckFunction &funct function.f_Det_BQ.bsaveAll = true; } } + if ("Det_RLine" == strCode) + { + auto value_f = value[i]; + // std::cout << value_f << std::endl; + function.f_RLineDet.bOpen = value_f["isOpen"].asBool(); + if (function.f_RLineDet.bOpen) + { + if (value_f["form"]["Config_Model_512"]["bOpen"]) + { + function.f_RLineDet.bOpen_512 = value_f["form"]["Config_Model_512"]["bOpen"].asBool(); + } + } + else + { + function.f_RLineDet.Init(); + } + // function.f_RLineDet.print(""); + // getchar(); + } } } return 0;