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.

365 lines
7.1 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 _CheckProcessParam_H_
#define _CheckProcessParam_H_
#include <string>
#include <vector>
#include "JsonCoversion.h"
#include <opencv2/opencv.hpp>
enum PARAM_TYPE_
{
PARAM_TYPE_NULL,
PARAM_TYPE_PRE_Crop,
PARAM_TYPE_PRE_Resize,
PARAM_TYPE_PRE_Color,
PARAM_TYPE_PRE_Flip,
PARAM_TYPE_PRE_RotatedRect,
PARAM_TYPE_PRE_SplitImg,
PARAM_TYPE_AI_Locate,
PARAM_TYPE_Det_MAXROI,
PARAM_TYPE_Det_BLOB,
PARAM_TYPE_Det_MINROI,
};
enum PRE_PARAM_TYPE_
{
PRE_PARAM_TYPE_NULL,
PRE_PARAM_COLOR_TYPE_RGBToGRAY,
PRE_PARAM_COLOR_TYPE_GRAYToRBG,
PRE_PARAM_COLOR_TYPE_RGBToBGR,
PRE_PARAM_FLIP_TYPE_horizontally,
PRE_PARAM_FLIP_TYPE_vertically,
};
struct ImageInfo
{
int width;
int height;
int channels;
ImageInfo()
{
width = 0;
height = 0;
channels = 0;
}
void copy(ImageInfo tem)
{
this->width = tem.width;
this->height = tem.height;
this->channels = tem.channels;
}
void print(std::string str)
{
printf("%s width=%d height=%d channels=%d\n", str.c_str(), width, height, channels);
}
};
// 预处理图片参数信息
struct PreDealImgConfig
{
// 图片预处理:
// 1cut到指定大小
// 2、bresize = true, 缩放到模型输入图片尺寸大小
// 3、bInAI_ImgFflip 输入模型的图片是否要 水平翻转
// 4、bOutAI_ImgFflip 模型输出的图片是否要 水平翻转
cv::Rect cutRoi; // 图片裁剪区域信息
bool bresize; // 是否要resize 到模型输入图尺寸大小
bool bInAI_ImgFflip; // 模型输入的图片是否翻转
bool bOutAI_ImgFflip; // 模型输出的图片是否翻转
PreDealImgConfig()
{
cutRoi.x = 0;
cutRoi.y = 0;
cutRoi.width = 0;
cutRoi.height = 0;
bInAI_ImgFflip = false;
bOutAI_ImgFflip = false;
bresize = false;
}
void copy(PreDealImgConfig tem)
{
this->cutRoi.x = tem.cutRoi.x;
this->cutRoi.y = tem.cutRoi.y;
this->cutRoi.width = tem.cutRoi.width;
this->cutRoi.height = tem.cutRoi.height;
this->bInAI_ImgFflip = tem.bInAI_ImgFflip;
this->bOutAI_ImgFflip = tem.bOutAI_ImgFflip;
this->bresize = tem.bresize;
}
};
// 预处理参数 Corp
struct PRE_PARAM_Crop
{
int paramType = PARAM_TYPE_PRE_Crop;
bool buse = false;
cv::Rect roi;
void print()
{
if (!buse)
{
return;
}
printf("paramType %d roi x,y,w,h %d %d %d %d\n", paramType, roi.x, roi.y, roi.width, roi.height);
}
};
// 预处理参数 resize
struct PRE_PARAM_Resize
{
int paramType = PARAM_TYPE_PRE_Resize;
bool buse = false;
cv::Size sz;
void print()
{
if (!buse)
{
return;
}
printf("paramType %d sz w,h %d %d \n", paramType, sz.width, sz.height);
}
};
// 预处理参数 color
struct PRE_PARAM_Color
{
int paramType = PARAM_TYPE_PRE_Color;
bool buse = false;
int ncolorChangeType = PRE_PARAM_TYPE_NULL;
};
// 预处理参数 镜像翻转
struct PRE_PARAM_Flip
{
int paramType = PARAM_TYPE_PRE_Flip;
bool buse = false;
int nFlipType = PRE_PARAM_TYPE_NULL;
};
// 预处理参数 旋转角度 度数
struct PRE_PARAM_Rotation
{
int paramType = PARAM_TYPE_PRE_RotatedRect;
bool buse = false;
float fAngle = 0;
};
// 预处理参数 分切小图
struct PRE_PARAM_SplitImg
{
int paramType = PARAM_TYPE_PRE_SplitImg;
bool buse = false;
cv::Rect roi; // 分切区域
int SamllImg_width; // 小图大小
int SmallImg_height; // 小图大小
int overlap_x; // 小图间 重叠区域 < 0 自动计算
int overlap_y; // 小图间 重叠区域 < 0 自动计算
};
// 预处理参数
struct DETECT_PROCESS_PRE_PARAM
{
bool buse = false;
PRE_PARAM_Crop crop;
PRE_PARAM_Resize resizeze;
PRE_PARAM_Color color;
PRE_PARAM_Flip flip;
PRE_PARAM_Rotation rotation;
PRE_PARAM_SplitImg splitImg;
void print()
{
if (!buse)
{
return;
}
crop.print();
resizeze.print();
}
};
// AI理参数
struct DETECT_PROCESS_AI_PARAM
{
bool buse = false;
int nAIModleID; // 模型号
void print()
{
if (!buse)
{
return;
}
printf("nAIModleID %d\n", nAIModleID);
}
};
// 处理参数 roi
struct DET_PARAM_MAXROI
{
int paramType = PARAM_TYPE_Det_MAXROI;
bool buse = false;
void print()
{
if (!buse)
{
return;
}
}
};
// 处理参数 roi
struct DET_PARAM_MINROI
{
int paramType = PARAM_TYPE_Det_MINROI;
bool buse = false;
void print()
{
if (!buse)
{
return;
}
}
};
struct BLOB_QX_IMGVALUE_
{
std::string qx_name;
int img_value;
float AreaT_mm2;
};
// 处理参数 blob
struct DET_PARAM_BLOB
{
int paramType = PARAM_TYPE_Det_BLOB;
bool buse = false;
std::vector<BLOB_QX_IMGVALUE_> qx_value;
int minArea_pixel = 1;
int minMergeDis_pixel = 10;
void print()
{
if (!buse)
{
return;
}
printf("BLOb minArea_pixel %d minMergeDis_pixel %d ", minArea_pixel, minMergeDis_pixel);
for (int i = 0; i < qx_value.size(); i++)
{
printf(" %s=%d areaT %f mm2", qx_value.at(i).qx_name.c_str(), qx_value.at(i).img_value, qx_value.at(i).AreaT_mm2);
}
printf("\n");
}
};
// 检测参数
struct DETECT_PROCESS_DET_PARAM
{
bool buse = false;
DET_PARAM_MAXROI maxRoi;
DET_PARAM_BLOB blob;
void print()
{
if (!buse)
{
return;
}
maxRoi.print();
blob.print();
}
};
// 节点
struct DETECT_PROCESS_PARAM
{
DETECT_PROCESS_PRE_PARAM preParam;
DETECT_PROCESS_AI_PARAM AIParam;
DETECT_PROCESS_DET_PARAM detParam;
void print()
{
preParam.print();
AIParam.print();
detParam.print();
}
};
// 节点
struct DETECT_PROCESS_NODE
{
int ID;
std::string strName_CN;
std::string strName_EN;
int type;
bool bsaveImg;
bool bUse; //是否使用
bool bresultImg;
bool bshowResult;
std::vector<int> imgpreNodeList;
std::vector<int> resultpreNodeList;
DETECT_PROCESS_PARAM detParam;
DETECT_PROCESS_NODE()
{
ID = -1;
strName_CN = "";
strName_EN = "";
bsaveImg = false;
bresultImg = false;
bshowResult = false;
bUse = false;
type = PARAM_TYPE_NULL;
imgpreNodeList.clear();
imgpreNodeList.shrink_to_fit();
resultpreNodeList.clear();
resultpreNodeList.shrink_to_fit();
}
void print(std::string str = "")
{
printf("============================%s=========================\n", str.c_str());
printf("ID %d type %d strName %s buse %d img pre Node ", ID, type, strName_CN.c_str(),bUse);
for (int i = 0; i < imgpreNodeList.size(); i++)
{
printf(" %d ", imgpreNodeList.at(i));
}
printf("result pre Node ");
for (int i = 0; i < resultpreNodeList.size(); i++)
{
printf(" %d ", resultpreNodeList.at(i));
}
printf("\n");
detParam.print();
printf("============================%s=========================\n", str.c_str());
}
};
// 检测流程
struct DETECT_PROCESS
{
ImageInfo Srcimg_in;
ImageInfo resultimg_out;
std::vector<DETECT_PROCESS_NODE> Nodes;
DETECT_PROCESS()
{
Nodes.clear();
Nodes.shrink_to_fit();
}
void copy(DETECT_PROCESS tem)
{
this->Nodes.assign(tem.Nodes.begin(), tem.Nodes.end());
this->Srcimg_in.copy(tem.Srcimg_in);
this->resultimg_out.copy(tem.resultimg_out);
}
};
class CheckProcessParamJson : public JsonCoversion
{
public:
CheckProcessParamJson() {}
virtual ~CheckProcessParamJson() {}
public:
virtual Json::Value toJsonValue();
virtual void toObjectFromValue(Json::Value root);
int GetConfig(std::shared_ptr<DETECT_PROCESS> &pconfig);
private:
std::shared_ptr<DETECT_PROCESS> m_pconfig;
};
#endif