fix 传统检测resize回原图尺寸

dev_lsy
liusiyang 1 month ago
parent ac5c51758c
commit e16100f205

@ -312,6 +312,13 @@ cv::Scalar ImgCheckAnalysisy::calc_blob_info_withstats(cv::Mat &img, const cv::M
// 计算感兴趣区域 (ROI) // 计算感兴趣区域 (ROI)
cv::Rect roi(x - expand, y - expand, w + 2 * expand, h + 2 * expand); cv::Rect roi(x - expand, y - expand, w + 2 * expand, h + 2 * expand);
roi &= cv::Rect(0, 0, img.cols, img.rows); // 确保ROI在图像内 roi &= cv::Rect(0, 0, img.cols, img.rows); // 确保ROI在图像内
roi &= cv::Rect(0, 0, mask.cols, mask.rows); // 确保ROI在mask内
// 检查 mask 是否有效
if (mask.empty() || roi.width <= 0 || roi.height <= 0)
{
return cv::Scalar(0, 0, 0);
}
cv::Mat cimg = img(roi); cv::Mat cimg = img(roi);
@ -846,6 +853,18 @@ int ImgCheckAnalysisy::CalBlob_Other()
m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, "CalBlob_Other", " Start"); m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, "CalBlob_Other", " Start");
// 检查 detImg 和 AIMaskImg 是否为空
if (m_pImageAllResult->detImg.empty())
{
m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, "CalBlob_Other", " detImg is empty, return");
return -1;
}
if (m_pImageAllResult->AIMaskImg.empty())
{
m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, "CalBlob_Other", " AIMaskImg is empty, return");
return -1;
}
float fs_x = m_fImgage_Scale_X; float fs_x = m_fImgage_Scale_X;
float fs_y = m_fImgage_Scale_Y; float fs_y = m_fImgage_Scale_Y;
@ -1631,7 +1650,7 @@ int ImgCheckAnalysisy::Traditional_Detect_Thread(const cv::Mat &img, cv::Mat &Re
bTcsInited = true; bTcsInited = true;
} }
// 调用传统检测:输出残点二值图 // 调用传统检测:输出残点二值图(已内部完成 crop+resize 反向映射,与 img 同尺寸)
int ret = m_tcsCheck.TraditionalDetect(img, ResultImg); int ret = m_tcsCheck.TraditionalDetect(img, ResultImg);
if (ret != 0) if (ret != 0)
{ {

@ -351,6 +351,38 @@ int CTcsCheck::TraditionalDetect(const cv::Mat& img, cv::Mat& blobImg)
m_matBlob = AdaptiveBinary(m_matBlur); m_matBlob = AdaptiveBinary(m_matBlur);
blobImg = m_matBlob.clone(); blobImg = m_matBlob.clone();
// 7. 反向映射:将 crop+resize 后的残点图恢复为原始输入图尺寸
// 调用方拿到的是与输入 img 同尺寸的 mask坐标体系一致
if (m_cpCfg.fZoomRatio > 0)
{
// 7a. 反向映射 blobImg二值 mask用 INTER_NEAREST
{
cv::Mat matCropSize;
cv::resize(blobImg, matCropSize, cv::Size(rtCrop.width, rtCrop.height), 0, 0, cv::INTER_NEAREST);
cv::Mat fullMask = cv::Mat::zeros(m_matLoad.size(), CV_8UC1);
matCropSize.copyTo(fullMask(rtCrop));
blobImg = fullMask;
}
// 7b. 同步反向映射 m_matBlur灰度图供 TraditionalClassify 使用,用 INTER_LINEAR
{
cv::Mat matCropSize;
cv::resize(m_matBlur, matCropSize, cv::Size(rtCrop.width, rtCrop.height), 0, 0, cv::INTER_LINEAR);
cv::Mat fullBlur = cv::Mat::zeros(m_matLoad.size(), m_matBlur.type());
matCropSize.copyTo(fullBlur(rtCrop));
m_matBlur = fullBlur;
}
// 7c. 同步反向映射 m_matBlob二值 mask用 INTER_NEAREST
{
cv::Mat matCropSize;
cv::resize(m_matBlob, matCropSize, cv::Size(rtCrop.width, rtCrop.height), 0, 0, cv::INTER_NEAREST);
cv::Mat fullBlob = cv::Mat::zeros(m_matLoad.size(), CV_8UC1);
matCropSize.copyTo(fullBlob(rtCrop));
m_matBlob = fullBlob;
}
}
return 0; return 0;
} }

Loading…
Cancel
Save