更新除穿孔算法,提高效能;BUG-711

This commit is contained in:
yangjiaxuan 2023-12-08 15:33:47 +08:00
parent bb4b577f14
commit d8ade4c912
2 changed files with 27 additions and 10 deletions

View File

@ -84,6 +84,27 @@ void CImageApplyOutHole::apply(std::vector<cv::Mat>& mats, bool isTwoSide)
back = mats[1];
}
cv::Mat thumbnail;
cv::resize(front, thumbnail, cv::Size(200, 200));
cv::Scalar color_front = hg::getBackGroundColor(thumbnail, cv::Mat(), 20);
if (color_front[1] == 0)
if (color_front[0] < m_threshold)
return;
if (color_front[1] != 0)
if ((color_front[0] + color_front[1] + color_front[2]) < m_threshold * 3)
return;
cv::resize(back, thumbnail, cv::Size(200, 200));
cv::Scalar color_back = hg::getBackGroundColor(thumbnail, cv::Mat(), 20);
if (color_back[1] == 0)
if (color_back[0] < m_threshold)
return;
if (color_back[1] != 0)
if ((color_back[0] + color_back[1] + color_back[2]) < m_threshold * 3)
return;
cv::Mat front_thre, back_thre;
hg::threshold_Mat(front, front_thre, m_threshold);
hg::threshold_Mat(back, back_thre, m_threshold);
@ -177,9 +198,6 @@ void CImageApplyOutHole::apply(std::vector<cv::Mat>& mats, bool isTwoSide)
for (size_t j = 0; j < hole_contours[i].size(); j++)
hole_contours[i][j] /= resize_scale;
cv::Mat thumbnail;
cv::resize(front(roi_front), thumbnail, cv::Size(200, 200));
cv::Scalar color = hg::getBackGroundColor(thumbnail, cv::Mat(), m_threshold);
roi_front.x /= resize_scale;
roi_front.y /= resize_scale;
roi_front.width /= resize_scale;
@ -187,10 +205,10 @@ void CImageApplyOutHole::apply(std::vector<cv::Mat>& mats, bool isTwoSide)
for (size_t i = 0; i < hole_contours.size(); i++)
{
std::vector<std::vector<cv::Point>> contourss_temp;
dilateContour(hole_contours[i], m_borderSize / 4);
dilateContour(hole_contours[i], cv::max(m_borderSize / 2, 5.0f));
contourss_temp.push_back(hole_contours[i]);
cv::Mat front_temp = mats[0](roi_front);
hg::fillPolys(front_temp, contourss_temp, color);
hg::fillPolys(front_temp, contourss_temp, color_front);
}
if (isTwoSide)
@ -198,8 +216,6 @@ void CImageApplyOutHole::apply(std::vector<cv::Mat>& mats, bool isTwoSide)
int width_ = roi_back.width;
roi_back.x = back.cols - roi_back.width - roi_back.x; //因为之前反面图像翻转所以现在ROI也要进行相应翻转
cv::resize(back(roi_back), thumbnail, cv::Size(200, 200));
color = hg::getBackGroundColor(thumbnail, cv::Mat(), m_threshold);
roi_back.x /= resize_scale;
roi_back.y /= resize_scale;
roi_back.width /= resize_scale;
@ -217,10 +233,10 @@ void CImageApplyOutHole::apply(std::vector<cv::Mat>& mats, bool isTwoSide)
}
std::vector<std::vector<cv::Point>> contours_temp;
dilateContour(hole_contour, m_borderSize / 4);
dilateContour(hole_contour, cv::max(m_borderSize / 2, 5.0f));
contours_temp.push_back(hole_contour);
cv::Mat back_temp = mats[1](roi_back);
hg::fillPolys(back_temp, contours_temp, color);
hg::fillPolys(back_temp, contours_temp, color_back);
}
}
#ifdef LOG

View File

@ -29,7 +29,8 @@
* v1.10 2023/11/18
* v1.10.1 2023/11/28 kSize根据borderSize调整
* v1.11 2023/12/02 稿
* v1.11
* v1.11.1 2023/12/08 稿<;
* v1.11.1
* ====================================================
*/