You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.9 KiB
88 lines
2.9 KiB
|
|
#include "Pin_QX_Det.h"
|
|
#include "CheckUtil.hpp"
|
|
#include <numeric>
|
|
#include <random>
|
|
#include "CheckErrorCodeDefine.hpp"
|
|
|
|
Pin_QX_Det::Pin_QX_Det(std::shared_ptr<DetLog> &log_ref)
|
|
: m_pdetlog(log_ref)
|
|
{
|
|
std::string m_strSavePath;
|
|
AI_Factory = AIFactory::GetInstance();
|
|
m_strLastDate = "";
|
|
m_strRootPath_Pin = "/home/aidlux/BOE/Algin/Pin/";
|
|
m_pImageStorage = ImageStorage::getInstance();
|
|
creatsavedir();
|
|
}
|
|
Pin_QX_Det::~Pin_QX_Det()
|
|
{
|
|
}
|
|
|
|
int Pin_QX_Det::GetPinMask(const cv::Mat &img, DetConfigResult *pDetConfig, Mat &mask)
|
|
{
|
|
std::shared_ptr<AIModel_Base> pSocket_Pin;
|
|
pSocket_Pin = AI_Factory->Pin_Loc;
|
|
cv::Size sz;
|
|
sz.width = pSocket_Pin->input_0.width;
|
|
sz.height = pSocket_Pin->input_0.height;
|
|
cv::Mat detImg;
|
|
cout<< pDetConfig->strChannel << ": " << "---Pin---";
|
|
cout << "imgSize: " << img.size() << ", " << "detImgSize: " << detImg.size() << ", " << "szSize: " << sz << endl;
|
|
|
|
cv::resize(img, detImg, sz);
|
|
// 存图用: 通道转换(灰度化)之前的模型输入图(未开启存图时不克隆, 节省时间/内存)
|
|
cv::Mat saveInImg;
|
|
if (pDetConfig->pBaseCheckFunction != NULL && pDetConfig->pBaseCheckFunction->saveImg.bSavePinImg)
|
|
{
|
|
saveInImg = detImg.clone();
|
|
}
|
|
int re = 0;
|
|
if (detImg.channels() != 1)
|
|
{
|
|
cv::cvtColor(detImg, detImg, cv::COLOR_RGB2GRAY);
|
|
}
|
|
|
|
re = pSocket_Pin->AIDet(detImg, mask);
|
|
if (re != 0)
|
|
{
|
|
m_pdetlog->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AI_Pin ", "AICheck_Pin----error %d ", re);
|
|
int re123 = 100 + re;
|
|
return re123;
|
|
}
|
|
|
|
// 参数 Align_Pin_Save 打开时, 保存Pin脚定位模型的输入/输出图(异步存图, 不阻塞检测)
|
|
// 输入图存未做通道转化(灰度化)之前的图; 文件名首位用产品ID
|
|
if (pDetConfig->pBaseCheckFunction != NULL && pDetConfig->pBaseCheckFunction->saveImg.bSavePinImg)
|
|
{
|
|
creatsavedir();
|
|
std::string str = m_strSavePath_Pin + pDetConfig->strProductID + "_" + pDetConfig->strChannel + "_pin_in.png";
|
|
int sr = m_pImageStorage->addImage(str, saveInImg);
|
|
if (sr == 0)
|
|
{
|
|
str = m_strSavePath_Pin + pDetConfig->strProductID + "_" + pDetConfig->strChannel + "_pin_out_mask.png";
|
|
m_pImageStorage->addImage(str, mask, true);
|
|
}
|
|
}
|
|
|
|
if (pDetConfig->bSaveResultImg)
|
|
{
|
|
cv::imwrite(pDetConfig->strChannel +"_pin_" +"in.png", detImg);
|
|
cv::imwrite(pDetConfig->strChannel +"_pin_" +"out_mask.png", mask);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int Pin_QX_Det::creatsavedir()
|
|
{
|
|
std::string curDate = CheckUtil::getCurrentDate();
|
|
if (curDate == m_strLastDate)
|
|
{
|
|
return 0;
|
|
}
|
|
m_strLastDate = curDate;
|
|
m_strSavePath_Pin = m_strRootPath_Pin + curDate + "/";
|
|
CheckUtil::CreateDir(m_strSavePath_Pin);
|
|
return 0;
|
|
} |