parent
486346db6d
commit
92afa850b7
@ -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
|
||||||
@ -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;
|
||||||
|
}
|
||||||
Loading…
Reference in new issue