update 修改标签屏蔽(模型检测)

main
liusiyang 1 month ago
parent 486346db6d
commit 92afa850b7

@ -174,6 +174,8 @@ public:
std::shared_ptr<AIModel_Base> AI_defect_zf; // L127 L255
std::shared_ptr<AIModel_Base> AI_defect_bq; // L127 L255
std::shared_ptr<AIModel_Base> AI_defect_127Cell; // L127 L255
std::shared_ptr<AIModel_Base> AI_defect_RE_POL; // L127 L255

@ -143,6 +143,17 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig)
boe_config.inputType = AIModel_Base::Input_CHW;
AI_defect_zf->Init(boe_config);
}
// 标签 检测
if (!AI_defect_bq)
{
AI_defect_bq = AIModel_Base::GetInstance();
AIModel_Base::AIModelRun_Config boe_config;
boe_config.gpuconfig.copy(gupconfig);
boe_config.strPath = "/home/aidlux/BOE/UseModel_FOG/FOG_tag.engine";
boe_config.strName = "bq";
boe_config.inputType = AIModel_Base::Input_CHW;
AI_defect_bq->Init(boe_config);
}
// 字符 127cell
if (!AI_defect_127Cell)
{

@ -0,0 +1,85 @@
/*
* @Author: xiewenji 527774126@qq.com
* @Date: 2025-09-25 16:25:30
* @LastEditors: xiewenji 527774126@qq.com
* @LastEditTime: 2025-09-25 17:16:49
* @FilePath: /BOE_POL_ET_Detect/AlgorithmModule/include/AI_Mark_Det.h
* @Description: ,`customMade`, koroFileHeader : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
/*
//实现对部分缺陷 需要进行 数量 和距离上分析的
*/
#ifndef AI_BQ_Det_H_
#define AI_BQ_Det_H_
#include <opencv2/opencv.hpp>
#include "CheckUtil.hpp"
#include "OtherDetect.h"
#include "OtherDetBaseDefine.h"
#include "CheckErrorCodeDefine.hpp"
#include "ImageDetConfig.h"
#include "CheckConfigDefine.h"
#include "ImageStorage.h"
#include "AI_Factory.h"
using namespace std;
using namespace cv;
// 二次分割求面积
class AI_BQ_Det
{
public:
// 检测参数和结果
struct DetConfigResult
{
std::string strCamName;
int nresult;
std::shared_ptr<BQ_Result> pBQ_Result;
bool bDebugsaveimg;
bool bDetSaveImg;
std::shared_ptr<DetLog> pdetlog;
DetConfigResult()
{
nresult = -1;
strCamName = "";
bDebugsaveimg = false;
bDetSaveImg = false;
}
};
public:
AI_BQ_Det(/* args */);
~AI_BQ_Det();
int Detect(const cv::Mat &img, DetConfigResult *pDetConfig);
private:
int Det_img(const cv::Mat &img, DetConfigResult *pDetConfig);
// 分析结果
int Analysisy(const cv::Mat &maskImg, DetConfigResult *pDetConfig);
// 存储过程图片
int SaveProcessImg(const cv::Mat &inImg, const cv::Mat &outImg, const cv::Mat &oldmask, DetConfigResult *pDetConfig);
private:
bool m_bModelSucc;
cv::Mat detimg123;
ImageStorage *m_pImageStorage;
std::shared_ptr<AIFactory> AI_Factory;
std::shared_ptr<DetLog> m_pdetlog;
int m_Show_Area;
float m_Show_Len;
cv::Point m_Len_P1;
cv::Point m_Len_P2;
private:
/* data */
};
#endif

@ -31,6 +31,7 @@
#include "Edge_Search.h"
#include "AI_Mark_Det.h"
#include "AI_ZF_Det.h"
#include "AI_BQ_Det.h"
#include "ImageMerge.h"
#include "QX_Merge_Analysis.h"
using namespace std;
@ -130,6 +131,8 @@ public:
// 字符检测
AI_ZF_Det m_ZF_Det;
// 标签检测
AI_BQ_Det m_BQ_Det;
ImageMerge m_ImageMerge;

@ -343,7 +343,7 @@ struct ZF_Result
struct BQ_Result
{
int nresult = 1;
bool bShield_BQ = false; // 是否屏蔽标签
bool bShield_BQ = true; // 是否屏蔽标签
std::vector<cv::Rect> pBQ_roiList; // 标签的区域
std::vector<cv::Point> BQ_centerPoint; // 标签的中心点位置
};

@ -0,0 +1,157 @@
#include "AI_BQ_Det.h"
#include "CheckErrorCodeDefine.hpp"
static bool compareContourAreas123(const vector<Point> &contour1, const vector<Point> &contour2)
{
double i = contourArea(contour1);
double j = contourArea(contour2);
return (i > j);
}
AI_BQ_Det::AI_BQ_Det()
{
m_bModelSucc = false;
CheckUtil::CreateDir("/home/aidlux/BOE/FOG/bq/");
m_pImageStorage = ImageStorage::getInstance();
m_Show_Area = 0;
m_Show_Len = 0;
m_Len_P1 = cv::Point(0, 0);
m_Len_P2 = cv::Point(0, 0);
AI_Factory = AIFactory::GetInstance();
}
AI_BQ_Det::~AI_BQ_Det()
{
}
int AI_BQ_Det::Detect(const cv::Mat &img, DetConfigResult *pDetConfig)
{
std::shared_ptr<AIModel_Base> pAI_Model = AI_Factory->AI_defect_bq;
m_pdetlog = pDetConfig->pdetlog;
cv::Size sz;
sz.width = pAI_Model->input_0.width;
sz.height = pAI_Model->input_0.height;
cv::Mat inImg;
cv::Mat AIoutimg;
cv::resize(img, inImg, sz, 0, 0, cv::INTER_AREA);
pAI_Model->AIDet(inImg, AIoutimg);
if (pDetConfig->bDebugsaveimg)
{
if (!inImg.empty())
{
cv::imwrite("BQ_img_In.png", inImg);
}
if (!AIoutimg.empty())
{
cv::imwrite("BQ_img_out.png", AIoutimg);
}
}
{
float fx = img.cols * 1.0f / AIoutimg.cols;
float fy = img.rows * 1.0f / AIoutimg.rows;
// 轮廓检测
std::vector<std::vector<cv::Point>> contours;
findContours(AIoutimg, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
// 根据面积大小对轮廓进行排序
sort(contours.begin(), contours.end(), compareContourAreas123);
int kd = 0;
for (size_t i = 0; i < contours.size(); ++i)
{
// 获取当前轮廓的边界矩形
cv::Rect boundingRect = cv::boundingRect(contours[i]);
cv::Rect roi;
roi.x = boundingRect.x * fx;
roi.y = boundingRect.y * fy;
roi.width = boundingRect.width * fx;
roi.height = boundingRect.height * fy;
pDetConfig->pBQ_Result->pBQ_roiList.push_back(roi);
kd++;
if (kd >= 2)
{
break;
}
}
}
return 0;
}
int AI_BQ_Det::Det_img(const cv::Mat &img, DetConfigResult *pDetConfig)
{
return 0;
}
int AI_BQ_Det::Analysisy(const cv::Mat &maskImg, DetConfigResult *pDetConfig)
{
return 0;
}
int AI_BQ_Det::SaveProcessImg(const cv::Mat &inImg, const cv::Mat &outImg, const cv::Mat &oldmask, DetConfigResult *pDetConfig)
{
// if (inImg.empty() || outImg.empty())
// {
// return 1;
// }
// static int saveimgIdx_pol = 0;
// static int saveimgIdx_ad = 0;
// // 循环存储
// std::string str_Root = "/home/aidlux/BOE/Second/";
// if (pDetConfig->qx_type == CONFIG_QX_NAME_POL_Cell)
// {
// saveimgIdx_pol++;
// if (saveimgIdx_pol > 1000)
// {
// saveimgIdx_pol = 0;
// }
// str_Root += "POL/POl_" + pDetConfig->strChannel + "_" + std::to_string(saveimgIdx_pol);
// }
// if (pDetConfig->qx_type == CONFIG_QX_NAME_AD)
// {
// saveimgIdx_ad++;
// if (saveimgIdx_ad > 1000)
// {
// saveimgIdx_ad = 0;
// }
// str_Root += "AD/AD_" + pDetConfig->strChannel + "_" + std::to_string(saveimgIdx_ad);
// }
// std::string strIn = str_Root + +"_in.png";
// int re = 0;
// if (!inImg.empty())
// {
// re = m_pImageStorage->addImage(strIn, inImg);
// }
// if (re == 0)
// {
// std::string strmask = str_Root + "_in_mask.png";
// if (!outImg.empty())
// {
// m_pImageStorage->addImage(strmask, outImg, true); // 强制 存储
// }
// std::string stroldmask = str_Root + "_old_mask.png";
// if (!oldmask.empty())
// {
// m_pImageStorage->addImage(stroldmask, oldmask, true); // 强制 存储
// }
// }
return 0;
}

@ -679,37 +679,49 @@ int CameraCheckAnalysisy::preDet_ZF(const cv::Mat &L255CutImg, std::shared_ptr<I
return 0;
}
int CameraCheckAnalysisy::preDet_BQ(const cv::Mat &L255CutImg, std::shared_ptr<ImageAllResult> L255)
{
{
long ts = CheckUtil::getcurTime();
m_pCheck_Result->cameraBaseResult->pBQ_Result = std::make_shared<BQ_Result>();
m_pCheck_Result->cameraBaseResult->pBQ_Result->bShield_BQ = m_AnalysisyConfig.commonCheckConfig.baseConfig.bShield_BQ;
cv::Rect Det_CropRoi = m_pCheck_Result->cameraBaseResult->pEdgeDetResult->cutRoi;
AI_BQ_Det::DetConfigResult detresult;
detresult.strCamName = m_strcameraName;
detresult.bDebugsaveimg = L255->result->in_shareImage->bDebugsaveImg;
detresult.pdetlog = m_pdetlog;
if (DET_MODE_ZF == L255->result->in_shareImage->Det_Mode)
{
detresult.bDetSaveImg = true;
}
detresult.pBQ_Result = m_pCheck_Result->cameraBaseResult->pBQ_Result;
cv::Mat detimg = L255CutImg;
int re = BQ_Det(detimg, m_pCheck_Result->cameraBaseResult->pBQ_Result);
// 屏蔽标签
int re = m_BQ_Det.Detect(detimg, &detresult);
if (re != 0)
{
return re;
}
// 如果要屏蔽标签
if (m_pCheck_Result->cameraBaseResult->pBQ_Result->bShield_BQ)
{
m_pdetlog->AddCheckstr(PrintLevel_2, "preDet_BQ", "shieldBQ is Open");
cv::Mat detImg_mask = m_pCheck_Result->cameraBaseResult->pEdgeDetResult->shieldMask;
for (int i = 0; i < m_pCheck_Result->cameraBaseResult->pBQ_Result->pBQ_roiList.size(); i++)
{
cv::Rect boundingRect = m_pCheck_Result->cameraBaseResult->pBQ_Result->pBQ_roiList.at(i);
boundingRect.x -= 50;
boundingRect.y -= 50;
boundingRect.width += 100;
boundingRect.height += 100;
if(CheckUtil::JudgRect(boundingRect, detimg.cols, detimg.rows))
detImg_mask(boundingRect).setTo(255);
else
m_pdetlog->AddCheckstr(PrintLevel_2, "preDet_BQ", "detImg_mask fail !!!");
// cv::imwrite("BQ_sheildImg.png", m_pCheck_Result->cameraBaseResult->pEdgeDetResult->shieldMask);
detImg_mask(boundingRect).setTo(255);
}
if (L255->result->in_shareImage->bDebugsaveImg)
{
// cv::imwrite("sheildImg.png", m_pCheck_Result->cameraBaseResult->pEdgeDetResult->shieldMask);
cv::imwrite("sheildImg.png", m_pCheck_Result->cameraBaseResult->pEdgeDetResult->shieldMask);
}
}
else
{
m_pdetlog->AddCheckstr(PrintLevel_2, "preDet_BQ", "shieldBQ is false");
}
std::shared_ptr<BQ_Result> pBQ_Result = m_pCheck_Result->cameraBaseResult->pBQ_Result; // BQ 检测结果
pBQ_Result->BQ_centerPoint.erase(pBQ_Result->BQ_centerPoint.begin(), pBQ_Result->BQ_centerPoint.end());
for (int i = 0; i < pBQ_Result->pBQ_roiList.size(); i++)
@ -719,15 +731,17 @@ int CameraCheckAnalysisy::preDet_BQ(const cv::Mat &L255CutImg, std::shared_ptr<I
cv::Point p;
p.x = boundingRect.x + boundingRect.width * 0.5f;
p.y = boundingRect.y + boundingRect.height * 0.5f;
// printf("--- bq %d %d %d %d \n", boundingRect.x, boundingRect.y, boundingRect.width, boundingRect.height);
// printf("--- zf %d %d %d %d \n", boundingRect.x, boundingRect.y, boundingRect.width, boundingRect.height);
pBQ_Result->BQ_centerPoint.push_back(p);
}
if (L255->result->in_shareImage->bDebugsaveImg)
{
cv::Mat showimg = detimg.clone();
for (int i = 0; i < m_pCheck_Result->cameraBaseResult->pBQ_Result->pBQ_roiList.size(); i++)
{
cv::Rect boundingRect = m_pCheck_Result->cameraBaseResult->pBQ_Result->pBQ_roiList.at(i);
cv::rectangle(showimg, boundingRect, cv::Scalar(200), 5);
}
cv::imwrite("bq_result.png", showimg);
@ -737,6 +751,7 @@ int CameraCheckAnalysisy::preDet_BQ(const cv::Mat &L255CutImg, std::shared_ptr<I
m_pdetlog->AddCheckstr(PrintLevel_1, "preDet_BQ", "==================End bq num %ld re = %d time %ld ms ", m_pCheck_Result->cameraBaseResult->pBQ_Result->pBQ_roiList.size(), re, te - ts);
return 0;
}
int CameraCheckAnalysisy::Init(std::string strcameraName)
{
m_strcameraName = strcameraName;

Loading…
Cancel
Save