fix paraMaskImg添加clone

main
liusiyang 3 weeks ago
parent c61729e2e0
commit 494d0da8f7

@ -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) int Edge_Search::Detect_Draw(const cv::Mat &detimg, DetConfigResult *pDetConfig, std::shared_ptr<EdgeDetResult> &pEdgeDetResult)
{ {
Function_EdgeROI *pEdgeROI = pDetConfig->pEdgeROI; Function_EdgeROI *pEdgeROI = pDetConfig->pEdgeROI;
cv::Mat paraMaskImg = pEdgeROI->EdgeMask; cv::Mat paraMaskImg = pEdgeROI->EdgeMask.clone();
bool bsucc = false; bool bsucc = false;
cv::Rect roi; 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 (!paraMaskImg.empty())
{ {
if (pDetConfig->bDebugsaveImg) if (pDetConfig->bDebugsaveImg)
@ -228,27 +237,36 @@ int Edge_Search::Detect_Draw(const cv::Mat &detimg, DetConfigResult *pDetConfig,
pEdgeDetResult->shieldMask_Src = paraMaskImg; pEdgeDetResult->shieldMask_Src = paraMaskImg;
// m_DetEdge.detmask = paraMaskImg; // m_DetEdge.detmask = paraMaskImg;
// 查找轮廓 // 查找轮廓
std::vector<std::vector<cv::Point>> contours; // std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy; // std::vector<cv::Vec4i> hierarchy;
cv::findContours(paraMaskImg, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE); // cv::findContours(paraMaskImg.clone(), contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
// 找到最大轮廓 // 找到最大轮廓
int max_contour_index = -1; int max_contour_index = -1;
double max_area = 0; 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]); // roi = cv::boundingRect(contours[max_contour_index]);
if (area > max_area) 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; bsucc = true;
max_contour_index = i; }
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 else
{ {

@ -170,7 +170,7 @@ int ImgCheckAnalysisy::GetStatus()
std::string ImgCheckAnalysisy::GetVersion() std::string ImgCheckAnalysisy::GetVersion()
{ {
return std::string("BOE_1.7.51"); return std::string("BOE_1.2.0");
} }
std::string ImgCheckAnalysisy::GetErrorInfo() std::string ImgCheckAnalysisy::GetErrorInfo()

Loading…
Cancel
Save