|
|
/*
|
|
|
* @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/Edge_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/Edge_QX_Det.h
|
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
|
*/
|
|
|
/*
|
|
|
//实现对部分缺陷 需要进行 数量 和距离上分析的
|
|
|
*/
|
|
|
#ifndef Edge_QX_Det_H_
|
|
|
#define Edge_QX_Det_H_
|
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
|
|
#include "CheckErrorCodeDefine.hpp"
|
|
|
#include "ImageDetConfig.h"
|
|
|
#include "CheckConfigDefine.h"
|
|
|
|
|
|
using namespace std;
|
|
|
using namespace cv;
|
|
|
|
|
|
// 边缘缺陷检测
|
|
|
class Edge_QX_Det
|
|
|
{
|
|
|
public:
|
|
|
// 搜索方向
|
|
|
enum Edge_DirectSign
|
|
|
{
|
|
|
DirectSign_UP,
|
|
|
DirectSign_DOWN,
|
|
|
DirectSign_Left,
|
|
|
DirectSign_Right,
|
|
|
};
|
|
|
// 搜索边缘了下,黑还是白
|
|
|
enum Search_Value_Type
|
|
|
{
|
|
|
Search_Value_White,
|
|
|
Search_Value_Black,
|
|
|
};
|
|
|
// 边缘搜索参数
|
|
|
struct Edge_Search_Config
|
|
|
{
|
|
|
cv::Rect roi; // 边缘搜索区域
|
|
|
Search_Value_Type searchValueType; // 搜索边缘了下,黑还是白
|
|
|
Edge_DirectSign directSign; // 搜索方向
|
|
|
int nValueThreshold; // 灰度阈值
|
|
|
int nSearchCount; // 搜索点的个数 把roi 均分成多少个点。
|
|
|
int nSearchrange; // 搜索范围,一般为单数,如果 1表示 搜索当前点,如果3表示 除了当前点,还有左右 点。5表示 从-2到2
|
|
|
int stepCount; // 每个搜索点的步数
|
|
|
int nLimit; // 连续搜索多个满足阈值的点后,停止搜索,当前搜索点 搜索成功。
|
|
|
std::string strchannel;
|
|
|
Edge_Search_Config()
|
|
|
{
|
|
|
roi = cv::Rect(0, 0, 0, 0);
|
|
|
directSign = DirectSign_UP;
|
|
|
searchValueType = Search_Value_White;
|
|
|
nValueThreshold = 40;
|
|
|
nSearchCount = 30;
|
|
|
nSearchrange = 1;
|
|
|
stepCount = 2;
|
|
|
nLimit = 3;
|
|
|
strchannel = "";
|
|
|
}
|
|
|
bool CheckConfigValid()
|
|
|
{
|
|
|
bool bRet = true;
|
|
|
if (roi.width <= 0 || roi.height <= 0)
|
|
|
{
|
|
|
printf("s1 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (searchValueType < Search_Value_White || searchValueType > Search_Value_Black)
|
|
|
{
|
|
|
printf("s2 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (directSign < 0 || directSign > 4)
|
|
|
{
|
|
|
printf("s3 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (nValueThreshold < 0 || nValueThreshold > 255)
|
|
|
{
|
|
|
printf("s4 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (nSearchCount < 0)
|
|
|
{
|
|
|
printf("s5 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (stepCount < 0)
|
|
|
{
|
|
|
printf("s6 \n");
|
|
|
return false;
|
|
|
}
|
|
|
if (nLimit < 0)
|
|
|
{
|
|
|
printf("s7 \n");
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
};
|
|
|
struct Line
|
|
|
{
|
|
|
cv::Point p1;
|
|
|
cv::Point p2;
|
|
|
Line()
|
|
|
{
|
|
|
p1 = cv::Point(0, 0);
|
|
|
p2 = cv::Point(0, 0);
|
|
|
}
|
|
|
};
|
|
|
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 Algin_Result
|
|
|
{
|
|
|
cv::Rect corpRoi;
|
|
|
int offtx;
|
|
|
int offty;
|
|
|
cv::Mat H;
|
|
|
Algin_Result()
|
|
|
{
|
|
|
Init();
|
|
|
}
|
|
|
void Init()
|
|
|
{
|
|
|
corpRoi = cv::Rect(0, 0, 0, 0);
|
|
|
offtx = 0;
|
|
|
offty = 0;
|
|
|
if (!H.empty())
|
|
|
{
|
|
|
H.release();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
/* data */
|
|
|
};
|
|
|
|
|
|
// 检测参数和结果
|
|
|
struct DetConfigResult
|
|
|
{
|
|
|
|
|
|
BaseCheckFunction *pBaseCheckFunction;
|
|
|
std::string strChannel;
|
|
|
std::vector<QX_Result> qx_result;
|
|
|
std::vector<Det_ROI_Config> edge_det_roi;
|
|
|
Algin_Result alginResult;
|
|
|
|
|
|
std::vector<cv::Point> Det_region;
|
|
|
bool bSaveResultImg;
|
|
|
DetConfigResult()
|
|
|
{
|
|
|
Init();
|
|
|
}
|
|
|
void Init()
|
|
|
{
|
|
|
pBaseCheckFunction = NULL;
|
|
|
strChannel = "";
|
|
|
qx_result.clear();
|
|
|
edge_det_roi.clear();
|
|
|
alginResult.Init();
|
|
|
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,
|
|
|
};
|
|
|
|
|
|
public:
|
|
|
bool GetSegmentIntersection(const Line &l1, const Line &l2, cv::Point2f &intersection);
|
|
|
Edge_QX_Det(/* args */);
|
|
|
~Edge_QX_Det();
|
|
|
|
|
|
int Detect(const cv::Mat &img, DetConfigResult *pDetConfig);
|
|
|
|
|
|
private:
|
|
|
// 边缘点搜索函数
|
|
|
int GetEdgePoint(const cv::Mat &img, Edge_Search_Config *pEdge_Search_Config, std::vector<cv::Point> &pointList);
|
|
|
|
|
|
int GetLine(const cv::Mat &img, std::vector<cv::Point> &pointList, int lineNum, int xory, std::vector<Line> &lineList);
|
|
|
|
|
|
// 检测缺陷
|
|
|
int Det_qx(const cv::Mat &img, std::vector<Det_ROI_Config> roilist, Det_ROI_Type type, DetConfigResult *pDetConfig);
|
|
|
|
|
|
int applyMaskInROI(const cv::Mat &grayImg, const Det_ROI_Config &config, cv::Mat &result, int threshold);
|
|
|
|
|
|
// 通过手绘的方式来检测
|
|
|
int Draw_Det(const cv::Mat &img, DetConfigResult *pDetConfig);
|
|
|
|
|
|
private:
|
|
|
/// @brief
|
|
|
/// @param img 搜到图片 单通道
|
|
|
/// @param DirectSign 搜索方向 >0 正向,< 0 反向
|
|
|
/// @param Gate 阈值
|
|
|
/// @param BorW 搜索黑点 = 0还是白点 = 1
|
|
|
/// @param roi 搜索范围
|
|
|
/// @param StepCount 搜索点数
|
|
|
/// @param Limit 最小满是阈值点个数算上搜索成功
|
|
|
/// @return <0 搜索错误, >=0表示 搜索位置
|
|
|
int UDNoiseEdgeDetect(cv::Mat img, int DirectSign, int Gate, int BorW, cv::Rect roi, int StepCount, int Limit);
|
|
|
/// @brief
|
|
|
/// @param img 搜到图片 单通道
|
|
|
/// @param DirectSign 搜索方向 >0 正向,< 0 反向
|
|
|
/// @param Gate 阈值
|
|
|
/// @param BorW 搜索黑点 = 0还是白点 = 1
|
|
|
/// @param roi 搜索范围
|
|
|
/// @param StepCount 搜索点数
|
|
|
/// @param Limit 最小满是阈值点个数算上搜索成功
|
|
|
/// @return <0 搜索错误, >=0表示 搜索位置
|
|
|
int LRNoiseEdgeDetect(cv::Mat img, int DirectSign, int Gate, int BorW, cv::Rect roi, int StepCount, int Limit);
|
|
|
// int LRNoiseEdgeDetect(cv::Mat img,int DirectSign, int Gate,int BorW, int StartSearchSite, int Step, int StepCount, int top, int bottom, int Limit, int Depth, int MaxLimit);
|
|
|
|
|
|
private:
|
|
|
cv::Mat showimg;
|
|
|
bool bshowimg;
|
|
|
|
|
|
private:
|
|
|
/* data */
|
|
|
};
|
|
|
|
|
|
#endif |