parent
7864359af2
commit
dad094bf0a
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-08-04 21:26:32
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-08-13 16:05:08
|
||||
* @FilePath: /BOE_CELL_AOI/AlgorithmModule/include/Pin_QX_Det.h
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-08-04 21:26:32
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-08-04 21:29:05
|
||||
* @FilePath: /BOE_CELL_AOI/AlgorithmModule/include/Pin_QX_Det.h
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
/*
|
||||
//实现对部分缺陷 需要进行 数量 和距离上分析的
|
||||
*/
|
||||
#ifndef Pin_QX_Det_H_
|
||||
#define Pin_QX_Det_H_
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "CheckUtil.hpp"
|
||||
#include "OtherDetBaseDefine.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "ImageDetConfig.h"
|
||||
#include "CheckConfigDefine.h"
|
||||
#include "ImageStorage.h"
|
||||
#include "AI_Factory.h"
|
||||
#include "DetLog.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
// Pin脚缺陷检测
|
||||
class Pin_QX_Det
|
||||
{
|
||||
public:
|
||||
struct QX_Result
|
||||
{
|
||||
cv::Rect roi_src;
|
||||
int area_pixel;
|
||||
QX_Result()
|
||||
{
|
||||
roi_src = cv::Rect(0, 0, 0, 0);
|
||||
area_pixel = 0;
|
||||
}
|
||||
};
|
||||
struct Det_ROI_Config
|
||||
{
|
||||
cv::Rect roi;
|
||||
std::vector<cv::Point> plist;
|
||||
};
|
||||
// 检测参数和结果
|
||||
struct DetConfigResult
|
||||
{
|
||||
|
||||
BaseCheckFunction *pBaseCheckFunction;
|
||||
std::string strChannel;
|
||||
std::vector<QX_Result> qx_result;
|
||||
std::vector<Det_ROI_Config> pin_det_roi;
|
||||
|
||||
std::vector<cv::Point> Det_region;
|
||||
bool bSaveResultImg;
|
||||
DetConfigResult()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
pBaseCheckFunction = NULL;
|
||||
strChannel = "";
|
||||
qx_result.clear();
|
||||
pin_det_roi.clear();
|
||||
Det_region.clear();
|
||||
bSaveResultImg = false;
|
||||
}
|
||||
};
|
||||
|
||||
enum Det_ROI_Type
|
||||
{
|
||||
Det_ROI_Type_UP,
|
||||
Det_ROI_Type_DOWN,
|
||||
Det_ROI_Type_LEFT,
|
||||
Det_ROI_Type_RIGHT,
|
||||
};
|
||||
|
||||
// 边缘搜索定位结果
|
||||
struct Pin_AI_Result
|
||||
{
|
||||
int nresult;
|
||||
cv::RotatedRect bigroi;
|
||||
cv::RotatedRect smallroi;
|
||||
bool buseOfft;
|
||||
int offt_x;
|
||||
int offt_y;
|
||||
cv::Mat H;
|
||||
|
||||
Pin_AI_Result()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
buseOfft = false;
|
||||
nresult = 0;
|
||||
offt_x = 0;
|
||||
offt_y = 0;
|
||||
bigroi = cv::RotatedRect(cv::Point2f(0, 0), cv::Size2f(0, 0), 0);
|
||||
smallroi = cv::RotatedRect(cv::Point2f(0, 0), cv::Size2f(0, 0), 0);
|
||||
if (!H.empty())
|
||||
{
|
||||
H.release();
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
enum SaveProcessType
|
||||
{
|
||||
Save_Close, // 不保存
|
||||
Save_Filter, // 过滤的
|
||||
Save_ALL, // 全部
|
||||
};
|
||||
struct DetConfig
|
||||
{
|
||||
int ncamId; // 相机ID
|
||||
BaseCheckFunction *pBaseCheckFunction;
|
||||
std::string strChannel; // 通道
|
||||
int nthresholdvalue; // 背景阈值
|
||||
int nAIErodesize; // 边缘腐蚀强度
|
||||
bool bSaveResultImg; // 保存结果图片
|
||||
SaveProcessType saveProcessImg; // 保存过程图片
|
||||
bool bUseDrawRoi_Check; // 是否用绘制的ROI进行校验
|
||||
cv::Rect drawRoi; // 绘制的 ROi;
|
||||
cv::Mat drawMask; // 绘制的maksk
|
||||
DetConfig()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
pBaseCheckFunction = NULL;
|
||||
ncamId = 0;
|
||||
nthresholdvalue = 1;
|
||||
nAIErodesize = 7;
|
||||
bSaveResultImg = false;
|
||||
saveProcessImg = Save_Close;
|
||||
bUseDrawRoi_Check = false;
|
||||
drawRoi = cv::Rect(0, 0, 0, 0);
|
||||
if (!drawMask.empty())
|
||||
{
|
||||
drawMask.release();
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
void Print()
|
||||
{
|
||||
printf("nthresholdvalue:%d;nAIErodesize %d;bSaveResultImg %s SaveProcessImg %d\n",
|
||||
nthresholdvalue, nAIErodesize, BOOL_TO_STR(bSaveResultImg), saveProcessImg);
|
||||
|
||||
printf("bUseDrawRoi_Check %s roi %s \n",
|
||||
BOOL_TO_STR(bUseDrawRoi_Check), CheckUtil::GetRectString(drawRoi).c_str());
|
||||
}
|
||||
bool IsSaveProcessImg()
|
||||
{
|
||||
if (saveProcessImg != Save_Close)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
Pin_QX_Det(std::shared_ptr<DetLog>& log_ref);
|
||||
~Pin_QX_Det();
|
||||
|
||||
int Detect(const cv::Mat &img, DetConfigResult *pDetConfig);
|
||||
|
||||
private:
|
||||
int InitModel_Pin();
|
||||
int creatsavedir();
|
||||
|
||||
private:
|
||||
bool m_bInitSucc; // 是否初始化成功
|
||||
// 检测结果
|
||||
std::shared_ptr<Pin_AI_Result> m_pCheckResult_Pin;
|
||||
|
||||
std::shared_ptr<DetLog>& m_pdetlog;
|
||||
|
||||
bool m_bInitialized;
|
||||
bool m_bModelSucc;
|
||||
bool m_bModel_Mark_Succ;
|
||||
|
||||
bool m_bshowimg;
|
||||
cv::Mat showimg;
|
||||
std::string m_strRootPath_Pin;
|
||||
std::string m_strSavePath_Pin;
|
||||
std::string m_strLastDate;
|
||||
|
||||
ImageStorage *m_pImageStorage;
|
||||
|
||||
std::shared_ptr<AIFactory> AI_Factory;
|
||||
|
||||
private:
|
||||
/* data */
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,97 @@
|
||||
|
||||
#include "Pin_QX_Det.h"
|
||||
#include "CheckUtil.hpp"
|
||||
#include <numeric>
|
||||
#include <random>
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Pin_QX_Det::Pin_QX_Det(std::shared_ptr<DetLog> &log_ref)
|
||||
: m_pdetlog(log_ref)
|
||||
{
|
||||
m_bInitialized = false;
|
||||
m_bModelSucc = false;
|
||||
m_bModel_Mark_Succ = false;
|
||||
m_bshowimg = false;
|
||||
m_strRootPath_Pin = "/home/aidlux/BOE/Pin/";
|
||||
creatsavedir();
|
||||
std::string m_strSavePath;
|
||||
|
||||
m_pImageStorage = ImageStorage::getInstance();
|
||||
AI_Factory = AIFactory::GetInstance();
|
||||
}
|
||||
Pin_QX_Det::~Pin_QX_Det()
|
||||
{
|
||||
}
|
||||
int Pin_QX_Det::Detect(const cv::Mat &img, DetConfigResult *pDetConfig)
|
||||
{
|
||||
// if (!pDetConfig->pBaseCheckFunction->edgeDet.bOpen)
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
m_bshowimg = false;
|
||||
if (pDetConfig->bSaveResultImg)
|
||||
{
|
||||
m_bshowimg = true;
|
||||
}
|
||||
|
||||
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;
|
||||
cv::Mat mask;
|
||||
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_Edge_Algin ", "AICheck_Edge----error %d ", re);
|
||||
int re123 = 100 + re;
|
||||
return re123;
|
||||
}
|
||||
|
||||
if (pDetConfig->pBaseCheckFunction->saveImg.bSaveAlginImg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (pDetConfig->bSaveResultImg)
|
||||
{
|
||||
cv::imwrite(pDetConfig->strChannel +"_pin_" +"in.png", detImg);
|
||||
cv::imwrite(pDetConfig->strChannel +"_pin_" +"out_mask.png", mask);
|
||||
}
|
||||
|
||||
if (m_bshowimg)
|
||||
{
|
||||
cv::cvtColor(img, showimg, cv::COLOR_GRAY2BGR);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in new issue