/* * @Author: your name * @Date: 2022-04-20 15:49:50 * @LastEditTime: 2025-09-17 20:10:01 * @LastEditors: xiewenji 527774126@qq.com * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h */ #ifndef CameraCheckAnalysisy_H_ #define CameraCheckAnalysisy_H_ #include #include #include #include #include #include #include "Define_Base.h" #include "ImgCheckBase.h" #include "ImageDetBase.h" #include "ImgCheckConfig.h" #include "CheckErrorCodeDefine.hpp" #include "ConfigBase.h" #include "CheckConfigDefine.h" #include "ImageDetConfig.h" #include "Define_Product.hpp" #include "CameraResult.h" #include "DetLog.h" #include "ImageResultJudge.h" #include "CheckResultJson.h" using namespace std; using namespace cv; // 相机处理类 class CameraCheckAnalysisy { public: // 搜索方向 enum Edge_DirectSign { DirectSign_UP, DirectSign_DOWN, DirectSign_Left, DirectSign_Right, }; // 搜索边缘了下,黑还是白 enum Search_Value_Type { Search_Value_White, Search_Value_Black, }; // 边缘搜索参数 struct Edge_Search_Config { cv::Rect roi; // 边缘搜索区域 Search_Value_Type searchValueType; // 搜索边缘了下,黑还是白 Edge_DirectSign directSign; // 搜索方向 int nValueThreshold; // 灰度阈值 int nSearchCount; // 搜索点的个数 把roi 均分成多少个点。 int nSearchrange; // 搜索范围,一般为单数,如果 1表示 搜索当前点,如果3表示 除了当前点,还有左右 点。5表示 从-2到2 int stepCount; // 每个搜索点的步数 int nLimit; // 连续搜索多个满足阈值的点后,停止搜索,当前搜索点 搜索成功。 std::string strchannel; Edge_Search_Config() { roi = cv::Rect(0, 0, 0, 0); directSign = DirectSign_UP; searchValueType = Search_Value_White; nValueThreshold = 40; nSearchCount = 30; nSearchrange = 1; stepCount = 2; nLimit = 3; strchannel = ""; } bool CheckConfigValid() { bool bRet = true; if (roi.width <= 0 || roi.height <= 0) { printf("s1 \n"); return false; } if (searchValueType < Search_Value_White || searchValueType > Search_Value_Black) { printf("s2 \n"); return false; } if (directSign < 0 || directSign > 4) { printf("s3 \n"); return false; } if (nValueThreshold < 0 || nValueThreshold > 255) { printf("s4 \n"); return false; } if (nSearchCount < 0) { printf("s5 \n"); return false; } if (stepCount < 0) { printf("s6 \n"); return false; } if (nLimit < 0) { printf("s7 \n"); return false; } return true; } }; struct Line { cv::Point p1; cv::Point p2; Line() { p1 = cv::Point(0, 0); p2 = cv::Point(0, 0); } }; public: CameraCheckAnalysisy(); ~CameraCheckAnalysisy(); // 相机处理类 初始化 int Init(std::string strcameraName); int StartCheck(std::shared_ptr pCamera_Check_Result); private: // 开启线程 int StartThread(); // 停止线程 int StopThread(); // 初始化检测分析线程类 int InitCheckAnalysisy(); // 初始化其他 int InitRun(); // 设置新的检测参数 int SetNewConfig(); // 处理每张图片 int CheckImgRun(); int Run(); // 运行; int set_cpu_id(const std::vector &cpu_set_vec); // 等待处理图片 int WaitDetImg(); // 预处理图片 int Detect_Pre(); // 合并图片 int Mergimg(cv::Mat &img, const cv::Mat &img_B, std::string strcam, std::string strchannel); int GetRectAndPoint(const cv::Mat &img,cv::Rect& roi,cv::Point& merg_p_up, cv::Point& merg_p_down,bool bleft , std::string strcam, std::string strchannel); // 检测图片 // 处理每张图片 int Detect_Images(); // 结果参数分析 int ResultParamJudge(); // 边缘处理 int ImgEdge(cv::Mat img, cv::Mat &detMaskImg, cv::Rect &roi, int productIdx); // 插入相机日志 int InsertCameraLog(); ChannelCheckFunction *GetChannelFuntion(std::string strChannelName); // 获得 通道的检测功能 // 预处理 字符检测 int preDet_ZF(std::shared_ptr p, std::shared_ptr &pResult); // 获取 检测核心库 ImgCheckBase *GetDealResult(int idx = -1); // 边缘点搜索函数 int GetEdgePoint(const cv::Mat &img, Edge_Search_Config *pEdge_Search_Config, int &outP); int GetLine(const cv::Mat &img, std::vector &pointList, int lineNum, int xory, int &outP); public: // 运行的基本参数 RunInfoST m_RunConfig; // 检测参数模块 std::shared_ptr m_pConfig; int m_nConfigIdx; // 检测分析参数 AnalysisyConfigST m_AnalysisyConfig; CommonConfigNodeST *m_pCommonAnalysisyConfig; ALLChannelCheckFunction *m_pChannelFuntion; // 画面检测功能 BaseCheckFunction *m_pbaseCheckFunction; // 基础检测 std::shared_ptr m_pdetlog; // 结果分析类 ImageResultJudge m_imageResultJudge; private: // 相机ID std::string m_strcameraName; int m_nErrorCode; // 错误代码 bool m_bInitSucc; // 初始化状态 bool m_bExit; // 是否退出检测 int nLastCheckAnalysisyThreadIdx; // 图片处理线程 std::shared_ptr ptr_thread_Run; std::shared_ptr m_pCheck_Result; bool m_bHaveImgeDet; // 是否有图片需要检查 std::mutex mtx_WaiteImg; // 等待图片的锁 std::condition_variable cond_WaiteImg; // 条件变量,是否有图片需要检查 private: // 检测核心库 ImgCheckBase *m_pImgCheckAnalysisy[IMGCHECKANALYSISY_NUM]; CheckResultJson m_CheckResultJson; private: cv::Mat showimg; bool bshowimg; private: }; #endif