|
|
|
|
@ -212,9 +212,18 @@ int Edge_Search::Detect_AI(const cv::Mat &detimg, DetConfigResult *pDetConfig, s
|
|
|
|
|
int Edge_Search::Detect_Draw(const cv::Mat &detimg, DetConfigResult *pDetConfig, std::shared_ptr<EdgeDetResult> &pEdgeDetResult)
|
|
|
|
|
{
|
|
|
|
|
Function_EdgeROI *pEdgeROI = pDetConfig->pEdgeROI;
|
|
|
|
|
cv::Mat paraMaskImg = pEdgeROI->EdgeMask;
|
|
|
|
|
cv::Mat paraMaskImg = pEdgeROI->EdgeMask.clone();
|
|
|
|
|
bool bsucc = false;
|
|
|
|
|
cv::Rect roi;
|
|
|
|
|
if (pDetConfig)
|
|
|
|
|
{
|
|
|
|
|
for (auto p:pDetConfig->pEdgeROI->pointArry1)
|
|
|
|
|
{
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_3, "Detect_Draw", "pointArry1: %d , %d", p.x, p.y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!paraMaskImg.empty())
|
|
|
|
|
{
|
|
|
|
|
if (pDetConfig->bDebugsaveImg)
|
|
|
|
|
@ -228,27 +237,36 @@ int Edge_Search::Detect_Draw(const cv::Mat &detimg, DetConfigResult *pDetConfig,
|
|
|
|
|
pEdgeDetResult->shieldMask_Src = paraMaskImg;
|
|
|
|
|
// m_DetEdge.detmask = paraMaskImg;
|
|
|
|
|
// 查找轮廓
|
|
|
|
|
std::vector<std::vector<cv::Point>> contours;
|
|
|
|
|
std::vector<cv::Vec4i> hierarchy;
|
|
|
|
|
cv::findContours(paraMaskImg, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
|
|
|
|
|
// std::vector<std::vector<cv::Point>> contours;
|
|
|
|
|
// std::vector<cv::Vec4i> hierarchy;
|
|
|
|
|
// cv::findContours(paraMaskImg.clone(), contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
|
|
|
|
|
|
|
|
|
|
// 找到最大轮廓
|
|
|
|
|
int max_contour_index = -1;
|
|
|
|
|
double max_area = 0;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < contours.size(); i++)
|
|
|
|
|
// for (size_t i = 0; i < contours.size(); i++)
|
|
|
|
|
// {
|
|
|
|
|
// double area = cv::contourArea(contours[i]);
|
|
|
|
|
// if (area > max_area)
|
|
|
|
|
// {
|
|
|
|
|
// max_area = area;
|
|
|
|
|
// max_contour_index = i;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
if(pDetConfig->pEdgeROI->pointArry1.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
double area = cv::contourArea(contours[i]);
|
|
|
|
|
if (area > max_area)
|
|
|
|
|
// roi = cv::boundingRect(contours[max_contour_index]);
|
|
|
|
|
roi = cv::boundingRect(pDetConfig->pEdgeROI->pointArry1);
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_3, "Detect_Draw", "ROI %d %d %d %d", roi.x, roi.y, roi.width, roi.height);
|
|
|
|
|
if(CheckUtil::JudgRect(roi, pEdgeROI->EdgeMask.cols, pEdgeROI->EdgeMask.rows))
|
|
|
|
|
{
|
|
|
|
|
max_area = area;
|
|
|
|
|
max_contour_index = i;
|
|
|
|
|
bsucc = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_3, "Detect_Draw", "Error DrMaskImg Get roi out of range");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (max_contour_index >= 0)
|
|
|
|
|
{
|
|
|
|
|
roi = cv::boundingRect(contours[max_contour_index]);
|
|
|
|
|
bsucc = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|