|
|
/*
|
|
|
* @Author: your name
|
|
|
* @Date: 2022-04-20 15:49:50
|
|
|
* @LastEditTime: 2022-09-23 21:51:58
|
|
|
* @LastEditors: sueRimn
|
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
|
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
|
|
*/
|
|
|
#ifndef ImgCheckAnalysisy_H_
|
|
|
#define ImgCheckAnalysisy_H_
|
|
|
|
|
|
#include <iostream>
|
|
|
#include <stdio.h>
|
|
|
#include <sys/time.h>
|
|
|
#include <opencv2/opencv.hpp>
|
|
|
#include <condition_variable>
|
|
|
#include <mutex>
|
|
|
#include <vector>
|
|
|
#include <thread>
|
|
|
#include <string>
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <unistd.h>
|
|
|
#include "BlobBase.h"
|
|
|
#include "AICheck.h"
|
|
|
#include "ImgCheckBase.h"
|
|
|
#include "ImageDetBase.h"
|
|
|
#include "ImgCheckConfig.h"
|
|
|
#include "CheckErrorCodeDefine.hpp"
|
|
|
#include "AIImgDeal.h"
|
|
|
#include "DrawImg.h"
|
|
|
#include "CheckConfigDefine.h"
|
|
|
#include "ConfigBase.h"
|
|
|
#include "ImageDetConfig.h"
|
|
|
#include "QX_Analysis.h"
|
|
|
#include "AIClassify.h"
|
|
|
#include "OtherDetect.h"
|
|
|
#include "AI_Second_Det.h"
|
|
|
#include "Define_Error.h"
|
|
|
|
|
|
using namespace std;
|
|
|
using namespace cv;
|
|
|
|
|
|
enum AT_THRESHOLD_TYPE_
|
|
|
{
|
|
|
AT_THRESHOLD_TYPE_NULL,
|
|
|
AT_THRESHOLD_TYPE_READY,
|
|
|
AT_THRESHOLD_TYPE_BUSY,
|
|
|
AT_THRESHOLD_TYPE_COMPLETE,
|
|
|
};
|
|
|
|
|
|
// 全局静态变量, 记录图像灰度值异常累计数量
|
|
|
static int g_nImgBrightnessErrorCount = 0;
|
|
|
class ImgCheckAnalysisy : public ImgCheckBase
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
ImgCheckAnalysisy();
|
|
|
~ImgCheckAnalysisy();
|
|
|
|
|
|
// 初始化参数 pconfig 参数指针 返回:0 成功 其他异常
|
|
|
int RunStart(void *pconfig1);
|
|
|
|
|
|
// 设置检测数据,并开启检测 返回:0 成AT_THRESHOLD_TYPE_READY功 其他异常
|
|
|
int SetDataRun_SharePtr(std::shared_ptr<ImageDetconfig> p);
|
|
|
|
|
|
// 获取结果信息 返回:0 成功 其他异常
|
|
|
int GetCheckReuslt(std::shared_ptr<ImageDetResult> &pResult);
|
|
|
|
|
|
int CheckImg(std::shared_ptr<ImageDetconfig> p, std::shared_ptr<ImageDetResult> &pResult);
|
|
|
int ReJsonResul(std::shared_ptr<ImageDetconfig> p, std::shared_ptr<ImageDetResult> &pResult);
|
|
|
// 获取检测库 状态信息 返回:CHECK_THREAD_RUN_STATUS
|
|
|
int GetStatus();
|
|
|
|
|
|
// 更新参数 pconfig 参数指针,nConfigType 需要更新的参数类型 返回:0 成功 其他异常
|
|
|
int UpdateConfig(void *pconfig, int nConfigType);
|
|
|
|
|
|
std::string GetVersion();
|
|
|
|
|
|
std::string GetErrorInfo();
|
|
|
|
|
|
private:
|
|
|
// 加载运行参数
|
|
|
int LoadRunConfig(void *p);
|
|
|
|
|
|
// 加载分析参数
|
|
|
int LoadCheckConfig(void *p);
|
|
|
|
|
|
/// @brief 初始化并且启动程序
|
|
|
/// @return
|
|
|
int InitRun(int nId);
|
|
|
|
|
|
/// @brief 开启检测
|
|
|
/// @return
|
|
|
int StartCheck();
|
|
|
|
|
|
/// @brief 设置空闲
|
|
|
/// @return
|
|
|
int SetIDLE();
|
|
|
|
|
|
private:
|
|
|
// 开启线程
|
|
|
int StartThread(int nId);
|
|
|
// 停止线程
|
|
|
int StopThread();
|
|
|
|
|
|
// 退出系统
|
|
|
int ExitSystem();
|
|
|
|
|
|
// 初始化模型
|
|
|
int InitModel();
|
|
|
int InitModel_NF();
|
|
|
int InitModel_YX();
|
|
|
int InitModel_Clas();
|
|
|
int InitModel_ZF();
|
|
|
int InitModel_Up();
|
|
|
int InitModel_127Cell();
|
|
|
// 检测
|
|
|
int CheckRun();
|
|
|
|
|
|
// 设置新的检测参数
|
|
|
int SetNewConfig();
|
|
|
int GetParamidx();
|
|
|
// 增加检测日志
|
|
|
int AddCheckLog(int nlevel, std::string str);
|
|
|
|
|
|
int GetRegionIdx(int x, int y);
|
|
|
|
|
|
ChannelCheckFunction *GetChannelFuntion(std::string strChannelName); // 获得 通道的检测功能
|
|
|
|
|
|
private:
|
|
|
// 图片处理线程
|
|
|
std::shared_ptr<std::thread> ptr_thread_Run;
|
|
|
int Run(int nId); // 运行;
|
|
|
|
|
|
// 图片处理线程
|
|
|
std::shared_ptr<std::thread> ptr_thread_AI;
|
|
|
|
|
|
int set_cpu_id(const std::vector<int> &cpu_set_vec);
|
|
|
|
|
|
int saveAIImg();
|
|
|
int AnalysisResult_New();
|
|
|
int AnalysisResult_Qx();
|
|
|
int AnalysisResult_Param_Judge();
|
|
|
int AnalysisResult_Pre(QX_ERROR_INFO_ *pQX_info, std::string strChannel); // 弱化处理
|
|
|
int AI_Det(cv::Mat inImg, cv::Mat &outimg);
|
|
|
|
|
|
// 利用Up 画面过滤
|
|
|
float UseUpMaskAnalysis(cv::Rect teroi, cv::Mat AIMaskImg);
|
|
|
float CalImgScorl(cv::Mat det_img, cv::Mat up_img);
|
|
|
float CalImgScorl_t(cv::Mat det_img, cv::Mat up_img);
|
|
|
// 分类
|
|
|
int AI_Classify(cv::Mat img, cv::Rect qx_roi, float fjustarea, float *fmaxScore);
|
|
|
// 多区域分类
|
|
|
int AI_Classify_New(const cv::Mat &src_Img, cv::Rect qx_roi, float fjustarea, float *fmaxScore);
|
|
|
// 计算缺陷长度
|
|
|
float Cal_QXLen(cv::Mat qx_maskImg, int qx_type, float fsc_x, float fsc_y);
|
|
|
// 启动AI处理
|
|
|
int StartAIDeal();
|
|
|
// 等待AIdeal完成
|
|
|
int waitImgAIDealEnd();
|
|
|
void waitAIData();
|
|
|
// 二次计算缺陷面积
|
|
|
int ReCalQX_AreaAndLen(AI_SecondDet::DetConfigResult *pdetConfig);
|
|
|
|
|
|
// 检测结果分析
|
|
|
int CheckAnalysisResult();
|
|
|
|
|
|
// BLob分析
|
|
|
int BlobAnalysis_new();
|
|
|
|
|
|
int CalBLobMean_GrayDis();
|
|
|
int CalBLobMean_GrayDis_127Cell();
|
|
|
|
|
|
// 计算blob的密度
|
|
|
int CalBlobDensity();
|
|
|
int CalBlobDensity_QX();
|
|
|
|
|
|
// 轮廓处理
|
|
|
int Contours();
|
|
|
// 轮廓处理
|
|
|
int Contours_New(cv::Mat mask);
|
|
|
|
|
|
cv::Rect GetCutRoi(cv::Rect roi, cv::Mat img);
|
|
|
cv::Rect GetREAIRoi(cv::Rect roi, cv::Mat img);
|
|
|
// 异显检测
|
|
|
int AI_Det_YX(cv::Mat cropImg);
|
|
|
// 检测初始化
|
|
|
int CheckImgInit();
|
|
|
// 参数 核对
|
|
|
int ConfigCheck(cv::Mat img);
|
|
|
// 多线程方式处理
|
|
|
int AI_Detect_Thread(cv::Mat img, cv::Mat &ResultImg);
|
|
|
// 多线程处理,获取小图 序号。
|
|
|
int Multi_Thread_GetSmallImgIdx(int ntype);
|
|
|
// 多线程处理,设置资源状态
|
|
|
int Multi_Thread_SetSmallType(int idx, int ntype);
|
|
|
// AI 后处理
|
|
|
int Multi_Thread_AIResultDet(cv::Mat &resultImg, int idx);
|
|
|
// AI预处理图片
|
|
|
int AI_PreImg(cv::Mat img, cv::Mat &AI_DealImg);
|
|
|
|
|
|
int ThreadAI(int nId); // 运行;
|
|
|
// resize 图片
|
|
|
int ResizeImg();
|
|
|
|
|
|
// 更新 检测区域
|
|
|
int Update_DetRoiList();
|
|
|
// 绘制结果
|
|
|
int DrawResult();
|
|
|
|
|
|
// 对127重复检测
|
|
|
int ReCheck127Cell(const cv::Mat &DetImage);
|
|
|
|
|
|
// 把检查结果转成json
|
|
|
int DetResultToJson();
|
|
|
|
|
|
int DrawOther();
|
|
|
// 创建mask
|
|
|
int CreateMaskImg();
|
|
|
|
|
|
int SetInDetConfig();
|
|
|
// 更新亮点参数
|
|
|
int UPdateLDConfig();
|
|
|
// 添加检测结果
|
|
|
int AddQXResult(cv::Rect qx_roi_src, cv::Rect qx_roi_resize, int qx_type, float fJudgArea, float fenergy, float fgrayDis, cv::Mat YX_AI_InImg, cv::Mat YX_AI_OUTImg);
|
|
|
|
|
|
// 参数缺陷类型转 结果参数类型
|
|
|
int AIClassTypeToConfigType(int nAIQXType, cv::Rect qx_roi);
|
|
|
// 参数缺陷类型转 结果参数类型
|
|
|
int ConfigTypeToResultType(int nconfigType);
|
|
|
int ConfigTypeToQXAnalysis(int nconfigType);
|
|
|
// 判断是否是点状缺陷
|
|
|
bool IsPointQX(int config_qx_tpe);
|
|
|
// 解析 指令
|
|
|
int GetInstruct(int nInstruct);
|
|
|
|
|
|
int GetZfCropMask(cv::Rect roi);
|
|
|
|
|
|
int ZF_Check(cv::Mat img, cv::Mat &inImg, cv::Mat &maskimg);
|
|
|
int YX_Check_L255(cv::Mat cropImg, cv::Mat &inImg, cv::Mat &outmaskimg);
|
|
|
|
|
|
// 使用 DP mask 进行二次判断
|
|
|
int UseDPMask(int L0, int nconfigtype, cv::Rect roi, float JudgeArea, int maxV, int hj);
|
|
|
// 检测有效区域mask图片
|
|
|
int GetDetMaskImg(cv::Mat img, cv::Rect cutroi);
|
|
|
|
|
|
// 亮的判断
|
|
|
int LDJudge(int nconfigtype, cv::Rect roi, float JudgeArea, int maxV, int hj);
|
|
|
|
|
|
// 获取缺陷 对应的AI输入 输出图片,
|
|
|
int GetAIDetImg(cv::Rect Qx_roi, cv::Mat &AI_InImg, cv::Mat &AI_OutImg);
|
|
|
int GetUpMaskImg(cv::Mat inImg, cv::Mat &maskimg);
|
|
|
// 更新成像精度
|
|
|
int UpdateImgageScale(const cv::Mat &srcimg);
|
|
|
// 更新屏蔽区域
|
|
|
int UpdateSheildMask(std::string strChannel, cv::Rect roi);
|
|
|
|
|
|
// 缺陷是否要进行检测分析 缺陷是参数类型的缺陷
|
|
|
bool JudgeQXAnalysis(int nqx_configType);
|
|
|
|
|
|
// 缺陷是否要进行检测分析 缺陷是参数类型的缺陷
|
|
|
bool Judge_MarkLine_QX(int nqx_configType,cv::Rect detqx_Roi);
|
|
|
|
|
|
// AI 检测的缺陷类型,转换成 web 控制 是否要分析检测的缺陷类型
|
|
|
std::string ConfigTypeToWebDetType(int nconfigType);
|
|
|
|
|
|
// 增加到 绘制区域
|
|
|
int addInDrawBlob(int errortype, int blobidx, ERROR_DOTS_BLOB_DATA *blob, float fs_resize_x, float fs_resize_y);
|
|
|
int addInDrawBlob_New(int errortype, int blobidx, QX_ERROR_INFO_ *QX_info, float fs_resize_x, float fs_resize_y);
|
|
|
// 初始化其他检测类
|
|
|
int InitOtherDet();
|
|
|
|
|
|
// 其他类的检测
|
|
|
int OtherDetect();
|
|
|
// 缺失pol检测
|
|
|
int Detect_LackPol(const cv::Mat &DetImage);
|
|
|
|
|
|
// 精确计算缺陷能量(基于像素灰度差)
|
|
|
cv::Scalar calc_blob_info_withstats(cv::Mat &img, const cv::Mat &mask, cv::Rect &stats, cv::Size k_size = cv::Size(5, 5), int expand = 10, double threshold = 0.7);
|
|
|
|
|
|
private:
|
|
|
int m_nErrorCode; // 错误代码
|
|
|
bool m_bInitSucc; // 初始化状态
|
|
|
bool m_bExit; // 是否退出检测
|
|
|
int m_nThreadIdx; // 线程序号 //相机处理的顺序号,该序号 程序运行就已经固定
|
|
|
|
|
|
std::shared_ptr<shareImage> DetImgInfo_shareP;
|
|
|
std::shared_ptr<ImageDetconfig> ImageDet_shareP;
|
|
|
// 检测结果
|
|
|
std::shared_ptr<CheckResult> m_CheckResult_shareP;
|
|
|
std::shared_ptr<ImageDetResult> m_ImageDetResult_shareP;
|
|
|
// 检测参数模块
|
|
|
ConfigBase *m_pConfig;
|
|
|
// 线程运行的一些参数
|
|
|
RunInfoST m_RunConfig;
|
|
|
// 检测结果
|
|
|
// CheckResult m_CheckResult;
|
|
|
// 基本信息和深度学习模型文件参数
|
|
|
CheckConfigST m_CheckConfig;
|
|
|
|
|
|
float m_fImgage_Scale_X;
|
|
|
float m_fImgage_Scale_Y;
|
|
|
|
|
|
// 分析参数
|
|
|
AnalysisyConfigST m_AnalysisyConfig;
|
|
|
ChannelCheckFunction *m_pFuntion;
|
|
|
BaseCheckFunction *m_pbaseCheckFunction; // 基础检测
|
|
|
CommonConfigNodeST *m_pCommonAnalysisyConfig;
|
|
|
BasicConfig *m_pBasicConfig;
|
|
|
RegionConfigST *m_pRegionAnalysisyParam; // 分析参数
|
|
|
int m_QxInParamListIdx[CONFIG_QX_NAME_count];
|
|
|
|
|
|
cv::Mat m_AnalysisyMaskImg; // 分析的mask
|
|
|
cv::Rect m_CutRoi;
|
|
|
cv::Rect m_Crop_Roi_paramImg; // 裁切在参数模板图上的 位置。
|
|
|
bool m_bShield_ZF; // 屏蔽字符检测
|
|
|
|
|
|
// // 检测控制参数
|
|
|
// CheckControlConfigSt *m_pcheckControlConfig;
|
|
|
int m_nRun_Status; // 运行状态:空闲,运行中,异常,。。。。。
|
|
|
|
|
|
int m_nCheckResultErrorCode;
|
|
|
|
|
|
AI_IMG_deal m_AIDeal;
|
|
|
|
|
|
CHECK_TEM_RESULT m_TemCheck;
|
|
|
|
|
|
Detect_ROI_Config m_DetRoiList; // 检测区域roi List
|
|
|
|
|
|
ERROR_DOTS_BLOBS blobs;
|
|
|
ERROR_DOTS_BLOBS blobs_127;
|
|
|
|
|
|
std::mutex mutex_AIDeal; // AI处理互斥锁
|
|
|
std::condition_variable condVar_AI; // 条件变量
|
|
|
int m_nWaite_AIDeal_SmallImg_Num; // 等待AI处理多线程状态 小图数目
|
|
|
int m_nWaite_AIComplete_SmallImg_Num; // AI处理完成 等待 后处理的小图数目
|
|
|
|
|
|
// 小图资源
|
|
|
// SMALLIMGINFO Multi_Thread_DetSmallImgList[MAX_THREAD_AIDET_NUM];
|
|
|
SMALLIMGINFO Multi_Thread_DetSmallImgList[MAX_THREAD_AIDET_NUM];
|
|
|
std::vector<SMALLIMGINFO> AI_DetImgList;
|
|
|
std::mutex mutex_SmallImgList; // 小图资源锁
|
|
|
|
|
|
OtherCheckResult m_OtherResult;
|
|
|
DrawImg m_DrawImg;
|
|
|
CHECK_INSTRUCT_ m_CheckInstruct; // 检测指令
|
|
|
|
|
|
std::vector<cv::Point> m_ZF_centerPoint; // 字符的中心点位置
|
|
|
cv::Rect m_Cut_roi; // 裁剪区域
|
|
|
int m_curLogLevel; // 当前日志等级
|
|
|
cv::Mat m_DetImgMask; // 检测有效区域mask图片
|
|
|
cv::Mat m_ShieldImg_resize;
|
|
|
|
|
|
QX_Analysis m_qx_Analysis;
|
|
|
|
|
|
LD_ConfigT_ m_LDConfig;
|
|
|
LD_ConfigT_ m_LD_WTBConfig;
|
|
|
LD_ConfigT_ m_LD_HSConfig;
|
|
|
|
|
|
AIClassify m_AIClassify; // 缺陷分类
|
|
|
|
|
|
DetResultST m_DetResult; // 检测结果
|
|
|
|
|
|
OtherDet_Config m_OtherDet_Config;
|
|
|
LackPolDet m_LackPolDet; // 缺Pol 检测;
|
|
|
AI_SecondDet m_SecondDet; // 二次分割检测
|
|
|
|
|
|
std::vector<QXImageResult> m_Draw_qxImageResult; // 缺陷小图结果
|
|
|
|
|
|
std::vector<cv::Rect> SmallRoiList;
|
|
|
int det_SmallImgNum;
|
|
|
|
|
|
cv::Mat m_127CellAIMask;
|
|
|
bool m_bstatus_ReJson;
|
|
|
CheckResultJson m_CheckResultJson;
|
|
|
};
|
|
|
|
|
|
#endif |