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.

228 lines
6.6 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.

/*
* @Author: your name
* @Date: 2022-04-20 15:49:50
* @LastEditTime: 2025-10-09 18:21:49
* @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 ImageAllResult_H_
#define ImageAllResult_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 <stdlib.h>
#include "Define_Product.hpp"
#include "CheckErrorCodeDefine.hpp"
#include "ImgCheckConfig.h"
#include "ImageDetConfig.h"
#include "DetLog.h"
#include "CheckResultJson.h"
using namespace std;
using namespace cv;
// 包含所有的图片检测结果,如 返回的结果,临时结果, 其他检测结果
class ImageAllResult
{
public:
enum DetStep
{
DetStep_NotDet,
DetStep_Deting,
DetStep_Complet,
};
struct AI_Det_MaskImg
{
cv::Rect roi;
cv::Mat AI_inImg;
cv::Mat AI_mask;
};
struct Config_Update
{
bool bUpdate = false;
bool wait_DP= false;
bool wait_UP= false;
};
// AI MaskImg 的相关使用的参数信息。
struct AI_MaskImg_BlobParam
{
unsigned char *imgBlobHFlagData = NULL; // mask 图片在 Y方向是否有餐点用以加速 blob 分析。
std::queue<std::shared_ptr<AI_Det_MaskImg>> AIMaskImgBLobQueue; // AI 中间结果 队列
std::mutex mtx_AIMaskImgBLobQueue;
int ndatalen;
AI_MaskImg_BlobParam()
{
Init();
}
void Init()
{
if (imgBlobHFlagData != NULL)
{
delete[] imgBlobHFlagData;
imgBlobHFlagData = NULL;
}
ndatalen = 0;
}
void InitBLobHData(int ndataLen)
{
if (imgBlobHFlagData != NULL)
{
delete[] imgBlobHFlagData;
imgBlobHFlagData = NULL;
}
ndatalen = ndataLen;
imgBlobHFlagData = new unsigned char[ndataLen];
}
~AI_MaskImg_BlobParam()
{
Init();
}
};
// 图片的AI 检测相关结果。
// 兼容多种AI模型输出结果的。
struct Image_AI_Det_Result
{
bool bDet; // 是否有检测
int Model_in_Image_width; // AI 检测图片的宽度
int Model_in_Image_height; // AI 检测图片的高度
int Model_out_Image_width; // AI 推理后的图片的宽度
int Model_out_Image_height; // AI 推理后的图片的宽度
cv::Mat AI_MaskImg; // AI 推理的mask图片
std::vector<std::shared_ptr<AI_Det_MaskImg>> AI_Qx_MaskList; // AI 推理 输出中间结果信息。
std::shared_ptr<AI_MaskImg_BlobParam> blobDetParam; // BLob 检测要用到的一些 参数 。
Image_AI_Det_Result()
{
Init();
}
void Init()
{
bDet = false;
Model_in_Image_width = 0;
Model_in_Image_height = 0;
Model_out_Image_width = 0;
Model_out_Image_height = 0;
if (AI_MaskImg.empty())
{
AI_MaskImg.release();
}
AI_Qx_MaskList.clear();
blobDetParam = std::make_shared<AI_MaskImg_BlobParam>();
}
void InitBLobHData(int ndataLen)
{
blobDetParam->InitBLobHData(ndataLen);
}
~Image_AI_Det_Result()
{
Init();
}
};
struct WTB_Check_Result_
{
cv::Rect roi_src;
cv::Rect roi_show;
WTB_Check_Result_()
{
Init();
}
void Init()
{
roi_src = cv::Rect(0, 0, 0, 0);
roi_show = cv::Rect(0, 0, 0, 0);
}
};
private:
/* data */
public:
ImageAllResult(/* args */);
~ImageAllResult();
void AddLog(std::string str);
// 添加图片信息
int AddDetImage(std::shared_ptr<shareImage> p);
DetStep getStep();
void setStep(DetStep step);
bool IsNotDet();
bool IsChannel(std::string strChannelName);
public:
// 裁切大小
cv::Rect CropRoi = cv::Rect(0, 0, 0, 0);
// 检测的原始图片
cv::Mat detImg;
// 专用于 AI 检测的图片,如果 AI的输入尺寸 大于原始图片的尺寸,则 AIDetImg 要进行合理的扩展。
cv::Mat AI_detImg;
// AI 推理的mask图片
cv::Mat AIMaskImg;
// AI 127Cell推理的mask图片
cv::Mat AI_127CellMaskImg;
std::shared_ptr<Image_AI_Det_Result> qx_DetAIResult; // BLob 检测要用到的一些 参数 。
std::shared_ptr<Image_AI_Det_Result> cell127_DetAIResult; // 127 cell 检测要用到的一些 参数 。
// 结果图片
cv::Mat resultImg;
// 屏蔽图片 = 搜索边界的 屏蔽区域 +字符的屏蔽区 + 界面绘制的屏蔽区域
cv::Mat shieldImg;
// 专用于 AI 检测的屏蔽图片,如果 AI的输入尺寸 大于原始图片的尺寸,则 AI_shieldImg 要进行合理的扩展。
cv::Mat AI_shieldImg;
// 异显mask图片
cv::Mat YX_MaskImg;
// 缺失polmask图片
cv::Mat LcakPol_MaskImg;
float fscale_detToresult_x = 0;
float fscale_detToresult_y = 0;
int NG_num = 0;
int YS_num = 0;
int Ok_num = 0;
int NoJudge_num = 0;
int AI_Det_Img_Width = 0; // AI 检测图片的宽度
int AI_Det_Img_Height = 0; // AI 检测图片的宽度
bool bChangeSize = false; // 是否改变尺寸
bool bWhiteOrBlackImg = false; // 是否是白底黑字图片
bool bOnlyBlob = false;
Config_Update config_update;
public:
DetStep m_step = DetStep_NotDet;
std::string strBaseInfo = "";
std::string strChannel = "";
std::vector<std::string> LogList;
std::shared_ptr<DetLog> detlog;
std::shared_ptr<CheckResult> result; // 返回检测结果
std::shared_ptr<One_Image_CheckResult_> pDetResult; // 检测结果 后续主要对pDetResult 继续分析
std::shared_ptr<ProductBaseResult> productBaseResult; // 产品相关的基本结果信息
std::shared_ptr<CameraBaseResult> cameraBaseResult; // 相机相关的基本结果信息
std::shared_ptr<WTB_Check_Result_> pWTB_Check_Result;
std::vector<std::shared_ptr<AI_Det_MaskImg>> AI_Qx_MaskList;
std::mutex mtx_Det; // 互斥量
private:
PRINT_LOG_ m_PrintLog;
CheckResultJson m_CheckResultJson;
};
#endif