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.

81 lines
2.7 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);
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)
{
// 前缀用日期(年月日): 同一产品当天的所有图前缀一致; 文件已存在时在日期后追加序号, 不覆盖旧图
std::string strDatePre = CheckUtil::getCurrentDateYMD();
std::string strSaveDir = "/home/aidlux/BOE/AI_Detect/" + pDetConfig->strProductID + "/KK/";
std::string strName = pDetConfig->strChannel + "_pin_out";
std::string strSavePath_out = CheckUtil::GetUniqueImgPath(strSaveDir, strDatePre, strName, ".png");
CheckUtil::SaveImgAsync(strSavePath_out, mask);
}
if (pDetConfig->bSaveResultImg)
{
CheckUtil::SaveImgAsync(pDetConfig->strChannel +"_pin_" +"in.png", detImg);
CheckUtil::SaveImgAsync(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;
}