|
|
|
|
@ -9,6 +9,7 @@
|
|
|
|
|
|
|
|
|
|
#include "AI_Edge_Algin.h"
|
|
|
|
|
#include "CheckErrorCodeDefine.hpp"
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
#define EDGE_GPU 0
|
|
|
|
|
|
|
|
|
|
@ -231,8 +232,10 @@ int AI_Edge_Algin::Detect(const cv::Mat &img, DetConfig *pDetConfig, std::shared
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1、初步定位 找到产品大致区域
|
|
|
|
|
int re = 0;
|
|
|
|
|
// 1、初步定位 找到产品大致区域(三个模型输入输出尺寸不同,各自 resize;推理相互独立,并行执行)
|
|
|
|
|
int re0 = 0;
|
|
|
|
|
int re1 = 0;
|
|
|
|
|
int re2 = 0;
|
|
|
|
|
|
|
|
|
|
std::vector<cv::RotatedRect> Big_roi;
|
|
|
|
|
std::vector<cv::RotatedRect> Small_roi;
|
|
|
|
|
@ -241,35 +244,41 @@ int AI_Edge_Algin::Detect(const cv::Mat &img, DetConfig *pDetConfig, std::shared
|
|
|
|
|
cv::Mat Small_outimg;
|
|
|
|
|
cv::Mat Tag_outimg;
|
|
|
|
|
|
|
|
|
|
re = Get_Edge(0, img, pDetConfig, m_pDetConfig->strChannel, Big_roi, Big_outimg);
|
|
|
|
|
if (re != 0)
|
|
|
|
|
std::vector<std::thread> vecThreads;
|
|
|
|
|
vecThreads.emplace_back([&]() { re0 = Get_Edge(0, img, pDetConfig, m_pDetConfig->strChannel, Big_roi, Big_outimg, true); });
|
|
|
|
|
vecThreads.emplace_back([&]() { re1 = Get_Edge(1, img, pDetConfig, m_pDetConfig->strChannel, Small_roi, Small_outimg, false); });
|
|
|
|
|
vecThreads.emplace_back([&]() { re2 = Get_Edge(2, img, pDetConfig, m_pDetConfig->strChannel, Tag_roi, Tag_outimg, false); });
|
|
|
|
|
for (auto &t : vecThreads)
|
|
|
|
|
{
|
|
|
|
|
t.join();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (re0 != 0)
|
|
|
|
|
{
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, "AI_Edge_Algin ", "AICheck_Edge_Big----error %d ", re);
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, "AI_Edge_Algin ", "AICheck_Edge_Big----error %d ", re0);
|
|
|
|
|
if (m_pDetConfig->IsSaveProcessImg())
|
|
|
|
|
{
|
|
|
|
|
cv::imwrite(str_error, img);
|
|
|
|
|
}
|
|
|
|
|
return re;
|
|
|
|
|
return re0;
|
|
|
|
|
}
|
|
|
|
|
re = Get_Edge(1, img, pDetConfig, m_pDetConfig->strChannel, Small_roi, Small_outimg);
|
|
|
|
|
if (re != 0)
|
|
|
|
|
if (re1 != 0)
|
|
|
|
|
{
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, "AI_Edge_Algin ", "AICheck_Edge_Small----error %d ", re);
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, "AI_Edge_Algin ", "AICheck_Edge_Small----error %d ", re1);
|
|
|
|
|
if (m_pDetConfig->IsSaveProcessImg())
|
|
|
|
|
{
|
|
|
|
|
cv::imwrite(str_error, img);
|
|
|
|
|
}
|
|
|
|
|
return re;
|
|
|
|
|
return re1;
|
|
|
|
|
}
|
|
|
|
|
re = Get_Edge(2, img, pDetConfig, m_pDetConfig->strChannel, Tag_roi, Tag_outimg);
|
|
|
|
|
if (re != 0)
|
|
|
|
|
if (re2 != 0)
|
|
|
|
|
{
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, "AI_Edge_Algin ", "AICheck_Tag----error %d ", re);
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, "AI_Edge_Algin ", "AICheck_Tag----error %d ", re2);
|
|
|
|
|
if (m_pDetConfig->IsSaveProcessImg())
|
|
|
|
|
{
|
|
|
|
|
cv::imwrite(str_error, img);
|
|
|
|
|
}
|
|
|
|
|
return re;
|
|
|
|
|
return re2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pCheckResult_Aling->bigroi = Big_roi;
|
|
|
|
|
@ -348,7 +357,7 @@ int AI_Edge_Algin::InitModel_ALL()
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AI_Edge_Algin::Get_Edge(int AIModel_type, const cv::Mat &img, DetConfig *pDetConfig, std::string strChannel, std::vector<cv::RotatedRect> &RoiList, Mat &outmask)
|
|
|
|
|
int AI_Edge_Algin::Get_Edge(int AIModel_type, const cv::Mat &img, DetConfig *pDetConfig, std::string strChannel, std::vector<cv::RotatedRect> &RoiList, Mat &outmask, bool bResizeOut)
|
|
|
|
|
{
|
|
|
|
|
std::shared_ptr<AIModel_Base> pBackPlate_Align;
|
|
|
|
|
switch (AIModel_type)
|
|
|
|
|
@ -370,8 +379,8 @@ int AI_Edge_Algin::Get_Edge(int AIModel_type, const cv::Mat &img, DetConfig *pDe
|
|
|
|
|
sz.width = pBackPlate_Align->input_0.width;
|
|
|
|
|
sz.height = pBackPlate_Align->input_0.height;
|
|
|
|
|
cv::Mat detImg;
|
|
|
|
|
cout<< pDetConfig->strChannel << ": " << "---Get_Edge-resize-" << to_string(AIModel_type) <<"-- ";
|
|
|
|
|
cout << "imgSize: " << img.size() << ", " << "detImgSize: " << detImg.size() << ", " << "szSize: " << sz << endl;
|
|
|
|
|
// cout<< pDetConfig->strChannel << ": " << "---Get_Edge-resize-" << to_string(AIModel_type) <<"-- ";
|
|
|
|
|
// cout << "imgSize: " << img.size() << ", " << "detImgSize: " << detImg.size() << ", " << "szSize: " << sz << endl;
|
|
|
|
|
|
|
|
|
|
cv::resize(img, detImg, sz);
|
|
|
|
|
int re = 0;
|
|
|
|
|
@ -413,8 +422,15 @@ int AI_Edge_Algin::Get_Edge(int AIModel_type, const cv::Mat &img, DetConfig *pDe
|
|
|
|
|
cv::imwrite(strChannel +"_edge_"+ to_string(AIModel_type) +"_in.png", detImg);
|
|
|
|
|
cv::imwrite(strChannel +"_edge_"+ to_string(AIModel_type) +"_out_mask.png", mask);
|
|
|
|
|
}
|
|
|
|
|
// resize out_mask并返回
|
|
|
|
|
// resize out_mask并返回(仅大轮廓 mask 需要原图尺寸,后续用于把手检测;其余保持小图)
|
|
|
|
|
if (bResizeOut)
|
|
|
|
|
{
|
|
|
|
|
cv::resize(mask, outmask, img.size());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
outmask = mask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查模型输入尺寸
|
|
|
|
|
if (sz.width <= 0 || sz.height <= 0)
|
|
|
|
|
|