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.
162 lines
5.0 KiB
162 lines
5.0 KiB
/*
|
|
//图片基本处理
|
|
*/
|
|
#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);
|
|
|
|
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);
|
|
|
|
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); // 弱化处理
|
|
|
|
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 |