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.
BOE_FOG_DETECT/AlgorithmModule/src/ImageAllResult.cpp

191 lines
4.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* @Author: xiewenji 527774126@qq.com
* @Date: 2025-09-13 20:39:37
* @LastEditors: xiewenji 527774126@qq.com
* @LastEditTime: 2025-09-24 14:17:55
* @FilePath: /BOE_FOG_Detect/AlgorithmModule/src/CameraResult.cpp
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
#include "ImageAllResult.h"
ImageAllResult::ImageAllResult()
{
detlog = std::make_shared<DetLog>();
pDetResult = std::make_shared<One_Image_CheckResult_>();
}
ImageAllResult::~ImageAllResult()
{
}
// ✅ 处理完成后释放中间 cv::Mat 数据,减少内存占用
// 注意CheckResultresult中的图像数据必须保留
void ImageAllResult::ReleaseIntermediateData()
{
std::lock_guard<std::mutex> lock_cam(mtx_Det);
// ✅ 释放原始输入图像(处理完成后不再需要)
if (result && result->in_shareImage)
{
if (!result->in_shareImage->img.empty())
{
result->in_shareImage->img.release();
}
if (!result->in_shareImage->AI_maskImg.empty())
{
result->in_shareImage->AI_maskImg.release();
}
}
// ✅ AI_Time 开启时需要保留 detImg用于生成缺陷小图和 AI_Qx_MaskList用于 AI 调试图像)
// 其他中间数据可以安全释放
#ifndef AI_Time
if (!detImg.empty()) { detImg.release(); }
#endif
if (!AI_detImg.empty()) { AI_detImg.release(); }
if (!AIMaskImg.empty()) { AIMaskImg.release(); }
if (!AI_127CellMaskImg.empty()) { AI_127CellMaskImg.release(); }
if (!resultImg.empty()) { resultImg.release(); }
if (!shieldImg.empty()) { shieldImg.release(); }
if (!AI_shieldImg.empty()) { AI_shieldImg.release(); }
if (!YX_MaskImg.empty()) { YX_MaskImg.release(); }
if (!LcakPol_MaskImg.empty()) { LcakPol_MaskImg.release(); }
// 释放 AI 检测中间结果
if (qx_DetAIResult) { qx_DetAIResult->Init(); }
if (cell127_DetAIResult) { cell127_DetAIResult->Init(); }
// ✅ AI_Time 开启时需要保留 AI_Qx_MaskListGetAIDetImg 使用)
#ifndef AI_Time
AI_Qx_MaskList.clear();
#endif
}
void ImageAllResult::AddLog(std::string str)
{
LogList.push_back(str);
}
ImageAllResult::DetStep ImageAllResult::getStep()
{
std::lock_guard<std::mutex> lock_cam(mtx_Det);
return m_step;
}
void ImageAllResult::setStep(DetStep step)
{
std::lock_guard<std::mutex> lock_cam(mtx_Det);
m_step = step;
}
bool ImageAllResult::IsNotDet()
{
std::lock_guard<std::mutex> lock_cam(mtx_Det);
if (m_step == DetStep_NotDet)
{
return true;
}
return false;
}
bool ImageAllResult::IsChannel(std::string strChannelName)
{
std::lock_guard<std::mutex> lock_cam(mtx_Det);
if (strChannel == strChannelName)
{
return true;
}
return false;
}
int ImageAllResult::AddDetImage(std::shared_ptr<shareImage> p)
{
{
std::lock_guard<std::mutex> lock_cam(mtx_Det);
result = std::make_shared<CheckResult>();
p->time_PushIn = CheckUtil::getcurTime();
result->in_shareImage = p;
result->checkStatus = 1;
result->nDetStep = 0;
result->nresult = -1;
result->basicResult.img_id = p->img_id;
result->basicResult.imgtype = p->imgtype;
result->basicResult.imgstr = p->imgstr;
result->basicResult.strChannel = p->strChannel;
strChannel = p->strChannel;
if (strChannel == "Up-Particle")
{
cameraBaseResult->UpImg_Status = CameraBaseResult::ImageDet_Status_NoDet;
}
if (strChannel == "Down-Particle")
{
cameraBaseResult->DPImg_Status = CameraBaseResult::ImageDet_Status_NoDet;
}
}
// 需要指定 黑白画面
if (strChannel == "BTW" ||
strChannel == "WTB" ||
strChannel == "TBW" ||
strChannel == "HB3" ||
strChannel == "HB4")
{
bWhiteOrBlackImg = true;
}
strBaseInfo = productBaseResult->strproductName + " cam " + cameraBaseResult->strCameraName + " channel " + strChannel;
if (p->Det_Mode == DET_MODE_ReJson)
{
m_CheckResultJson.GetConfig(p->resultJson, pDetResult);
fscale_detToresult_x = 1;
fscale_detToresult_y = 1;
// 图片
if (!p->img.empty())
{
detImg = p->img;
/* code */
}
else
{
if (pDetResult->CutRoi.width > 0 && pDetResult->CutRoi.height > 0)
{
detImg = cv::Mat::zeros(pDetResult->CutRoi.height, pDetResult->CutRoi.width, CV_8UC1);
}
else
{
detImg = cv::Mat::zeros(1000, 2000, CV_8UC1);
}
}
{
cv::Size sz;
sz.width = RESIZE_IMAGE_WIDTH;
float fw = RESIZE_IMAGE_WIDTH * 1.0f / detImg.cols;
sz.height = int(detImg.rows * fw);
cv::resize(detImg, resultImg, sz);
if (resultImg.channels() == 1)
{
cv::cvtColor(resultImg, resultImg, cv::COLOR_GRAY2BGR);
}
result->resultimg = resultImg;
result->cutSrcimg = detImg;
fscale_detToresult_x = resultImg.cols * 1.0f / detImg.cols;
fscale_detToresult_y = resultImg.rows * 1.0f / detImg.rows;
}
// pDetResult->print("result");
// getchar();
}
return 0;
}