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.
579 lines
14 KiB
579 lines
14 KiB
#ifndef _CheckBaseParam_H_
|
|
#define _CheckBaseParam_H_
|
|
#include <string>
|
|
#include <vector>
|
|
#include "JsonCoversion.h"
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
// 分析类型
|
|
enum ANALYSIS_TYPE_
|
|
{
|
|
ANALYSIS_TYPE_TF, // 检测 分析
|
|
ANALYSIS_TYPE_YS, // 疑是 分析
|
|
ANALYSIS_TYPE_COUNT,
|
|
};
|
|
|
|
static const std::string ANALYSIS_TYPE_Names[] =
|
|
{
|
|
"Check",
|
|
"YS_Config"};
|
|
|
|
enum CONFIG_QX_NAME_
|
|
{
|
|
CONFIG_QX_NAME_zangwu,
|
|
CONFIG_QX_NAME_huahen,
|
|
CONFIG_QX_NAME_aokeng,
|
|
CONFIG_QX_NAME_count,
|
|
};
|
|
|
|
// 缺陷项对应在参数中的名称
|
|
static const std::string CONFIG_QX_NAME_Names[] =
|
|
{
|
|
"zangwu",
|
|
"huaheng",
|
|
"aokeng"};
|
|
|
|
// 成像精度参数
|
|
struct ImageScale_Param
|
|
{
|
|
float fScale_X;
|
|
float fScale_Y;
|
|
ImageScale_Param()
|
|
{
|
|
Init();
|
|
}
|
|
void Init()
|
|
{
|
|
fScale_X = 1;
|
|
fScale_X = 1;
|
|
}
|
|
void copy(ImageScale_Param tem)
|
|
{
|
|
this->fScale_X = tem.fScale_X;
|
|
this->fScale_X = tem.fScale_X;
|
|
}
|
|
void print(std::string str)
|
|
{
|
|
printf("%s img Scale = %f %f\n", str.c_str(), fScale_X, fScale_X);
|
|
}
|
|
};
|
|
// 分割 检测的缺陷 判废阈值参数
|
|
struct QXSeg_Param
|
|
{
|
|
bool buse;
|
|
float Area;
|
|
float GrayDis;
|
|
|
|
QXSeg_Param()
|
|
{
|
|
Init();
|
|
}
|
|
void Init()
|
|
{
|
|
GrayDis = 1;
|
|
Area = 1;
|
|
buse = false;
|
|
}
|
|
void copy(QXSeg_Param tem)
|
|
{
|
|
this->buse = tem.buse;
|
|
this->Area = tem.Area;
|
|
this->GrayDis = tem.GrayDis;
|
|
}
|
|
void print(std::string str)
|
|
{
|
|
printf("%s buse %d Area %f GrayDis %f\n", str.c_str(), buse, Area, GrayDis);
|
|
}
|
|
};
|
|
// 正样本检测参数
|
|
struct ZYB_Param
|
|
{
|
|
int Dis;
|
|
int MinSize;
|
|
ZYB_Param()
|
|
{
|
|
Init();
|
|
}
|
|
void Init()
|
|
{
|
|
Dis = 15;
|
|
MinSize = 5;
|
|
}
|
|
void copy(ZYB_Param tem)
|
|
{
|
|
this->Dis = tem.Dis;
|
|
this->MinSize = tem.MinSize;
|
|
}
|
|
void print(std::string str)
|
|
{
|
|
printf("%s Dis %d MinSize %d\n", str.c_str(), Dis, MinSize);
|
|
}
|
|
};
|
|
|
|
enum DetRotateType
|
|
{
|
|
Ratio_0 = 0,
|
|
Ratio_90 = 1,
|
|
Ratio_180 = 2,
|
|
Ratio_270 = 3,
|
|
};
|
|
|
|
// 基础检测功能 基础检测
|
|
struct Base_Function_DetConfig
|
|
{
|
|
bool bOpen; // 是否开启
|
|
cv::Rect cropROI;
|
|
DetRotateType rotate;
|
|
cv::Rect LabelPolygonBoundingRect; // 标记的芯片多边形最大外接矩形 1107-add
|
|
std::vector<cv::Point> pointArry; // 最小外接矩形
|
|
int chip_width_mm; // 芯片宽度 mm 1107-add
|
|
int chip_height_mm; // 芯片高度 mm 1107-add
|
|
int chip_width_offset_mm; // 芯片宽度偏差 mm
|
|
int chip_height_offset_mm; // 芯片高度偏差 mm 1107-add
|
|
Base_Function_DetConfig()
|
|
{
|
|
Init();
|
|
}
|
|
void Init()
|
|
{
|
|
bOpen = false;
|
|
cropROI = cv::Rect(0, 0, 0, 0);
|
|
rotate = Ratio_0;
|
|
LabelPolygonBoundingRect = cv::Rect(0, 0, 0, 0); // 1107-add
|
|
pointArry.clear(); // 1107-add
|
|
pointArry.shrink_to_fit(); // 1107-add
|
|
chip_width_mm = 0; // 1107-add
|
|
chip_height_mm = 0; // 1107-add
|
|
}
|
|
|
|
void copy(Base_Function_DetConfig tem)
|
|
{
|
|
this->bOpen = tem.bOpen;
|
|
this->cropROI = tem.cropROI;
|
|
this->rotate = tem.rotate;
|
|
this->pointArry.assign(tem.pointArry.begin(), tem.pointArry.end()); // 1107-add
|
|
this->LabelPolygonBoundingRect = tem.LabelPolygonBoundingRect; // 1107-add
|
|
this->chip_width_mm = tem.chip_width_mm; // 1107-add
|
|
this->chip_height_mm = tem.chip_height_mm; // 1107
|
|
}
|
|
void print(std::string str)
|
|
{
|
|
printf("%s>>bOpen %d cropROI [%d %d %d %d]\n", str.c_str(),
|
|
bOpen, cropROI.x, cropROI.y, cropROI.width, cropROI.height);
|
|
}
|
|
std::string GetInfo(std::string str)
|
|
{
|
|
char buffer[256];
|
|
sprintf(buffer, "%s>>bOpen %d cropROI [%d %d %d %d]\n", str.c_str(),
|
|
bOpen, cropROI.x, cropROI.y, cropROI.width, cropROI.height);
|
|
std::string str123 = buffer;
|
|
return str123;
|
|
}
|
|
};
|
|
// 基础检测功能
|
|
struct BaseCheckFunction
|
|
{
|
|
Base_Function_DetConfig detconfig;
|
|
BaseCheckFunction()
|
|
{
|
|
Init();
|
|
}
|
|
void Init()
|
|
{
|
|
detconfig.Init();
|
|
}
|
|
void copy(BaseCheckFunction tem)
|
|
{
|
|
this->detconfig.copy(tem.detconfig);
|
|
}
|
|
void print(std::string str)
|
|
{
|
|
printf("******* %s *********\n", str.c_str());
|
|
detconfig.print("detconfig");
|
|
}
|
|
std::string GetInfo(std::string str)
|
|
{
|
|
std::string str123 = "";
|
|
str123 += detconfig.GetInfo("detconfig");
|
|
|
|
// str123 += "\n";
|
|
|
|
return str123;
|
|
}
|
|
};
|
|
|
|
struct BasicConfig
|
|
{
|
|
std::string strCamearName;
|
|
int image_widht;
|
|
int Image_height;
|
|
int width_min; // 20231122xls-add
|
|
int width_max;
|
|
int height_min;
|
|
int height_max; // 20231122xls-add
|
|
bool bDrawShieldRoi; // 绘制屏蔽区域
|
|
bool bShield_ZF; // 屏蔽字符区域,不检测
|
|
bool bDrawPreRoi; // 绘制弱化区域
|
|
float fUP_IOU;
|
|
bool bCal_ImageScale; // 是否自动计算成像精度
|
|
float Product_Size_Width_mm; // 产品尺寸 宽度 mm
|
|
float Product_Size_Height_mm; // 产品尺寸 高度 mm
|
|
float fImage_Scale_x; // 成像精度
|
|
float fImage_Scale_y; // 成像精度
|
|
std::string strCamName; //
|
|
|
|
float density_R_mm; // 密度计算半径 像素
|
|
BasicConfig()
|
|
{
|
|
Image_height = 0;
|
|
image_widht = 0;
|
|
width_min = 0; // 20231122xls-add
|
|
width_max = 999999;
|
|
height_min = 0;
|
|
height_max = 999999;
|
|
bDrawShieldRoi = false;
|
|
bShield_ZF = false;
|
|
bDrawPreRoi = false;
|
|
fUP_IOU = 0.9;
|
|
bCal_ImageScale = false;
|
|
Product_Size_Width_mm = 100;
|
|
Product_Size_Height_mm = 1000;
|
|
fImage_Scale_x = 0.03;
|
|
fImage_Scale_y = 0.03;
|
|
density_R_mm = 5;
|
|
strCamName = "";
|
|
strCamearName = "";
|
|
}
|
|
void copy(BasicConfig tem)
|
|
{
|
|
this->image_widht = tem.image_widht;
|
|
this->Image_height = tem.Image_height;
|
|
this->width_min = tem.width_min; // 20231122xls-add
|
|
this->width_max = tem.width_max;
|
|
this->height_min = tem.height_min;
|
|
this->height_max = tem.height_max;
|
|
this->bDrawShieldRoi = tem.bDrawShieldRoi;
|
|
this->bShield_ZF = tem.bShield_ZF;
|
|
this->fUP_IOU = tem.fUP_IOU;
|
|
this->bDrawPreRoi = tem.bDrawPreRoi;
|
|
this->strCamName = tem.strCamName;
|
|
|
|
this->bCal_ImageScale = tem.bCal_ImageScale;
|
|
this->Product_Size_Width_mm = tem.Product_Size_Width_mm;
|
|
this->Product_Size_Height_mm = tem.Product_Size_Height_mm;
|
|
this->fImage_Scale_x = tem.fImage_Scale_x;
|
|
this->fImage_Scale_y = tem.fImage_Scale_y;
|
|
this->density_R_mm = tem.density_R_mm;
|
|
this->strCamearName = tem.strCamearName;
|
|
}
|
|
void print(std::string str = "")
|
|
{
|
|
printf("============================↓↓↓↓↓↓%s↓↓ %s ↓↓↓↓↓=========================\n", str.c_str(), strCamearName.c_str());
|
|
printf("bCal_ImageScale %d Product_Size_Width =%f Product_Size_Height =%f \n", bCal_ImageScale, Product_Size_Width_mm, Product_Size_Height_mm);
|
|
printf("fImage_Scale_x =%f fImage_Scale_y=%f \n", fImage_Scale_x, fImage_Scale_y);
|
|
// printf("height_min =%d height_max=%d \n", height_min, height_max);
|
|
printf("bDrawShieldRoi %d bShield_ZF %d DrawPreRoi %d fUP_IOU %f density_R_mm %f\n", bDrawShieldRoi, bShield_ZF, bDrawPreRoi, fUP_IOU, density_R_mm);
|
|
printf("============================↑↑↑↑↑↑%s↑↑↑↑↑↑=========================\n", str.c_str());
|
|
}
|
|
};
|
|
|
|
struct NodeBasicConfig
|
|
{
|
|
|
|
float calss_conf; // 分类阈值参数,低于这个阈值的不处理,
|
|
float calss_area; // 分类阈值参数,低于这个阈值的不处理,
|
|
|
|
int img_width;
|
|
int img_height;
|
|
NodeBasicConfig()
|
|
{
|
|
|
|
calss_conf = 0.5;
|
|
calss_area = 1.0;
|
|
}
|
|
void copy(NodeBasicConfig tem)
|
|
{
|
|
|
|
this->calss_conf = tem.calss_conf;
|
|
this->calss_area = tem.calss_area;
|
|
}
|
|
void print(std::string str = "")
|
|
{
|
|
printf("============================↓↓↓↓↓↓%s↓↓↓↓↓↓↓=========================\n", str.c_str());
|
|
printf("img_width %d img_height %d alss_conf %f calss_area %f \n", img_width, img_height, calss_conf, calss_area);
|
|
|
|
printf("============================↑↑↑↑↑↑%s↑↑↑↑↑↑=========================\n", str.c_str());
|
|
}
|
|
};
|
|
|
|
struct RegionBasicInfo
|
|
{
|
|
std::string name; // 区域名称
|
|
int type; // 区域类型
|
|
int lay; // 层级
|
|
std::vector<cv::Point> pointArry; // 区域点
|
|
std::vector<std::string> ChannelArry; // 通道区域
|
|
bool bdraw; // 是否绘制
|
|
RegionBasicInfo()
|
|
{
|
|
Init();
|
|
}
|
|
void Init()
|
|
{
|
|
name = "";
|
|
type = 0;
|
|
lay = 0;
|
|
bdraw = false;
|
|
pointArry.clear();
|
|
pointArry.shrink_to_fit();
|
|
ChannelArry.clear();
|
|
ChannelArry.shrink_to_fit();
|
|
}
|
|
void copy(RegionBasicInfo tem)
|
|
{
|
|
this->name = tem.name;
|
|
this->type = tem.type;
|
|
this->lay = tem.lay;
|
|
this->bdraw = tem.bdraw;
|
|
this->pointArry.assign(tem.pointArry.begin(), tem.pointArry.end());
|
|
this->ChannelArry.assign(tem.ChannelArry.begin(), tem.ChannelArry.end());
|
|
}
|
|
};
|
|
|
|
struct AandEParam
|
|
{
|
|
bool bEnable; // 是否启用
|
|
bool bOk; // 好品条件
|
|
float area; // 面积
|
|
float area_max; // 面积上限
|
|
float energy; // 能量
|
|
float hj; // 灰阶
|
|
float length; // 长度
|
|
int num; // 数量
|
|
float dis; // 距离
|
|
float density; // 密度
|
|
AandEParam()
|
|
{
|
|
bOk = false;
|
|
bEnable = false;
|
|
area = -1;
|
|
area_max = -1;
|
|
energy = -1;
|
|
hj = -1;
|
|
length = -1;
|
|
num = -1;
|
|
dis = -1;
|
|
density = -1;
|
|
}
|
|
void print(std::string str)
|
|
{
|
|
printf("%s bEnable %d bOk %d area %f area_max %f energy %f hj %f length %f num %d dis %f density %f \n", str.c_str(), bEnable, bOk, area, area_max, energy, hj, length, num, dis, density);
|
|
}
|
|
void copy(AandEParam tem)
|
|
{
|
|
this->bEnable = tem.bEnable;
|
|
this->bOk = tem.bOk;
|
|
this->area = tem.area;
|
|
this->area_max = tem.area_max;
|
|
this->energy = tem.energy;
|
|
this->hj = tem.hj;
|
|
this->length = tem.length;
|
|
this->num = tem.num;
|
|
this->dis = tem.dis;
|
|
this->density = tem.density;
|
|
}
|
|
};
|
|
|
|
// 区域的检测参数
|
|
struct CheckConfig_Regions_Param
|
|
{
|
|
|
|
std::vector<AandEParam> paramArr;
|
|
std::string param_name;
|
|
int useNum; // 使用个数
|
|
CheckConfig_Regions_Param()
|
|
{
|
|
paramArr.clear();
|
|
paramArr.shrink_to_fit();
|
|
useNum = 0;
|
|
param_name = "";
|
|
}
|
|
void addParam(AandEParam param)
|
|
{
|
|
paramArr.push_back(param);
|
|
useNum++;
|
|
}
|
|
};
|
|
// 不同缺陷类型参数
|
|
struct CheckConfig_Regions_type
|
|
{
|
|
std::vector<CheckConfig_Regions_Param> checkConfig_Regions_Param;
|
|
};
|
|
|
|
// 区域相关参数
|
|
struct RegionConfigST
|
|
{
|
|
bool buse; // 是否使用
|
|
RegionBasicInfo basicInfo; // 基础信息
|
|
CheckConfig_Regions_type checkConfig_Regions_type[ANALYSIS_TYPE_COUNT];
|
|
RegionConfigST()
|
|
{
|
|
buse = false;
|
|
} /* data */
|
|
};
|
|
|
|
struct CommonConfigNodeST
|
|
{
|
|
NodeBasicConfig nodebasicConfog;
|
|
std::vector<RegionConfigST> regionConfigArr;
|
|
cv::Mat mask;
|
|
// cv::Mat SheildMask[IMG_CHANNEL_Count];
|
|
void copy(CommonConfigNodeST tem)
|
|
{
|
|
this->regionConfigArr.assign(tem.regionConfigArr.begin(), tem.regionConfigArr.end());
|
|
this->nodebasicConfog.copy(tem.nodebasicConfog);
|
|
if (!tem.mask.empty())
|
|
{
|
|
this->mask = tem.mask.clone();
|
|
}
|
|
// for (int i = 0; i < IMG_CHANNEL_Count; i++)
|
|
// {
|
|
// if (!tem.SheildMask[i].empty())
|
|
// {
|
|
// this->SheildMask[i] = tem.SheildMask[i].clone();
|
|
// }
|
|
// }
|
|
}
|
|
};
|
|
|
|
struct CommonCheckConfigST
|
|
{
|
|
BasicConfig baseConfig;
|
|
// 节点参数数据集
|
|
std::vector<CommonConfigNodeST> nodeConfigArr;
|
|
CommonCheckConfigST()
|
|
{
|
|
nodeConfigArr.clear();
|
|
nodeConfigArr.shrink_to_fit();
|
|
}
|
|
void copy(CommonCheckConfigST tem)
|
|
{
|
|
this->nodeConfigArr.assign(tem.nodeConfigArr.begin(), tem.nodeConfigArr.end());
|
|
this->baseConfig.copy(tem.baseConfig);
|
|
}
|
|
};
|
|
|
|
struct RegionCheckConfig
|
|
{
|
|
QXSeg_Param qxSegParam;
|
|
QXSeg_Param ysSegParam;
|
|
std::vector<cv::Point> pointArry; // 区域点
|
|
cv::Rect Det_Roi;
|
|
RegionCheckConfig()
|
|
{
|
|
Init();
|
|
}
|
|
void Init()
|
|
{
|
|
|
|
qxSegParam.Init();
|
|
ysSegParam.Init();
|
|
Det_Roi = cv::Rect(0, 0, 0, 0);
|
|
pointArry.clear();
|
|
pointArry.shrink_to_fit();
|
|
}
|
|
void copy(RegionCheckConfig tem)
|
|
{
|
|
this->Det_Roi = tem.Det_Roi;
|
|
this->qxSegParam.copy(tem.qxSegParam);
|
|
this->ysSegParam.copy(tem.ysSegParam);
|
|
|
|
this->pointArry.assign(tem.pointArry.begin(), tem.pointArry.end());
|
|
}
|
|
void print(std::string str)
|
|
{
|
|
|
|
qxSegParam.print("qxSegParam");
|
|
ysSegParam.print("ysSegParam");
|
|
printf("x y w h %d %d %d %d\n", Det_Roi.x, Det_Roi.y, Det_Roi.width, Det_Roi.height);
|
|
}
|
|
};
|
|
// 检测 基本参数
|
|
struct CheckBaseConfig
|
|
{
|
|
BaseCheckFunction baseCheckFunction;
|
|
ImageScale_Param imageScaleParam;
|
|
// 节点参数数据集
|
|
std::vector<CommonConfigNodeST> nodeConfigArr;
|
|
QXSeg_Param qxSegParam;
|
|
QXSeg_Param ysSegParam;
|
|
std::vector<cv::Point> pointArry; // 区域点
|
|
cv::Rect Det_Roi;
|
|
ZYB_Param zybParam;
|
|
float det_ratio_min;
|
|
float det_ratio_max;
|
|
cv::Rect crop;
|
|
std::vector<RegionCheckConfig> regionCheckConfig;
|
|
CheckBaseConfig()
|
|
{
|
|
Init();
|
|
}
|
|
void Init()
|
|
{
|
|
baseCheckFunction.Init();
|
|
imageScaleParam.Init();
|
|
qxSegParam.Init();
|
|
ysSegParam.Init();
|
|
ZYB_Param zybParam;
|
|
crop = cv::Rect(0, 0, 0, 0);
|
|
Det_Roi = cv::Rect(0, 0, 0, 0);
|
|
det_ratio_min = 0.6;
|
|
det_ratio_max = 2;
|
|
pointArry.clear();
|
|
pointArry.shrink_to_fit();
|
|
|
|
regionCheckConfig.clear();
|
|
regionCheckConfig.shrink_to_fit();
|
|
}
|
|
void copy(CheckBaseConfig tem)
|
|
{
|
|
this->imageScaleParam.copy(tem.imageScaleParam);
|
|
this->qxSegParam.copy(tem.qxSegParam);
|
|
this->ysSegParam.copy(tem.ysSegParam);
|
|
this->crop = tem.crop;
|
|
this->Det_Roi = tem.Det_Roi;
|
|
this->zybParam = tem.zybParam;
|
|
this->det_ratio_min = tem.det_ratio_min;
|
|
this->det_ratio_max = tem.det_ratio_max;
|
|
this->baseCheckFunction.copy(tem.baseCheckFunction);
|
|
this->pointArry.assign(tem.pointArry.begin(), tem.pointArry.end());
|
|
this->regionCheckConfig.assign(tem.regionCheckConfig.begin(), tem.regionCheckConfig.end());
|
|
}
|
|
void print(std::string str)
|
|
{
|
|
imageScaleParam.print("imageScaleParam");
|
|
qxSegParam.print("qxSegParam");
|
|
ysSegParam.print("ysSegParam");
|
|
zybParam.print("zybParam");
|
|
printf("x y w h %d %d %d %d\n", crop.x, crop.y, crop.width, crop.height);
|
|
baseCheckFunction.print("baseCheckFunction");
|
|
}
|
|
};
|
|
|
|
class CheckBaseParamJson : public JsonCoversion
|
|
{
|
|
public:
|
|
CheckBaseParamJson() {}
|
|
virtual ~CheckBaseParamJson() {}
|
|
|
|
public:
|
|
virtual Json::Value toJsonValue();
|
|
virtual void toObjectFromValue(Json::Value root);
|
|
int GetConfig(std::shared_ptr<CheckBaseConfig> &pconfig);
|
|
int GetFunction(Json::Value value);
|
|
|
|
private:
|
|
std::shared_ptr<CheckBaseConfig> m_pconfig;
|
|
};
|
|
|
|
#endif |