diff --git a/AlgorithmModule/include/ImgCheckAnalysisy.hpp b/AlgorithmModule/include/ImgCheckAnalysisy.hpp index 834b9e9..74e4bc0 100644 --- a/AlgorithmModule/include/ImgCheckAnalysisy.hpp +++ b/AlgorithmModule/include/ImgCheckAnalysisy.hpp @@ -200,7 +200,7 @@ private: int BLobToDetResult(); //自适应参数区域更新 - int Adapt_Config(Mat img, Rect roi, bool b_update); + int Adapt_Config(Mat img, Rect roi, bool b_update, cv::RotatedRect &rot_cur_roi); std::shared_ptr AI_Factory; diff --git a/AlgorithmModule/src/ImgCheckAnalysisy.cpp b/AlgorithmModule/src/ImgCheckAnalysisy.cpp index c13b81b..b5145e6 100644 --- a/AlgorithmModule/src/ImgCheckAnalysisy.cpp +++ b/AlgorithmModule/src/ImgCheckAnalysisy.cpp @@ -451,7 +451,7 @@ Point2f GetCoorPoint(Point2f point, Mat img_mat) return new_point; } -int GetEdgeRoi(Mat img, Rect &new_roi, cv::RotatedRect &rotated_roi, float scale_x, float scale_y){ +int GetEdgeRoi(Mat img, Rect &new_roi, cv::RotatedRect &rotated_roi, float scale_x, float scale_y, string cur_channel){ if (img.empty()) { return 1; @@ -465,9 +465,22 @@ int GetEdgeRoi(Mat img, Rect &new_roi, cv::RotatedRect &rotated_roi, float scale // 二值化找最大连通域 Mat r_img_bin; - threshold(r_img, r_img_bin, 15, 255, THRESH_BINARY); + if(cur_channel == "BCA" || cur_channel == "BTA") + { + threshold(r_img, r_img_bin, 35, 255, THRESH_BINARY); + } + else + { + threshold(r_img, r_img_bin, 35, 255, THRESH_BINARY); + } + // 做一步开运算 + Mat r_img_bin_close; + morphologyEx(r_img_bin, r_img_bin_close, MORPH_CLOSE, Mat::ones(15, 15, CV_8U)); + // imwrite("r_img_bin.tif", r_img_bin); + // imwrite("r_img_bin_close.tif", r_img_bin_close); + // imwrite("r_img.tif", r_img); std::vector> contours; - cv::findContours(r_img_bin, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE); + cv::findContours(r_img_bin_close, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE); if (contours.empty()) { return 2; @@ -599,7 +612,7 @@ std::vector sort_vertices(cv::RotatedRect rrect) { return vertices; } -int ImgCheckAnalysisy::Adapt_Config(Mat img, Rect cur_roi, bool b_update){ +int ImgCheckAnalysisy::Adapt_Config(Mat img, Rect cur_roi, bool b_update, cv::RotatedRect &rot_cur_roi){ if (img.empty()) { std::cerr << "Error: Input image 'img' is empty!" << std::endl; return -1; @@ -607,8 +620,8 @@ int ImgCheckAnalysisy::Adapt_Config(Mat img, Rect cur_roi, bool b_update){ if(!b_update){ return 1; } - cv::RotatedRect rot_cur_roi; - int get_edge_roi = GetEdgeRoi(img, cur_roi, rot_cur_roi, 20, 20); + // cv::RotatedRect rot_cur_roi; + int get_edge_roi = GetEdgeRoi(img, cur_roi, rot_cur_roi, 20, 20, m_CheckResult_shareP->basicResult.strChannel); if(get_edge_roi != 0){ return 2; } @@ -798,7 +811,11 @@ int ImgCheckAnalysisy::CheckRun() m_strCurDetChannel = m_CheckResult_shareP->basicResult.strChannel; /*自适应更新参数*/ - Adapt_Config(m_CheckResult_shareP->in_shareImage->img, m_CutRoi, m_pbaseCheckFunction->markLine.badapt_region); + long time_adapt_s = CheckUtil::getcurTime(); + cv::RotatedRect rot_cur_roi; + Adapt_Config(m_CheckResult_shareP->in_shareImage->img, m_CutRoi, m_pbaseCheckFunction->markLine.badapt_region, rot_cur_roi); + long time_adapt_e = CheckUtil::getcurTime(); + m_pdetlog->AddCheckstr(PrintLevel_0, "Adapt_Config", "time = %ld", time_adapt_e - time_adapt_s); // 2、参数检查 int rec = ConfigCheck(DetImgInfo_shareP->img); @@ -811,14 +828,25 @@ int ImgCheckAnalysisy::CheckRun() } long time_edge_s = CheckUtil::getcurTime(); // 3、AI 边缘定位 - int reedge = AI_Edge(m_CheckResult_shareP->in_shareImage->img, m_CutRoi); - if (reedge != 0) + if(m_CheckResult_shareP->basicResult.strChannel == "DCA" || m_CheckResult_shareP->basicResult.strChannel == "DTA") { - m_pdetlog->AddCheckstr(PrintLevel_0, "Error", "AI_Edge is error type = %d", reedge); - m_nErrorCode = reedge; - m_nCheckResultErrorCode = m_nErrorCode; - return m_nErrorCode; + m_pdetlog->AddCheckstr(PrintLevel_0, "Edge", "Not Use AI_Edge %s", m_CheckResult_shareP->basicResult.strChannel.c_str()); + m_CutRoi = cv::Rect(rot_cur_roi.boundingRect().x - 50 , rot_cur_roi.boundingRect().y - 50, rot_cur_roi.boundingRect().width + 100, rot_cur_roi.boundingRect().height + 100) + & cv::Rect(0, 0, m_CheckResult_shareP->in_shareImage->img.cols, m_CheckResult_shareP->in_shareImage->img.rows); } + else + { + m_pdetlog->AddCheckstr(PrintLevel_0, "Edge", "Use AI_Edge %s", m_CheckResult_shareP->basicResult.strChannel.c_str()); + int reedge = AI_Edge(m_CheckResult_shareP->in_shareImage->img, m_CutRoi); + if (reedge != 0) + { + m_pdetlog->AddCheckstr(PrintLevel_0, "Error", "AI_Edge is error type = %d", reedge); + m_nErrorCode = reedge; + m_nCheckResultErrorCode = m_nErrorCode; + return m_nErrorCode; + } + } + long time_edge_e = CheckUtil::getcurTime(); m_pdetlog->AddCheckstr(PrintLevel_0, "2、pre detect", "-------------------------AI_Edge------------succ---time %ld----\n", time_edge_e - time_edge_s);