|
|
|
|
|
|
|
|
#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"
|
|
|
#include "DetLog.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
|
|
|
|
|
|
|
|
|
|
|
|
// resize 图片的 宽度
|
|
|
#define RESIZE_IMAGE_WIDTH 1680
|
|
|
|
|
|
|
|
|
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"};
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 检测区域参数
|
|
|
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);
|
|
|
// printf("-- %d %d \n", adjustedPoint.x, adjustedPoint.y);
|
|
|
if (adjustedPoint.y < 0)
|
|
|
{
|
|
|
adjustedPoint.y = 0;
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
void Update_1(const std::vector<cv::Point> &list, const cv::Rect &roi, int offtx, int offty, 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 + offtx - roi.x, point.y + offty - roi.y);
|
|
|
if (adjustedPoint.y < 0)
|
|
|
{
|
|
|
adjustedPoint.y = 0;
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
void Update_Marit(const std::vector<cv::Point> &list, const cv::Rect &roi, cv::Mat &H, float fScale_x, float fScale_y)
|
|
|
{
|
|
|
|
|
|
std::vector<cv::Point> adjustedPolygon;
|
|
|
std::vector<cv::Point> adjustedPolygon_size;
|
|
|
// 遍历多边形中的每个点,并根据roi调整位置
|
|
|
for (const auto &point : list)
|
|
|
{
|
|
|
|
|
|
cv::Point pt = CheckUtil::transformPoint(point, H);
|
|
|
// printf(" %d %d -> %d %d \n",point.x,point.y,pt.x,pt.y);
|
|
|
// 调整每个点的位置,平移到roi的位置
|
|
|
cv::Point adjustedPoint(pt.x - roi.x, pt.y - roi.y);
|
|
|
if (adjustedPoint.y < 0)
|
|
|
{
|
|
|
adjustedPoint.y = 0;
|
|
|
}
|
|
|
|
|
|
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 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);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
extern std::string GetErrorCodeInfo(int nErrorCode);
|
|
|
|
|
|
#endif //_CORELOGICFACTORY_HPP_
|