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.

652 lines
13 KiB

/*
* @Descripttion:
* @version:
* @Author: sueRimn
* @Date: 2022-03-16 17:09:11
* @LastEditors: xiewenji 527774126@qq.com
* @LastEditTime: 2025-07-26 11:21:59
*/
/***********************************************/
/************ ***************/
/************金佰利检测算法参数定义**************/
/************ **************/
/**********************************************/
#ifndef _ImgCheckConfig_HPP_
#define _ImgCheckConfig_HPP_
#include <string>
#include <opencv2/opencv.hpp>
#define RESULT_VERSION 26
#define MAX_BLOB_NUM 200
// 输入模型图片尺寸
#define SRCIMG_WIDTH 14200
#define SRCIMG_HEIGHT 10640
#define CHECKIMG_HEIGHT 2000
#define CHECKIMG_WIDTH 4000
#define MASK_IMG_STEP 16
#define MASK_IMG_STARTVALUE 48
// 检测日志 等级
enum DET_LOG_LEVEL_
{
DET_LOG_LEVEL_0, // 极简信息
DET_LOG_LEVEL_1, // 包含检测关键信息
DET_LOG_LEVEL_2, // 关键信息+ 一般节点信息
DET_LOG_LEVEL_3, // 详细信息
};
struct VERSION_INFO
{
int ConfigVersion = 0;
int ResultVersion = RESULT_VERSION;
int InterfaceVersion = 0;
};
// 检测错误代码
enum ERROR_TYPE_
{
ERROR_TYPE_OK, // 0 疑是
ERROR_TYPE_AD_YX, // 1 AD-异常显示
ERROR_TYPE_Line_X, // 2 x line
ERROR_TYPE_Line_Y, // 3 y line
ERROR_TYPE_Line_fangge, // 3 y line
ERROR_TYPE_Rubbing_Mura, // 4
ERROR_TYPE_line_Broken, // 5 断线
ERROR_TYPE_ZARA, // 6 ZARA
ERROR_TYPE_MTX, // 7 MTX
ERROR_TYPE_POL_Cell, // 8 异物
ERROR_TYPE_LD, // 9 亮点
ERROR_TYPE_AD, // 10 暗点
ERROR_TYPE_BD, // 11 黑点
ERROR_TYPE_WD, // 12 白点
ERROR_TYPE_Scratch, // 13 划伤
ERROR_TYPE_Weak_Bright_Mura, // 14 白GAP
ERROR_TYPE_No_Label, // 15 缺POL
ERROR_TYPE_PS, // 16 PS
ERROR_TYPE_GRID_LINE, // 17 方格线
ERROR_TYPE_STEAM_POCKET, // 19 气泡
ERROR_TYPE_Dirty, // 19 脏污
ERROR_TYPE_Other, // 19 other
ERROR_TYPE_Cell_W, // 19 other
ERROR_TYPE_Cell_B, // 19 other
ERROR_TYPE_LackPol, // 缺失Pol
ERROR_TYPE_CHESS,
ERROR_TYPE_COUNT,
};
static const std::string QX_Result_Names[] =
{
"OK",
"AD_YX",
"X_Line",
"Y_Line",
"fangge",
"Rubbing_Mura",
"Broken_line",
"ZARA",
"MTX",
"POL_Cell",
"Bright_Point",
"Dark_Point",
"BLack_Point",
"White_Point",
"Scratch",
"Weak_Bright_Mura",
"No_Label",
"Bright_Mura_Exe",
"Sweak_Line_Dark",
"STEAM_POCKET",
"Dirty",
"other",
"Cell_W",
"Cell_B",
"LackPol",
"Chess"};
static const std::string QX_Result_Code[] =
{
"P1153",
"P6873",
"P3351",
"P3452",
"P3453",
"P1550",
"P3379",
"P1153",
"P1164",
"P1101",
"P1112",
"P1111",
"P1104",
"P1103",
"P1557",
"P1654",
"P2833",
"P1549",
"P1204",
"P2534",
"P2534",
"P1101",
"P1103",
"P1104",
"P8001",
"P8002",
};
// 检测检测参数类型
enum CHECK_CONFIG_TYPE_
{
CHECK_CONFIG_Run, // 运行参数
CHECK_CONFIG_Module, // 参数模块
CHECK_CONFIG_Module_Cam2, // 参数模块 相机2参数
CHECK_CONFIG_COUNT,
};
// 输入检测图片的
enum IMG_INPUT_
{
IMG_INPUT_SRC,
IMG_INPUT_COUNT,
};
// 输入检测缺陷小图
enum IMG_OUTPUT_
{
IMG_OUTPUT_RESIZE,
IMG_OUTPUT_COUNT,
};
// 输入图片的状态
enum IN_IMG_Status_
{
IN_IMG_Status_Start,
IN_IMG_Status_Other,
IN_IMG_Status_End,
IN_IMG_Status_OneImg,
};
// 检测模式
enum DET_MODE_
{
DET_MODE_NULL,
DET_MODE_EDGE,
DET_MODE_ZF,
DET_MODE_YX,
DET_MODE_UP,
DET_MODE_Det,
DET_MODE_MarkLine,
DET_MODE_ReJson,
};
#define MAX_REGION_NUM 20
// 一个检测项基本信息,包括图片序号,图片、开始时间
struct shareImage
{
int Det_Mode; // 检测模式
int Status;
int camera_ID; // 相机ID
std::string camera_Name; // 相机名称
int img_id;
cv::Mat img;
cv::Mat other_channel_Result_mask; // 其他通道的mask图片
cv::Mat AI_maskImg; // 推理图片
std::string strSnowID; // 相机发古来的雪花码
long getImgTimeMs; // 获取图片的时间点
long readImg_start;
long readImg_end;
long time_PushIn;
long time_sendCheck;
long time_startCheck;
long time_EndCheck;
int imgtype;
cv::Rect cutRoi;
int img_channel; // 图片通道号
int ninstruct; // 运行指令
int nlogLevel; // 日志等级
std::string imgstr;
std::string strImgName;
std::string strImgProductID;
std::string strImgType;
std::string strChannel;
int nImgBigIdx;
int otherValue;
int otherValue_1;
std::string resultJson;
bool bsaveProcessImg; // 保存处理图片
shareImage()
{
Init();
}
~shareImage()
{
}
void Init()
{
if (!img.empty())
{
img.release();
}
if (!other_channel_Result_mask.empty())
{
other_channel_Result_mask.release();
}
if (!AI_maskImg.empty())
{
AI_maskImg.release();
}
Det_Mode = 0;
Status = 0;
nlogLevel = DET_LOG_LEVEL_0;
img_id = -1;
getImgTimeMs = 0;
time_PushIn = 0;
time_sendCheck = 0;
time_startCheck = 0;
time_EndCheck = 0;
readImg_start = 0;
readImg_end = 0;
imgtype = 0;
imgstr = "";
strSnowID = "";
camera_ID = 0;
strImgName = "";
strImgProductID = "";
strChannel = "";
strImgType = "";
nImgBigIdx = 0;
cutRoi = cv::Rect(0, 0, 0, 0);
otherValue = 0;
ninstruct = 0;
img_channel = 0;
resultJson = "";
camera_Name = "";
bsaveProcessImg = false;
}
void InitImg(int ImgW, int imgH, bool Isgray = true)
{
if (Isgray)
{
img = cv::Mat(imgH, ImgW, CV_8UC1);
}
else
{
img = cv::Mat(imgH, ImgW, CV_8UC3);
}
}
};
// AI分析结果
struct JudgeInfo
{
int result = 0;
int positive = 0;
int smudgy = 0;
int abnormal = 0;
int black = 0;
int dot = 0;
int other = 0;
std::string RESULT = "OK";
std::string POSITIVE = "OK"; // 正样本 4
std::string SMUDGY = "OK"; // 脏污 3 R通道
std::string ABNORMAL = "OK"; // zhansi 毛发 2 B通道
std::string BLACK = "OK"; // 黑接头 1
std::string DOT = "OK"; // 黑点 1
std::string OTHER = "OK"; // 其他 1
void Init()
{
result = 0;
positive = 0;
smudgy = 0;
abnormal = 0;
black = 0;
dot = 0;
other = 0;
RESULT = "OK";
POSITIVE = "OK";
SMUDGY = "OK";
ABNORMAL = "OK";
BLACK = "OK";
DOT = "OK";
OTHER = "OK";
}
void copy(JudgeInfo tem)
{
this->result = tem.result;
this->positive = tem.positive;
this->smudgy = tem.smudgy;
this->abnormal = tem.abnormal;
this->black = tem.black;
this->dot = tem.dot;
this->RESULT = tem.RESULT;
this->POSITIVE = tem.POSITIVE;
this->SMUDGY = tem.SMUDGY;
this->ABNORMAL = tem.ABNORMAL;
this->BLACK = tem.BLACK;
this->DOT = tem.DOT;
}
};
// 检测结果基本信息
struct BasicResult
{
int img_id;
long checkUseTimeMs; // 所有时间
int64_t snowId; // 雪花ID
int imgtype;
std::string imgstr;
std::string strChannel;
void Init()
{
img_id = 0;
checkUseTimeMs = 0;
snowId = 0;
imgtype = 0;
imgstr = "";
strChannel = "";
}
void copy(BasicResult tem)
{
this->img_id = tem.img_id;
this->checkUseTimeMs = tem.checkUseTimeMs;
this->snowId = tem.snowId;
this->imgtype = tem.imgtype;
this->imgstr = tem.imgstr;
this->strChannel = tem.strChannel;
}
};
// 缺陷blob信息
struct BLobST
{
cv::Rect blob;
cv::Rect blob_ResizeImg;
cv::Rect blob_SrcImg;
int energy;
int area;
float JudgArea;
int UserErrorType;
BLobST()
{
Init();
}
void Init()
{
blob = cv::Rect(0, 0, 0, 0);
blob_ResizeImg = cv::Rect(0, 0, 0, 0);
blob_SrcImg = cv::Rect(0, 0, 0, 0);
energy = 0;
area = 0;
JudgArea = 0;
UserErrorType = ERROR_TYPE_OK;
}
void copy(BLobST tem)
{
this->blob = tem.blob;
this->blob_ResizeImg = tem.blob_ResizeImg;
this->blob_SrcImg = tem.blob_SrcImg;
this->energy = tem.energy;
this->area = tem.area;
this->JudgArea = tem.JudgArea;
this->UserErrorType = tem.UserErrorType;
}
};
// 缺陷blob信息
struct BLobListST
{
BLobST bloblist[MAX_BLOB_NUM];
int blobNum;
BLobListST()
{
Init();
}
void Init()
{
blobNum = 0;
for (int i = 0; i < MAX_BLOB_NUM; i++)
{
bloblist[i].Init();
}
}
void copy(BLobListST tem)
{
this->blobNum = tem.blobNum;
for (int i = 0; i < MAX_BLOB_NUM; i++)
{
this->bloblist[i].copy(tem.bloblist[i]);
}
}
};
struct DetectInfo
{
int nresult;
std::string keyName;
std::string keyCode;
int num;
DetectInfo()
{
Init();
}
void Init()
{
nresult = 0;
num = 0;
keyName = "";
keyCode = "";
}
void copy(DetectInfo tem)
{
this->nresult = tem.nresult;
this->num = tem.num;
this->keyName = tem.keyName;
this->keyCode = tem.keyCode;
}
};
#define MAX_SamllImg_xcount 13
#define MAX_SamllImg_ycount 10
struct QXImageResult
{
int type; // 缺陷类型
std::string qx_Code; // 缺陷code
std::string strTypeName; // 缺陷名称
cv::Mat srcImg; // 缺陷原始图片
cv::Mat resizeImg; // 缺陷缩略图
cv::Mat AI_in_Img;
cv::Mat AI_out_img;
cv::Rect srcImgroi; // 相对原图的 框坐标;
cv::Rect CutImgroi; // 裁剪原图 框坐标;
cv::Rect resizeImgroi; // 相对相对小图 框坐标;
float x_pixel; // 缺陷坐标 像素
float y_pixel; // 缺陷坐标 像素
float x_mm; // 缺陷坐标 mm
float y_mm; // 缺陷坐标 mm
int idx;
float area;
float energy;
float hj;
float max_v;
float len;
float fScore;
int qx_type; // 缺陷的原因
float minDis_mm;
int qx_num;
float density; // 密度
QXImageResult()
{
Init();
}
void Init()
{
if (!srcImg.empty())
{
srcImg.release();
}
if (!resizeImg.empty())
{
resizeImg.release();
}
if (!AI_in_Img.empty())
{
AI_in_Img.release();
/* code */
}
if (!AI_out_img.empty())
{
AI_out_img.release();
/* code */
}
x_pixel = 0;
y_pixel = 0;
x_mm = 0;
y_mm = 0;
type = 0;
area = 0;
energy = 0;
hj = 0;
max_v = 0;
strTypeName = "";
qx_Code = "";
len = 0;
idx = 0;
fScore = 0;
qx_type = 0;
minDis_mm = 0;
qx_num = 0;
density = 0;
srcImgroi = cv::Rect(0, 0, 0, 0);
CutImgroi = cv::Rect(0, 0, 0, 0);
resizeImgroi = cv::Rect(0, 0, 0, 0);
}
};
// 结果信息
struct CheckResult
{
// 原始图片,输入检测的图片
int checkStatus;
int nDetStep; // 处理步骤
int nresult;
int nProductResult; // 产品结果
int nYS_result;
float productWidht_mm; // 产品宽度 毫米
float productHeight_mm; // 产品 高度 毫米
cv::Mat cutSrcimg;
cv::Mat resultimg;
cv::Mat SrcResultImg; // 结果
cv::Mat resultMaskImg; // AI mask Result
std::shared_ptr<shareImage> in_shareImage; // 输入图片信息
DetectInfo defectResultList[ERROR_TYPE_COUNT]; // 缺陷检测结果list
BasicResult basicResult; // 基本检测结果信息
std::vector<QXImageResult> qxImageResult; // 缺陷小图结果
std::vector<QXImageResult> YS_ImageResult; // 疑似小图结果
std::vector<std::string> det_LogList; // 检测日志
std::string strResultJson; // 缺陷结果 jason
bool bSaveALL;
int nflage1;
int nflage2;
CheckResult()
{
Init();
}
~CheckResult()
{
release();
}
void Init()
{
nProductResult = 0;
checkStatus = 0;
nDetStep = 0;
nresult = ERROR_TYPE_OK;
nYS_result = ERROR_TYPE_OK;
bSaveALL = false;
nflage1 = 0;
nflage2 = 0;
productWidht_mm = 0;
productHeight_mm = 0;
basicResult.Init();
strResultJson = "";
if (!resultimg.empty())
{
resultimg.release();
}
if (!cutSrcimg.empty())
{
cutSrcimg.release();
}
if (!SrcResultImg.empty())
{
SrcResultImg.release();
}
if (!resultMaskImg.empty())
{
resultMaskImg.release();
}
for (int i = 0; i < ERROR_TYPE_COUNT; i++)
{
defectResultList[i].Init();
}
std::vector<QXImageResult> tmp;
qxImageResult.swap(tmp);
YS_ImageResult.swap(tmp);
qxImageResult.erase(qxImageResult.begin(), qxImageResult.end());
YS_ImageResult.erase(YS_ImageResult.begin(), YS_ImageResult.end());
det_LogList.erase(det_LogList.begin(), det_LogList.end());
}
void release()
{
if (!resultimg.empty())
{
resultimg.release();
}
if (!cutSrcimg.empty())
{
cutSrcimg.release();
}
if (!SrcResultImg.empty())
{
SrcResultImg.release();
}
if (!resultMaskImg.empty())
{
resultMaskImg.release();
}
strResultJson = "";
std::vector<QXImageResult> tmp;
qxImageResult.swap(tmp);
YS_ImageResult.swap(tmp);
det_LogList.erase(det_LogList.begin(), det_LogList.end());
}
};
// AI处理后的 结果信息,上传到队列中,做后续风险
struct AI_REUSLTIMG
{
cv::Mat defectImg; // 缺陷检测结果图片
AI_REUSLTIMG()
{
if (!defectImg.empty())
{
defectImg.release();
}
}
~AI_REUSLTIMG()
{
release();
}
void release()
{
if (!defectImg.empty())
{
defectImg.release();
}
}
};
#endif //_CORELOGICFACTORY_HPP_