diff --git a/.gitignore b/.gitignore index 286242b..086456c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /include /data /SaveImg +/tmp .vscode/launch.json diff --git a/AlgorithmModule/src/ALLImgCheckAnalysisy.cpp b/AlgorithmModule/src/ALLImgCheckAnalysisy.cpp index f8f96db..6f2a5de 100644 --- a/AlgorithmModule/src/ALLImgCheckAnalysisy.cpp +++ b/AlgorithmModule/src/ALLImgCheckAnalysisy.cpp @@ -351,22 +351,6 @@ int ALLImgCheckAnalysisy::GetUpdateParamOut(const std::string &strCamera, Update return 0; } - // 兜底: 缓存中没有时, 直接按相机名从参数模块实时取一次 - if (m_pConfigManager != nullptr) - { - auto itConfig = m_pConfigManager->Config_instances_.find(strCamera); - if (itConfig != m_pConfigManager->Config_instances_.end() && itConfig->second) - { - AnalysisyConfigST analysisyConfig; - if (itConfig->second->GetConfig(ConfigType_Analysisy_Common_XL, &analysisyConfig) == 0) - { - FillUpdateParamOut(analysisyConfig, outParam); - m_UpdateParamOutMap[strCamera] = outParam; - return 0; - } - } - } - return 1; } diff --git a/AlgorithmModule/src/CameraCheckAnalysisy.cpp b/AlgorithmModule/src/CameraCheckAnalysisy.cpp index f0495d1..842b128 100644 --- a/AlgorithmModule/src/CameraCheckAnalysisy.cpp +++ b/AlgorithmModule/src/CameraCheckAnalysisy.cpp @@ -1627,82 +1627,6 @@ int CameraCheckAnalysisy::GetLine(const cv::Mat &img, std::vector &po return 0; } -// 找到图像中产品(亮色区域)所在的第一行(顶部边缘), 用于左右图上下对齐 -// 从上往下逐行扫描, 当某一行亮像素数量超过阈值比例时, 认为该行是产品顶边 -int CameraCheckAnalysisy::GetProductFirstRow(const cv::Mat &img, int &outRow) -{ - outRow = -1; - if (img.empty()) - { - return 1; - } - - cv::Mat gray; - if (img.channels() == 1) - { - gray = img; - } - else if (img.channels() == 3) - { - cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY); - } - else - { - return 1; - } - - const uchar brightThreshold = 35; // 亮像素灰度阈值(与背景判断阈值保持一致) - const int needBrightCount = std::max(1, (int)(gray.cols * 0.02)); // 该行亮像素数量占比超过 20% 认为是产品所在行 - const int rowStep = 16; // 跳行扫描步长 - - // 判断某一行是否为产品所在行(亮像素数量达到阈值) - auto isProductRow = [&](int row) -> bool - { - const uchar *p = gray.ptr(row); - int brightCount = 0; - for (int col = 0; col < gray.cols; ++col) - { - if (p[col] >= brightThreshold) - { - if (++brightCount >= needBrightCount) - { - return true; - } - } - } - return false; - }; - - // 1、跳行粗扫: 每隔 rowStep 行扫描一次, 定位产品顶边的大致位置 - int rowFound = -1; - for (int row = 0; row < gray.rows; row += rowStep) - { - if (isProductRow(row)) - { - rowFound = row; - break; - } - } - - if (rowFound < 0) - { - return 2; // 未找到产品顶边 - } - - // 2、在上一个采样行与 rowFound 之间逐行精确定位 - int rowStart = std::max(0, rowFound - rowStep + 1); - for (int row = rowStart; row <= rowFound; ++row) - { - if (isProductRow(row)) - { - outRow = row; - return 0; - } - } - - return 2; // 理论上不会走到这里 -} - // 拟合图像中产品(亮色区域)的顶边直线段: 对顶边上的点做最小二乘拟合, 得到 y = k * x + b // 产品倾斜时顶边在每一列的高度不同, 用逐列顶边点拟合出的直线才能真正反映倾斜, // 左右两张图各拟合一条线段后, 就可以让它们在拼接缝处首尾相连。 @@ -1734,8 +1658,8 @@ int CameraCheckAnalysisy::FitProductTopLine(const cv::Mat &img, float &outK, flo return 1; } - const uchar brightThreshold = 45; // 亮像素灰度阈值(与背景判断阈值保持一致) - const int needBrightCount = std::max(1, (int)(gray.cols * 0.1)); // 该行亮像素数量占比超过 20% 认为是产品所在行 + const uchar brightThreshold = 35; // 亮像素灰度阈值(与背景判断阈值保持一致) + const int needBrightCount = std::max(1, (int)(gray.cols * 0.02)); // 该行亮像素数量占比超过 20% 认为是产品所在行 const int rowStep = 16; // 跳行扫描步长 // 判断某一行是否为产品所在行(亮像素数量达到阈值) diff --git a/AlgorithmModule/src/ImgCheckAnalysisy.cpp b/AlgorithmModule/src/ImgCheckAnalysisy.cpp index f8f3809..6707ddc 100644 --- a/AlgorithmModule/src/ImgCheckAnalysisy.cpp +++ b/AlgorithmModule/src/ImgCheckAnalysisy.cpp @@ -181,7 +181,7 @@ int ImgCheckAnalysisy::GetStatus() std::string ImgCheckAnalysisy::GetVersion() { - return std::string("BOE_1.2.1"); + return std::string("BOE_1.2.3"); } std::string ImgCheckAnalysisy::GetErrorInfo() @@ -702,6 +702,13 @@ int ImgCheckAnalysisy::Adapt_Config(Mat img, Rect cur_roi, cv::RotatedRect& rot_ // cv::line(show_img, cur_regionConfigArr[i].basicInfo.pointArry.back(), cur_regionConfigArr[i].basicInfo.pointArry.front(), Scalar(255,0,0), 10); // } // } + // if (cur_traditional_region.size() >= 2) + // { + // for(size_t i = 0 ; i < cur_traditional_region.size() - 1; i++){ + // cv::line(show_img, cur_traditional_region[i], cur_traditional_region[i+1], Scalar(0,0,255), 20); + // } + // cv::line(show_img, cur_traditional_region.back(), cur_traditional_region.front(), Scalar(0,0,255), 20); + // } // imwrite(m_AnalysisyConfig.commonCheckConfig.baseConfig.strCamearName +"_org_img.tiff", show_img); /*使用仿射矩阵进行修改*/ @@ -763,6 +770,13 @@ int ImgCheckAnalysisy::Adapt_Config(Mat img, Rect cur_roi, cv::RotatedRect& rot_ // cv::line(show_img, cur_regionConfigArr[i].basicInfo.pointArry.back(), cur_regionConfigArr[i].basicInfo.pointArry.front(), Scalar(255,0,0), 10); // } // } + // if (cur_traditional_region.size() >= 2) + // { + // for(size_t i = 0 ; i < cur_traditional_region.size() - 1; i++){ + // cv::line(show_img, cur_traditional_region[i], cur_traditional_region[i+1], Scalar(0,0,255), 20); + // } + // cv::line(show_img, cur_traditional_region.back(), cur_traditional_region.front(), Scalar(0,0,255), 20); + // } // imwrite(m_AnalysisyConfig.commonCheckConfig.baseConfig.strCamearName +"_show_img.tiff", show_img); return 0;