|
|
/*
|
|
|
//图片基本处理
|
|
|
*/
|
|
|
#ifndef ImageResultJudge_H_
|
|
|
#define ImageResultJudge_H_
|
|
|
#include "CheckConfigDefine.h"
|
|
|
#include <mutex>
|
|
|
#include <vector>
|
|
|
#include <thread>
|
|
|
#include <string>
|
|
|
#include <stdio.h>
|
|
|
#include <condition_variable>
|
|
|
#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 "QX_Merge_Analysis.h"
|
|
|
class ImageResultJudge
|
|
|
{
|
|
|
private:
|
|
|
enum DrawType
|
|
|
{
|
|
|
Draw_rect,
|
|
|
Draw_circle,
|
|
|
Draw_str,
|
|
|
};
|
|
|
struct txtDrawBackgroundk
|
|
|
{
|
|
|
std::vector<cv::Rect> txtDrawRoi;
|
|
|
cv::Rect findNonOverlappingPos(
|
|
|
const cv::Rect &newRect,
|
|
|
int step = 5,
|
|
|
int maxRadius = 800)
|
|
|
{
|
|
|
// 如果本身就不重叠,直接返回
|
|
|
bool overlap = false;
|
|
|
for (const auto &r : txtDrawRoi)
|
|
|
{
|
|
|
if ((newRect & r).area() > 0)
|
|
|
{
|
|
|
overlap = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!overlap)
|
|
|
return newRect;
|
|
|
// 螺旋搜索
|
|
|
for (int radius = step; radius <= maxRadius; radius += step)
|
|
|
{
|
|
|
for (int dx = -radius; dx <= radius; dx += step)
|
|
|
{
|
|
|
for (int dy = -radius; dy <= radius; dy += step)
|
|
|
{
|
|
|
cv::Rect candidate = newRect + cv::Point(dx, dy);
|
|
|
bool conflict = false;
|
|
|
for (const auto &r : txtDrawRoi)
|
|
|
{
|
|
|
if ((candidate & r).area() > 0)
|
|
|
{
|
|
|
conflict = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!conflict)
|
|
|
{
|
|
|
return candidate; // 找到合适位置
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// printf("find fail ============= \n");
|
|
|
// 实在找不到,就返回原始位置
|
|
|
return newRect;
|
|
|
}
|
|
|
};
|
|
|
struct DrawInfo
|
|
|
{
|
|
|
cv::Mat drawImg;
|
|
|
DrawType type = Draw_rect;
|
|
|
std::vector<std::string> strlist;
|
|
|
cv::Point txtP = cv::Point(0, 0);
|
|
|
cv::Rect roi = cv::Rect(0, 0, 0, 0);
|
|
|
cv::Scalar color = cv::Scalar(255, 0, 255);
|
|
|
cv::Point cp = cv::Point(0, 0);
|
|
|
int dr = 0;
|
|
|
float txtsize = 0.8;
|
|
|
std::shared_ptr<txtDrawBackgroundk> txtbackgroundk;
|
|
|
};
|
|
|
|
|
|
public:
|
|
|
ImageResultJudge(/* args */);
|
|
|
~ImageResultJudge();
|
|
|
|
|
|
int SetAnalysisyConfig(AnalysisyConfigST *pAnalysisyConfig);
|
|
|
int ResultJudge(std::shared_ptr<ImageAllResult> pImageResult);
|
|
|
int UpdateMergedet(std::shared_ptr<CameraResult> pCheck_Result);
|
|
|
|
|
|
int MergeResult(std::shared_ptr<ImageAllResult> pImageResult, QX_Analysis_Result_List *ptemre);
|
|
|
|
|
|
int UpdateConfig(std::string strcameraName);
|
|
|
int DrawResult(std::shared_ptr<ImageAllResult> pImageResult);
|
|
|
|
|
|
// 盲失联合判断:主通道(ms_main_channel)检出的盲失(Other)若在过滤通道(ms_filter_channels)同位置存在缺陷
|
|
|
// (不限制缺陷类型),则不算盲失(撤销NG)。同位置判断参考暗点联合分析:双方按 ms_expand 扩张后计算 IOU, 大于 ms_iou 认为同位置
|
|
|
int FilterMsBlindNG(std::shared_ptr<CameraResult> pCheck_Result);
|
|
|
|
|
|
// cell黑白点联合判断:主通道(cellbw_main_channel)检出的cell黑白点(Cell127 也算白点)在过滤通道
|
|
|
// (cellbw_filter_channels)同位置存在缺陷(不限制缺陷类型)时不算cell黑白点(撤销NG)
|
|
|
// 同位置判断参考暗点联合分析:双方按 cellbw_expand 扩张后计算 IOU, 大于 cellbw_iou 认为同位置
|
|
|
int FilterCellBwNG(std::shared_ptr<CameraResult> pCheck_Result);
|
|
|
|
|
|
private:
|
|
|
// 获取 缺陷在参数列表的位置
|
|
|
int GetParamidx();
|
|
|
int UpdateImgageScale();
|
|
|
int SetInDetConfig(std::string strcameraName);
|
|
|
int SetMergeConfig(std::string strcameraName);
|
|
|
|
|
|
// 参数缺陷类型转 结果参数类型
|
|
|
int ConfigTypeToResultType(int nconfigType);
|
|
|
cv::Rect GetCutRoi(cv::Rect &roi, const cv::Mat &img);
|
|
|
// 获取缺陷 对应的AI输入 输出图片,
|
|
|
int GetAIDetImg(std::shared_ptr<ImageAllResult> pImageResult, cv::Point pcenter, cv::Mat &AI_InImg, cv::Mat &AI_OutImg);
|
|
|
|
|
|
// 绘制并保存结果图开关(base 配置 bDrawAndSave,替代 SAVE_RESIMG 宏)
|
|
|
bool NeedDrawAndSave();
|
|
|
|
|
|
int sendTask(std::shared_ptr<DrawInfo> task);
|
|
|
|
|
|
std::shared_ptr<ImageResultJudge::DrawInfo> GetTask();
|
|
|
|
|
|
void ThreadDraw();
|
|
|
int DrawResultTask(std::shared_ptr<ImageResultJudge::DrawInfo> task);
|
|
|
|
|
|
// 等待 绘制完成
|
|
|
int WaiteDrawComplate();
|
|
|
|
|
|
int AnalysisResult_Pre(QX_ERROR_INFO_ *QX_info); // 弱化处理
|
|
|
|
|
|
// 撤销单个缺陷的NG结果:恢复为OK,移除对应NG小图并回退计数
|
|
|
int UndoNGResult(std::shared_ptr<ImageAllResult> pImageResult, int qxidx, QX_ERROR_INFO_ *QX_info);
|
|
|
|
|
|
// 跨通道同位置判断:当前缺陷(产品坐标系ROI)在过滤通道是否存在同位置缺陷(双方按 expand 扩张后计算IOU)
|
|
|
bool IsOverlapQxInFilterChannels(const std::vector<std::shared_ptr<ImageAllResult>> &imgResults,
|
|
|
const std::string &cur_channel_name,
|
|
|
const std::vector<std::string> &filter_channels,
|
|
|
const std::vector<int> &match_qx_types,
|
|
|
const cv::Rect &qx_product_roi,
|
|
|
int roi_expand, float iou_threshold,
|
|
|
const std::string &strTag,
|
|
|
std::shared_ptr<DetLog> plog);
|
|
|
|
|
|
// 判断盲失(产品坐标系ROI)在配置的过滤通道是否存在同位置缺陷(不限制类型,双方按 expand 扩张后计算IOU)
|
|
|
bool IsOverlapQxInMsFilterChannel(const std::vector<std::shared_ptr<ImageAllResult>> &imgResults,
|
|
|
const std::string &cur_channel_name,
|
|
|
const cv::Rect &qx_product_roi,
|
|
|
int roi_expand, float iou_threshold,
|
|
|
std::shared_ptr<DetLog> plog);
|
|
|
|
|
|
// 跨通道联合判断(通用):主通道中指定类型的NG缺陷,若在过滤通道同位置存在指定类型的缺陷,则撤销该NG
|
|
|
int FilterCrossChannelNG(std::shared_ptr<CameraResult> pCheck_Result,
|
|
|
const std::vector<std::string> &main_channels,
|
|
|
const std::vector<std::string> &filter_channels,
|
|
|
const std::vector<int> &main_qx_types,
|
|
|
const std::vector<int> &match_qx_types,
|
|
|
int roi_expand, float iou_threshold,
|
|
|
const std::string &strTag,
|
|
|
const std::string &strReason);
|
|
|
|
|
|
// 关联过滤源过滤:撤销与关联通道过滤源缺陷重叠的暗点NG结果(含单图判定的单点NG)
|
|
|
int FilterCorrelatedDirtyNG(std::shared_ptr<ImageAllResult> pImageResult);
|
|
|
|
|
|
ChannelCheckFunction *GetChannelFuntion(std::string strChannelName); // 获得 通道的检测功能
|
|
|
|
|
|
int ConfigTypeToQXAnalysis(int nconfigType);
|
|
|
|
|
|
private:
|
|
|
bool m_bExit;
|
|
|
float m_fImgage_Scale_X = 0.1;
|
|
|
float m_fImgage_Scale_Y = 0.1;
|
|
|
// 检测分析参数
|
|
|
AnalysisyConfigST *m_pAnalysisyConfig;
|
|
|
CommonConfigNodeST *m_pCommonAnalysisyConfig;
|
|
|
ALLChannelCheckFunction *m_pChannelFuntion; // 画面检测功能
|
|
|
BaseCheckFunction *m_pbaseCheckFunction; // 基础检测
|
|
|
RegionConfigST *m_pRegionAnalysisyParam; // 分析参数
|
|
|
BasicConfig *m_pBasicConfig;
|
|
|
// 检查缺陷对应参数中的位置。
|
|
|
int m_QxInParamListIdx[CONFIG_QX_NAME_count];
|
|
|
|
|
|
std::queue<std::shared_ptr<DrawInfo>> m_DrawInfoList;
|
|
|
std::mutex m_task_mutex_;
|
|
|
std::condition_variable m_task_cv_;
|
|
|
std::shared_ptr<std::thread> ptr_thread_Draw;
|
|
|
std::condition_variable m_drawComplate_cv_;
|
|
|
|
|
|
std::shared_ptr<QX_Merge_Analysis> m_pQX_Merge_Analysis;
|
|
|
};
|
|
|
|
|
|
#endif |