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.

512 lines
9.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef _CheckErrorDefine_HPP_
#define _CheckErrorDefine_HPP_
#include <string>
#include <opencv2/opencv.hpp>
#include "CheckUtil.hpp"
#include "Base_Define.h"
#include "Define_Base.h"
#include "Define_Error.h"
#define BOOL_TO_STR(bool_expr) (bool_expr) ? "true" : "false"
#define BOOL_TO_STROK(bool_expr) (bool_expr) ? "OK" : "NG"
#define BOOL_TO_ThanLess(bool_expr) (bool_expr) ? ">" : "<"
#define BOOL_TO_LessThan(bool_expr) (bool_expr) ? "<" : ">"
#define BOOL_TO_STR_Error(bool_expr) ((bool_expr) ? "Succ" : "Error")
#define Re_TO_STR_Error(num) ((num) == 0 ? "Succ" : "Error")
#define Re_TO_STR_False(num) ((num) == 0 ? "Succ" : "false")
#define Re_TO_STR_Pass_1(num) ((num) == 1 ? "Pass" : "fail")
#define Re_TO_STR_NG(num) ((num) == 0 ? "OK" : "NG")
#define SRC_IMG_WIDTH 14192
#define SRC_IMG_HEIGHT 10640
// 输入模型图片尺寸
#define SRC_AI_In_IMAGE_WIDTH 1024
#define SRC_AI_In_IMAGE_HEIGHT 1024
// resize 图片的 宽度
#define RESIZE_IMAGE_WIDTH 1280
enum PrintLevel_
{
PrintLevel_0,
PrintLevel_1,
PrintLevel_2,
PrintLevel_3,
PrintLevel_4,
};
enum TEM_IMG_IDX_
{
TEM_IMG_IDX_SrcCrop,
TEM_IMG_IDX_AImask,
TEM_IMG_IDX_DrawSrc,
TEM_IMG_IDX_Result,
TEM_IMG_IDX_Count,
};
static const std::string TEM_IMG_IDX_Names[] =
{
"SrcCrop",
"AImask",
"Drawmask",
"result"};
// 检测过程临结果
struct CHECK_TEM_RESULT
{
cv::Mat temImgList[TEM_IMG_IDX_Count];
std::vector<std::string> timeInfoList;
std::vector<std::string> analysisInfoList;
std::vector<std::string> temlogList;
bool bPrintStr; // 是否打印日志
int addLogLevel;
bool bInTemList;
CHECK_TEM_RESULT()
{
Init();
}
void Init()
{
timeInfoList.clear();
timeInfoList.shrink_to_fit();
analysisInfoList.clear();
analysisInfoList.shrink_to_fit();
temlogList.clear();
temlogList.shrink_to_fit();
for (int i = 0; i < TEM_IMG_IDX_Count; i++)
{
if (!temImgList[i].empty())
{
temImgList[i].release();
}
}
bPrintStr = false;
addLogLevel = 0;
bInTemList = false;
}
void temLogListInit()
{
temlogList.erase(temlogList.begin(), temlogList.end());
temlogList.clear();
}
void AddTimeStr(std::string str, long start, long end)
{
char text[1024] = {0};
double t = end - start;
sprintf(text, "%s : use Time :%.2f", str.c_str(), t);
std::string temstr = text;
printf("%s\n", temstr.c_str());
timeInfoList.push_back(temstr);
}
template <typename... Args>
void AddCheckstr(int step, int LogLevel, std::string stepStr, const std::string &format, Args... args)
{
std::string str = "";
if (step <= PrintLevel_0)
{
str += ".. ";
}
else if (step == PrintLevel_1)
{
str += "..... ";
}
else if (step == PrintLevel_2)
{
str += "........ ";
}
else if (step == PrintLevel_3)
{
str += "........... ";
}
else if (step >= PrintLevel_4)
{
str += ".............. ";
}
str += stepStr + ": ";
str += str_Format(format, args...);
if (bPrintStr)
{
printf("%s\n", str.c_str());
}
if (bInTemList)
{
temlogList.push_back(str);
}
else
{
if (LogLevel <= addLogLevel)
{
analysisInfoList.push_back(str);
}
}
}
void AddCheckstr(std::string str)
{
if (str == "")
{
return;
}
printf("%s\n", str.c_str());
analysisInfoList.push_back(str);
}
void AddCheckstr(std::string str, std::string str1)
{
str = str + ":" + str1;
printf("%s\n", str.c_str());
analysisInfoList.push_back(str);
}
void AddCheckstr(std::string str, int value)
{
str = str + ":" + std::to_string(value);
printf("%s\n", str.c_str());
analysisInfoList.push_back(str);
}
void AddCheckstr(std::string str, float value)
{
str = str + ":" + std::to_string(value);
printf("%s\n", str.c_str());
analysisInfoList.push_back(str);
}
void saveImg()
{
for (int i = 0; i < TEM_IMG_IDX_Count; i++)
{
if (!temImgList[i].empty())
{
std::string str = TEM_IMG_IDX_Names[i] + ".png";
cv::imwrite(str, temImgList[i]);
}
}
}
};
enum Print_Level_
{
Print_Level_Info,
Print_Level_Key,
Print_Level_Error,
};
// 大于日志
struct PRINT_LOG_
{
bool bprint;
bool bshow_Info;
bool bshow_Key;
bool bshow_Error;
PRINT_LOG_()
{
Init();
}
void Init()
{
bprint = true;
bshow_Info = true;
bshow_Key = true;
bshow_Error = true;
}
template <typename... Args>
std::string printstr(int LogLevel, std::string stepStr, const std::string &format, Args... args)
{
std::string str = "";
if (!bprint)
{
return str;
}
switch (LogLevel)
{
case Print_Level_Info:
if (!bshow_Info)
{
return str;
}
str = "info-> ";
break;
case Print_Level_Key:
if (!bshow_Key)
{
return str;
}
str = "key-> ";
break;
case Print_Level_Error:
if (!bshow_Error)
{
return str;
}
str = "Error-> ";
break;
default:
return str;
break;
}
str += stepStr + ": ";
str += str_Format(format, args...);
printf("%s\n", str.c_str());
return str;
}
};
#define MAX_THREAD_AIDET_NUM 2
struct SMALLIMGINFO
{
int nDetType;
int nidx;
cv::Mat img;
cv::Mat outimg;
cv::Rect Roi;
int flag;
int start_x;
int start_y;
int nresult;
int x_idx;
int y_idx;
SMALLIMGINFO()
{
Init();
}
~SMALLIMGINFO()
{
release();
}
void Init()
{
if (!img.empty())
{
img.release();
}
if (!outimg.empty())
{
outimg.release();
}
nDetType = 0;
flag = 0;
start_x = 0;
start_y = 0;
nidx = 0;
nresult = 0;
x_idx = 0;
y_idx = 0;
}
void release()
{
if (!img.empty())
{
img.release();
}
if (!outimg.empty())
{
outimg.release();
}
}
};
struct YX_CheckResult_
{
int nresult; // 检测结果
YX_CheckResult_()
{
Init();
}
void Init()
{
nresult = 0;
}
};
// 缺失POl 检测
struct LackPol_CheckResult_
{
int nresult; // 检测结果
LackPol_CheckResult_()
{
Init();
}
void Init()
{
nresult = 0;
}
};
struct WTB_Check_Result_
{
cv::Rect roi_src;
cv::Rect roi_show;
WTB_Check_Result_()
{
Init();
}
void Init()
{
roi_src = cv::Rect(0, 0, 0, 0);
roi_show = cv::Rect(0, 0, 0, 0);
}
};
// 其他检测结果
struct OtherCheckResult
{
YX_CheckResult_ result_YX;
WTB_Check_Result_ WTB_Check_Result;
LackPol_CheckResult_ result_LackPol;
OtherCheckResult()
{
Init();
}
void Init()
{
result_YX.Init();
WTB_Check_Result.Init();
result_LackPol.Init();
}
};
// 检测指令
struct CHECK_INSTRUCT_
{
bool bWhiteAndBlack; // 使用另外一个 检测模型。
CHECK_INSTRUCT_()
{
Init();
}
void Init()
{
bWhiteAndBlack = false;
}
};
// 亮点的判断参数
struct LD_ConfigT_
{
bool buse;
float minArea;
float maxArea;
float hj;
LD_ConfigT_()
{
buse = false;
minArea = 0;
maxArea = 0;
hj = 0;
}
void print(std::string str)
{
printf("%s buse %d minArea %f maxArea %f hj %f\n", str.c_str(), buse, minArea, maxArea, hj);
}
};
// 检测区域参数
struct Detect_ROI_Config
{
bool bdraw; // 是否绘制
std::vector<std::vector<cv::Point>> roiList_Src;
std::vector<std::vector<cv::Point>> roiList_Show;
Detect_ROI_Config()
{
Init();
}
void Init()
{
bdraw = false;
for (auto &innerVec : roiList_Src)
{
innerVec.clear();
}
roiList_Src.clear(); // 清空外层vector
for (auto &innerVec : roiList_Show)
{
innerVec.clear();
}
roiList_Show.clear(); // 清空外层vector
}
void Update(const std::vector<cv::Point> &list, const cv::Rect &roi, float fScale_x, float fScale_y)
{
std::vector<cv::Point> adjustedPolygon;
std::vector<cv::Point> adjustedPolygon_size;
// 遍历多边形中的每个点并根据roi调整位置
for (const auto &point : list)
{
// 调整每个点的位置平移到roi的位置
cv::Point adjustedPoint(point.x - roi.x, point.y - roi.y);
cv::Point sizep;
sizep.x = adjustedPoint.x * fScale_x;
sizep.y = adjustedPoint.y * fScale_y;
adjustedPolygon.push_back(adjustedPoint);
adjustedPolygon_size.push_back(sizep);
}
// 将调整后的多边形添加到roiList_Src
roiList_Src.push_back(adjustedPolygon);
roiList_Show.push_back(adjustedPolygon_size);
}
// 判断点是否在指定idx的ROI内
bool isPointInROI(int idx, const cv::Point &point)
{
// 判断索引是否有效
if (idx < 0 || idx >= roiList_Src.size())
{
printf("Invalid idx: %d\n", idx);
return false;
}
// 获取第 idx 个多边形
const std::vector<cv::Point> &polygon = roiList_Src[idx];
// 使用 pointPolygonTest 来判断点是否在多边形内
double result = cv::pointPolygonTest(polygon, point, false);
// 如果结果大于 0则点在多边形内
if (result > 0)
{
return true;
}
// 如果结果等于 0点在边界上
else if (result == 0)
{
return true; // 你可以根据需求调整边界情况
}
// 如果结果小于 0点在多边形外
return false;
}
void print(std::string str)
{
printf("%s bdraw %d roi num %ld\n", str.c_str(), bdraw, roiList_Src.size());
}
};
// 复测的状态
enum ReJson_Status
{
ReJson_Status_Idel,
ReJson_Status_start,
ReJson_Status_Run,
ReJson_Status_end,
};
struct AD_Channel_Info_
{
cv::Rect roi;
int num;
float fdis;
AD_Channel_Info_()
{
roi = cv::Rect(0, 0, 0, 0);
num = 0;
fdis = 999999999999;
}
};
extern std::string GetErrorCodeInfo(int nErrorCode);
#endif //_CORELOGICFACTORY_HPP_