|
|
/*
|
|
|
//图片基本处理
|
|
|
*/
|
|
|
#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"
|
|
|
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;
|
|
|
};
|
|
|
|
|
|
struct singleQxInfo{
|
|
|
int qxidx;
|
|
|
int ng_type;
|
|
|
cv::Point pcenter;
|
|
|
singleQxInfo(int qxidx, int ng_type, cv::Point pcenter):qxidx(qxidx),ng_type(ng_type),pcenter(pcenter){}
|
|
|
};
|
|
|
struct singleQxZoningInfo{
|
|
|
float scale_X;
|
|
|
float scale_Y;
|
|
|
float judge_dis;
|
|
|
int judge_num;
|
|
|
Point center;
|
|
|
vector<singleQxInfo> qxList;
|
|
|
void Init(){
|
|
|
scale_X = 0;
|
|
|
scale_Y = 0;
|
|
|
judge_dis = 0;
|
|
|
judge_num = 0;
|
|
|
center = Point(0, 0);
|
|
|
qxList.clear();
|
|
|
}
|
|
|
float calulateDisSquared(cv::Point pcenter){
|
|
|
float dx = (pcenter.x - center.x) * scale_X;
|
|
|
float dy = (pcenter.y - center.y) * scale_Y;
|
|
|
return (pow(dx, 2) + pow(dy, 2));
|
|
|
}
|
|
|
// 由距离来卡控添加缺陷,并更新区域center坐标
|
|
|
bool Insert(singleQxInfo qxInfo){
|
|
|
if(qxList.size() == 0)
|
|
|
{
|
|
|
center = qxInfo.pcenter;
|
|
|
qxList.push_back(qxInfo);
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if(calulateDisSquared(qxInfo.pcenter) < judge_dis * judge_dis)
|
|
|
{
|
|
|
center = Point((qxInfo.pcenter.x + center.x) / 2, (qxInfo.pcenter.y + center.y) / 2);
|
|
|
qxList.push_back(qxInfo);
|
|
|
return true;
|
|
|
}
|
|
|
else return false;
|
|
|
}
|
|
|
}
|
|
|
bool judgeNum(){
|
|
|
if(qxList.size() >= judge_num) return true;
|
|
|
else return false;
|
|
|
}
|
|
|
};
|
|
|
struct usenumQxZoningInfo{
|
|
|
vector<singleQxZoningInfo> singleQxZoningList;
|
|
|
};
|
|
|
struct ictQxZoningInfo{
|
|
|
vector<usenumQxZoningInfo> usenumQxZoningList;
|
|
|
};
|
|
|
struct iregionQxZoningInfo{
|
|
|
vector<ictQxZoningInfo> ictQxZoningList;
|
|
|
};
|
|
|
public:
|
|
|
ImageResultJudge(/* args */);
|
|
|
~ImageResultJudge();
|
|
|
|
|
|
int SetAnalysisyConfig(AnalysisyConfigST *pAnalysisyConfig);
|
|
|
int ResultJudge(std::shared_ptr<ImageAllResult> pImageResult);
|
|
|
int UpdateConfig();
|
|
|
int DrawResult(std::shared_ptr<ImageAllResult> pImageResult);
|
|
|
|
|
|
private:
|
|
|
// 获取 缺陷在参数列表的位置
|
|
|
int GetParamidx();
|
|
|
int UpdateImgageScale();
|
|
|
|
|
|
int addInDrawBlob(int errortype, int blobidx, QX_ERROR_INFO_ *QX_info, float fs_resize_x, float fs_resize_y);
|
|
|
// 参数缺陷类型转 结果参数类型
|
|
|
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);
|
|
|
|
|
|
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();
|
|
|
|
|
|
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_;
|
|
|
};
|
|
|
|
|
|
#endif |