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.
213 lines
4.7 KiB
213 lines
4.7 KiB
/*
|
|
* @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 |