|
|
|
@ -1,6 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "ImageResultJudge.h"
|
|
|
|
#include "ImageResultJudge.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检测图坐标 -> 原图坐标(detToSrcMat 非空时按矩阵映射; 否则退回 CutRoi 平移)
|
|
|
|
|
|
|
|
static cv::Rect DetRoiToSrcRoi(const cv::Mat &detToSrcMat, cv::Rect detRoi, const cv::Rect &cutRoi, const cv::Size &srcSize)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (detToSrcMat.empty() || detToSrcMat.rows != 2 || detToSrcMat.cols != 3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cv::Rect srcRoi = detRoi;
|
|
|
|
|
|
|
|
srcRoi.x += cutRoi.x;
|
|
|
|
|
|
|
|
srcRoi.y += cutRoi.y;
|
|
|
|
|
|
|
|
return srcRoi;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const double *m = detToSrcMat.ptr<double>(0);
|
|
|
|
|
|
|
|
cv::Point2f pts[4] = {
|
|
|
|
|
|
|
|
cv::Point2f((float)detRoi.x, (float)detRoi.y),
|
|
|
|
|
|
|
|
cv::Point2f((float)(detRoi.x + detRoi.width), (float)detRoi.y),
|
|
|
|
|
|
|
|
cv::Point2f((float)(detRoi.x + detRoi.width), (float)(detRoi.y + detRoi.height)),
|
|
|
|
|
|
|
|
cv::Point2f((float)detRoi.x, (float)(detRoi.y + detRoi.height))};
|
|
|
|
|
|
|
|
float fminX = 1e18f, fmaxX = -1e18f, fminY = 1e18f, fmaxY = -1e18f;
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
float x = (float)(m[0] * pts[i].x + m[1] * pts[i].y + m[2]);
|
|
|
|
|
|
|
|
float y = (float)(m[3] * pts[i].x + m[4] * pts[i].y + m[5]);
|
|
|
|
|
|
|
|
if (x < fminX)
|
|
|
|
|
|
|
|
fminX = x;
|
|
|
|
|
|
|
|
if (x > fmaxX)
|
|
|
|
|
|
|
|
fmaxX = x;
|
|
|
|
|
|
|
|
if (y < fminY)
|
|
|
|
|
|
|
|
fminY = y;
|
|
|
|
|
|
|
|
if (y > fmaxY)
|
|
|
|
|
|
|
|
fmaxY = y;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cv::Rect srcRoi(cvFloor(fminX), cvFloor(fminY), cvCeil(fmaxX) - cvFloor(fminX), cvCeil(fmaxY) - cvFloor(fminY));
|
|
|
|
|
|
|
|
if (srcSize.width > 0 && srcSize.height > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
srcRoi &= cv::Rect(0, 0, srcSize.width, srcSize.height);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return srcRoi;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从原图取缺陷小图:detCutRoi 为检测图坐标下的截取框;输出按检测图坐标映射从原图取回(原图通道)
|
|
|
|
|
|
|
|
static bool WarpSrcCutImg(const cv::Mat &srcImg, const cv::Mat &detToSrcMat, const cv::Rect &detCutRoi, cv::Mat &outPatch)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
outPatch.release();
|
|
|
|
|
|
|
|
if (srcImg.empty() || detToSrcMat.empty() || detToSrcMat.rows != 2 || detToSrcMat.cols != 3 ||
|
|
|
|
|
|
|
|
detCutRoi.width <= 0 || detCutRoi.height <= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// detCutRoi 四角映射回原图,得到需要取的原图范围
|
|
|
|
|
|
|
|
cv::Rect srcBBox = DetRoiToSrcRoi(detToSrcMat, detCutRoi, cv::Rect(0, 0, 0, 0), srcImg.size());
|
|
|
|
|
|
|
|
if (srcBBox.width <= 0 || srcBBox.height <= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// dst 为截取框局部坐标, src 为原图坐标(再平移到 srcBBox 内):
|
|
|
|
|
|
|
|
// src = detToSrcMat * (dst + detCutRoi.tl()) - srcBBox.tl()
|
|
|
|
|
|
|
|
cv::Mat mat = detToSrcMat.clone();
|
|
|
|
|
|
|
|
mat.at<double>(0, 2) += mat.at<double>(0, 0) * detCutRoi.x + mat.at<double>(0, 1) * detCutRoi.y - srcBBox.x;
|
|
|
|
|
|
|
|
mat.at<double>(1, 2) += mat.at<double>(1, 0) * detCutRoi.x + mat.at<double>(1, 1) * detCutRoi.y - srcBBox.y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cv::warpAffine(srcImg(srcBBox), outPatch, mat, detCutRoi.size(), cv::INTER_LINEAR, cv::BORDER_REPLICATE);
|
|
|
|
|
|
|
|
return !outPatch.empty();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ImageResultJudge::ImageResultJudge(/* args */)
|
|
|
|
ImageResultJudge::ImageResultJudge(/* args */)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_pCommonAnalysisyConfig = NULL;
|
|
|
|
m_pCommonAnalysisyConfig = NULL;
|
|
|
|
@ -271,36 +337,17 @@ int ImageResultJudge::ResultJudge(std::shared_ptr<ImageAllResult> pImageResult)
|
|
|
|
allQxZoning[qx_name].push_back(singleQxZoningInfoTemp);
|
|
|
|
allQxZoning[qx_name].push_back(singleQxZoningInfoTemp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 黑缺陷
|
|
|
|
// 不区分亮暗缺陷: 参数(阈值)按正数配置; 实测灰阶/能量可能为负, 取绝对值后参与比较
|
|
|
|
if (QX_whiteBLACK == CONFIG_QX_WHITE)
|
|
|
|
int energyAbs = std::abs(energy);
|
|
|
|
{
|
|
|
|
float grayDisAbs = std::abs(grayDis);
|
|
|
|
// pQxLog->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "param---", "qx :white");
|
|
|
|
|
|
|
|
if (hj >= 0 || Et >= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, "param ", "Error param idx %d / %d qx white hj %f and energ %f >0",
|
|
|
|
|
|
|
|
j + 1, pParam->useNum, hj, Et);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Et = std::abs(Et);
|
|
|
|
|
|
|
|
hj = std::abs(hj);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// pQxLog->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "param---", "qx :blcak");
|
|
|
|
|
|
|
|
if (hj < 0 || Et < 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, "param ", "Error param idx %d / %d qx blcak hj %f and energ %f < 0",
|
|
|
|
|
|
|
|
j + 1, pParam->useNum, hj, Et);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Judge_Status = true;
|
|
|
|
Judge_Status = true;
|
|
|
|
|
|
|
|
|
|
|
|
float detArea = JudgArea;
|
|
|
|
float detArea = JudgArea;
|
|
|
|
|
|
|
|
|
|
|
|
if (energy >= Et &&
|
|
|
|
if (energyAbs >= Et &&
|
|
|
|
detArea >= At &&
|
|
|
|
detArea >= At &&
|
|
|
|
grayDis >= hj &&
|
|
|
|
grayDisAbs >= hj &&
|
|
|
|
flen >= Len &&
|
|
|
|
flen >= Len &&
|
|
|
|
fbreadth >= Breadth)
|
|
|
|
fbreadth >= Breadth)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -330,15 +377,15 @@ int ImageResultJudge::ResultJudge(std::shared_ptr<ImageAllResult> pImageResult)
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, "Area", "%s -> %f %s %f ",
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, "Area", "%s -> %f %s %f ",
|
|
|
|
BOOL_TO_STR(detArea >= At), detArea, BOOL_TO_ThanLess(detArea >= At), At);
|
|
|
|
BOOL_TO_STR(detArea >= At), detArea, BOOL_TO_ThanLess(detArea >= At), At);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (energy < Et)
|
|
|
|
if (energyAbs < Et)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, "Energy", "%s -> %d %s %f ",
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, "Energy", "%s -> %d %s %f ",
|
|
|
|
BOOL_TO_STR(energy >= Et), energy, BOOL_TO_ThanLess(energy >= Et), Et);
|
|
|
|
BOOL_TO_STR(energyAbs >= Et), energyAbs, BOOL_TO_ThanLess(energyAbs >= Et), Et);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (grayDis < hj)
|
|
|
|
if (grayDisAbs < hj)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, "HJ", "%s -> %f %s %f ",
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, "HJ", "%s -> %f %s %f ",
|
|
|
|
BOOL_TO_STR(grayDis >= hj), grayDis, BOOL_TO_ThanLess(grayDis > hj), hj);
|
|
|
|
BOOL_TO_STR(grayDisAbs >= hj), grayDisAbs, BOOL_TO_ThanLess(grayDisAbs > hj), hj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flen < Len)
|
|
|
|
if (flen < Len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -379,15 +426,22 @@ int ImageResultJudge::ResultJudge(std::shared_ptr<ImageAllResult> pImageResult)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 标签缺陷:检测到标签直接判 NG
|
|
|
|
std::string resultType = "OK";
|
|
|
|
if (config_qx_type == CONFIG_QX_NAME_cell_tag)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 不受区域参数控制的缺陷类型:区域参数未配置/未开启时,仍按"检出即 NG"上报
|
|
|
|
|
|
|
|
// ZJ_PianYi/ZJ_QueShi/CGMo_QueShi:传统算法检出
|
|
|
|
|
|
|
|
// TBBQ(铜箔标签):标签检测(或AI分类)给出,本身已按 BQ_Detect 开关/检出结果判定,不再受区域参数控制
|
|
|
|
|
|
|
|
if (!Judge_Status && (config_qx_type == CONFIG_QX_NAME_cell_ZJ_PianYi ||
|
|
|
|
|
|
|
|
config_qx_type == CONFIG_QX_NAME_cell_ZJ_QueShi ||
|
|
|
|
|
|
|
|
config_qx_type == CONFIG_QX_NAME_cell_CGMo_QueShi ||
|
|
|
|
|
|
|
|
config_qx_type == CONFIG_QX_NAME_cell_TBBQ))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bNG_Status = true;
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_3, "qx info", " %s: region param not used -> report NG by base judge", qx_name.c_str());
|
|
|
|
Judge_Status = true;
|
|
|
|
Judge_Status = true;
|
|
|
|
|
|
|
|
bNG_Status = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string resultType = "OK";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!Judge_Status)
|
|
|
|
if (!Judge_Status)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QX_info->result = QX_RESULT_TYPE_NoJduge;
|
|
|
|
QX_info->result = QX_RESULT_TYPE_NoJduge;
|
|
|
|
@ -510,13 +564,29 @@ int ImageResultJudge::ResultJudge(std::shared_ptr<ImageAllResult> pImageResult)
|
|
|
|
// CheckUtil::printROI(CutRoi, "CutRoi");
|
|
|
|
// CheckUtil::printROI(CutRoi, "CutRoi");
|
|
|
|
cv::Size sz = cv::Size(QX_SAMLLIMG_WIDTH, QX_SAMLLIMG_HEIGHT);
|
|
|
|
cv::Size sz = cv::Size(QX_SAMLLIMG_WIDTH, QX_SAMLLIMG_HEIGHT);
|
|
|
|
|
|
|
|
|
|
|
|
if (pImageResult->detImg.channels() == 1)
|
|
|
|
// 缺陷小图直接取自原图裁剪区(保持原图通道 -> 真实彩色);按仿射矩阵从原图取回,
|
|
|
|
{
|
|
|
|
// ReJson/异常时退回检测图
|
|
|
|
cv::cvtColor(pImageResult->detImg(CutRoi), tem.srcImg, cv::COLOR_GRAY2BGR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tem.srcImg = pImageResult->detImg(CutRoi).clone();
|
|
|
|
const cv::Mat &srcImg = pImageResult->result->in_shareImage->img;
|
|
|
|
|
|
|
|
bool bGot = false;
|
|
|
|
|
|
|
|
if (pImageResult->result->in_shareImage->Det_Mode != DET_MODE_ReJson)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bGot = WarpSrcCutImg(srcImg, pDetResult->detToSrcMat, CutRoi, tem.srcImg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bGot)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int nOffsetX = (pImageResult->result->in_shareImage->Det_Mode != DET_MODE_ReJson) ? pDetResult->CutRoi.x : 0;
|
|
|
|
|
|
|
|
int nOffsetY = (pImageResult->result->in_shareImage->Det_Mode != DET_MODE_ReJson) ? pDetResult->CutRoi.y : 0;
|
|
|
|
|
|
|
|
cv::Rect srcCanvasRoi(CutRoi.x + nOffsetX, CutRoi.y + nOffsetY, CutRoi.width, CutRoi.height);
|
|
|
|
|
|
|
|
if (!srcImg.empty() && CheckUtil::RoiInImg(srcCanvasRoi, srcImg))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tem.srcImg = srcImg(srcCanvasRoi).clone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tem.srcImg = pImageResult->detImg(CutRoi).clone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cv::resize(tem.srcImg, tem.resizeImg, sz);
|
|
|
|
cv::resize(tem.srcImg, tem.resizeImg, sz);
|
|
|
|
|
|
|
|
|
|
|
|
@ -528,9 +598,13 @@ int ImageResultJudge::ResultJudge(std::shared_ptr<ImageAllResult> pImageResult)
|
|
|
|
tem.max_v = maxValue;
|
|
|
|
tem.max_v = maxValue;
|
|
|
|
tem.strTypeName = QX_Result_Names[nqx_type];
|
|
|
|
tem.strTypeName = QX_Result_Names[nqx_type];
|
|
|
|
tem.qx_Code = QX_Result_Code[nqx_type];
|
|
|
|
tem.qx_Code = QX_Result_Code[nqx_type];
|
|
|
|
tem.srcImgroi = roi;
|
|
|
|
tem.qx_level = QX_info->qx_level;
|
|
|
|
tem.srcImgroi.x += pDetResult->CutRoi.x;
|
|
|
|
// 缺陷 roi 映射回原图(按仿射矩阵映射, 否则按 CutRoi 平移)
|
|
|
|
tem.srcImgroi.y += pDetResult->CutRoi.y;
|
|
|
|
{
|
|
|
|
|
|
|
|
const cv::Mat &srcSizeImg = pImageResult->result->in_shareImage->img;
|
|
|
|
|
|
|
|
tem.srcImgroi = DetRoiToSrcRoi(pDetResult->detToSrcMat, roi, pDetResult->CutRoi,
|
|
|
|
|
|
|
|
srcSizeImg.empty() ? pImageResult->detImg.size() : srcSizeImg.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
tem.len = flen;
|
|
|
|
tem.len = flen;
|
|
|
|
tem.breadth = fbreadth;
|
|
|
|
tem.breadth = fbreadth;
|
|
|
|
tem.qx_type = 0;
|
|
|
|
tem.qx_type = 0;
|
|
|
|
@ -566,9 +640,7 @@ int ImageResultJudge::ResultJudge(std::shared_ptr<ImageAllResult> pImageResult)
|
|
|
|
|
|
|
|
|
|
|
|
GetAIDetImg(pImageResult, pCenter, tem.AI_in_Img, tem.AI_out_img);
|
|
|
|
GetAIDetImg(pImageResult, pCenter, tem.AI_in_Img, tem.AI_out_img);
|
|
|
|
m_CheckResult_shareP->qxImageResult.push_back(tem);
|
|
|
|
m_CheckResult_shareP->qxImageResult.push_back(tem);
|
|
|
|
pQxLog->bPrintStr = true;
|
|
|
|
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, " result ", " ---name: %s ---code: %s ---srcImgroi.x: %d ---srcImgroi.y: %d\n", tem.strTypeName.c_str(), tem.qx_Code.c_str(), tem.srcImgroi.x, tem.srcImgroi.y);
|
|
|
|
pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, " result ", " ---name: %s ---code: %s ---srcImgroi.x: %d ---srcImgroi.y: %d\n", tem.strTypeName.c_str(), tem.qx_Code.c_str(), tem.srcImgroi.x, tem.srcImgroi.y);
|
|
|
|
pQxLog->bPrintStr = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -629,13 +701,29 @@ int ImageResultJudge::ResultJudge(std::shared_ptr<ImageAllResult> pImageResult)
|
|
|
|
// CheckUtil::printROI(CutRoi, "CutRoi");
|
|
|
|
// CheckUtil::printROI(CutRoi, "CutRoi");
|
|
|
|
cv::Size sz = cv::Size(QX_SAMLLIMG_WIDTH, QX_SAMLLIMG_HEIGHT);
|
|
|
|
cv::Size sz = cv::Size(QX_SAMLLIMG_WIDTH, QX_SAMLLIMG_HEIGHT);
|
|
|
|
|
|
|
|
|
|
|
|
if (pImageResult->detImg.channels() == 1)
|
|
|
|
// 缺陷小图直接取自原图裁剪区(保持原图通道 -> 真实彩色);按仿射矩阵从原图取回,
|
|
|
|
{
|
|
|
|
// ReJson/异常时退回检测图
|
|
|
|
cv::cvtColor(pImageResult->detImg(CutRoi), tem.srcImg, cv::COLOR_GRAY2BGR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tem.srcImg = pImageResult->detImg(CutRoi).clone();
|
|
|
|
const cv::Mat &srcImg = pImageResult->result->in_shareImage->img;
|
|
|
|
|
|
|
|
bool bGot = false;
|
|
|
|
|
|
|
|
if (pImageResult->result->in_shareImage->Det_Mode != DET_MODE_ReJson)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bGot = WarpSrcCutImg(srcImg, pDetResult->detToSrcMat, CutRoi, tem.srcImg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bGot)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int nOffsetX = (pImageResult->result->in_shareImage->Det_Mode != DET_MODE_ReJson) ? pDetResult->CutRoi.x : 0;
|
|
|
|
|
|
|
|
int nOffsetY = (pImageResult->result->in_shareImage->Det_Mode != DET_MODE_ReJson) ? pDetResult->CutRoi.y : 0;
|
|
|
|
|
|
|
|
cv::Rect srcCanvasRoi(CutRoi.x + nOffsetX, CutRoi.y + nOffsetY, CutRoi.width, CutRoi.height);
|
|
|
|
|
|
|
|
if (!srcImg.empty() && CheckUtil::RoiInImg(srcCanvasRoi, srcImg))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tem.srcImg = srcImg(srcCanvasRoi).clone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tem.srcImg = pImageResult->detImg(CutRoi).clone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cv::resize(tem.srcImg, tem.resizeImg, sz);
|
|
|
|
cv::resize(tem.srcImg, tem.resizeImg, sz);
|
|
|
|
|
|
|
|
|
|
|
|
@ -647,9 +735,13 @@ int ImageResultJudge::ResultJudge(std::shared_ptr<ImageAllResult> pImageResult)
|
|
|
|
tem.max_v = maxValue;
|
|
|
|
tem.max_v = maxValue;
|
|
|
|
tem.strTypeName = QX_Result_Names[nqx_type];
|
|
|
|
tem.strTypeName = QX_Result_Names[nqx_type];
|
|
|
|
tem.qx_Code = QX_Result_Code[nqx_type];
|
|
|
|
tem.qx_Code = QX_Result_Code[nqx_type];
|
|
|
|
tem.srcImgroi = roi;
|
|
|
|
tem.qx_level = QX_info->qx_level;
|
|
|
|
tem.srcImgroi.x += pDetResult->CutRoi.x;
|
|
|
|
// 缺陷 roi 映射回原图(按仿射矩阵映射, 否则按 CutRoi 平移)
|
|
|
|
tem.srcImgroi.y += pDetResult->CutRoi.y;
|
|
|
|
{
|
|
|
|
|
|
|
|
const cv::Mat &srcSizeImg = pImageResult->result->in_shareImage->img;
|
|
|
|
|
|
|
|
tem.srcImgroi = DetRoiToSrcRoi(pDetResult->detToSrcMat, roi, pDetResult->CutRoi,
|
|
|
|
|
|
|
|
srcSizeImg.empty() ? pImageResult->detImg.size() : srcSizeImg.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
tem.len = flen;
|
|
|
|
tem.len = flen;
|
|
|
|
tem.breadth = fbreadth;
|
|
|
|
tem.breadth = fbreadth;
|
|
|
|
tem.qx_type = 0;
|
|
|
|
tem.qx_type = 0;
|
|
|
|
@ -788,32 +880,9 @@ int ImageResultJudge::DrawResult(std::shared_ptr<ImageAllResult> pImageResult)
|
|
|
|
draw_str->txtP = cv::Point(draw_qx->cp.x + r, draw_qx->cp.y - r);
|
|
|
|
draw_str->txtP = cv::Point(draw_qx->cp.x + r, draw_qx->cp.y - r);
|
|
|
|
draw_str->txtsize = 0.5;
|
|
|
|
draw_str->txtsize = 0.5;
|
|
|
|
draw_str->txtbackgroundk = txtbackgroundk;
|
|
|
|
draw_str->txtbackgroundk = txtbackgroundk;
|
|
|
|
cv::Rect srcroi = pqx->srcImgroi;
|
|
|
|
|
|
|
|
cv::Point srccp = cv::Point(srcroi.x + srcroi.width * .5, srcroi.y + srcroi.height * 0.5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char buffer[128];
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string text = std::to_string(pqx->idx) + ":" + pqx->strTypeName;
|
|
|
|
// 只绘制 id:缺陷code (缺陷名可能中文乱码, 用code替代)
|
|
|
|
draw_str->strlist.push_back(text);
|
|
|
|
std::string text = std::to_string(pqx->idx) + ":" + pqx->qx_Code;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sprintf(buffer, " center:%d %d", srccp.x, srccp.y);
|
|
|
|
|
|
|
|
std::string text = buffer;
|
|
|
|
|
|
|
|
draw_str->strlist.push_back(text);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sprintf(buffer, " len %0.2f A: %0.2f ", pqx->len, pqx->area);
|
|
|
|
|
|
|
|
std::string text = buffer;
|
|
|
|
|
|
|
|
draw_str->strlist.push_back(text);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sprintf(buffer, " breadth %0.2f A: %0.2f ", pqx->breadth, pqx->area);
|
|
|
|
|
|
|
|
std::string text = buffer;
|
|
|
|
|
|
|
|
draw_str->strlist.push_back(text);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sprintf(buffer, " E:%0.2f hj %0.2f", pqx->energy, pqx->hj);
|
|
|
|
|
|
|
|
std::string text = buffer;
|
|
|
|
|
|
|
|
draw_str->strlist.push_back(text);
|
|
|
|
draw_str->strlist.push_back(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendTask(draw_str);
|
|
|
|
sendTask(draw_str);
|
|
|
|
@ -1028,75 +1097,13 @@ int ImageResultJudge::addInDrawBlob(int errortype, int blobidx, QX_ERROR_INFO_ *
|
|
|
|
int ImageResultJudge::ConfigTypeToResultType(int nconfigType)
|
|
|
|
int ImageResultJudge::ConfigTypeToResultType(int nconfigType)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
bool bdesc = false;
|
|
|
|
// 缺陷类型(CONFIG_QX_NAME_)与结果列表(QX_Result_Names/QX_Result_Code)按配置顺序一一对应,直接按下标映射
|
|
|
|
int resultError_type = ERROR_TYPE_OK;
|
|
|
|
if (nconfigType >= 0 && nconfigType < CONFIG_QX_NAME_count &&
|
|
|
|
if(nconfigType < CONFIG_QX_NAME_Names.size())
|
|
|
|
nconfigType < (int)QX_Result_Names.size())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string cqn = CONFIG_QX_NAME_Names[nconfigType];
|
|
|
|
return nconfigType;
|
|
|
|
for(int i = 0; i < m_FlawCodeList.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(int j = 0; j < m_FlawCodeList.at(i).config_flaw_name.size(); j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(cqn == m_FlawCodeList.at(i).config_flaw_name[j])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
resultError_type = i;
|
|
|
|
|
|
|
|
bdesc = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果描述没有配置,用默认值
|
|
|
|
|
|
|
|
if(!bdesc)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (nconfigType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_aotudian:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_aotudian;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_other:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_other;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_line:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_line;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_zangwu:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_zangwu;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_edge:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_edge;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_ymhs:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_ymhs;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_dianzhuang:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_dianzhuang;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_posun:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_posun;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_xianwei:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_xianwei;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_shuizi:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_shuizi;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_danban:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_danban;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_fuchen:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_fuchen;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFIG_QX_NAME_cell_tag:
|
|
|
|
|
|
|
|
resultError_type = ERROR_TYPE_tag;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_TYPE_OK;
|
|
|
|
return resultError_type;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ImageResultJudge::sendTask(std::shared_ptr<DrawInfo> task)
|
|
|
|
int ImageResultJudge::sendTask(std::shared_ptr<DrawInfo> task)
|
|
|
|
@ -1143,7 +1150,7 @@ int ImageResultJudge::DrawResultTask(std::shared_ptr<ImageResultJudge::DrawInfo>
|
|
|
|
|
|
|
|
|
|
|
|
if (task->type == Draw_circle)
|
|
|
|
if (task->type == Draw_circle)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cv::circle(task->drawImg, task->cp, task->dr, task->color);
|
|
|
|
cv::circle(task->drawImg, task->cp, task->dr, CheckUtil::GetDrawColor(task->drawImg, task->color));
|
|
|
|
if (task->txtbackgroundk)
|
|
|
|
if (task->txtbackgroundk)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
task->txtbackgroundk->txtDrawRoi.push_back(task->roi);
|
|
|
|
task->txtbackgroundk->txtDrawRoi.push_back(task->roi);
|
|
|
|
@ -1151,7 +1158,7 @@ int ImageResultJudge::DrawResultTask(std::shared_ptr<ImageResultJudge::DrawInfo>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (task->type == Draw_rect)
|
|
|
|
if (task->type == Draw_rect)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cv::rectangle(task->drawImg, task->roi, task->color);
|
|
|
|
cv::rectangle(task->drawImg, task->roi, CheckUtil::GetDrawColor(task->drawImg, task->color));
|
|
|
|
if (task->txtbackgroundk)
|
|
|
|
if (task->txtbackgroundk)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
task->txtbackgroundk->txtDrawRoi.push_back(task->roi);
|
|
|
|
task->txtbackgroundk->txtDrawRoi.push_back(task->roi);
|
|
|
|
@ -1215,7 +1222,7 @@ int ImageResultJudge::DrawResultTask(std::shared_ptr<ImageResultJudge::DrawInfo>
|
|
|
|
|
|
|
|
|
|
|
|
// 画文字
|
|
|
|
// 画文字
|
|
|
|
cv::putText(task->drawImg, txt, cv::Point(r.x, r.y + height),
|
|
|
|
cv::putText(task->drawImg, txt, cv::Point(r.x, r.y + height),
|
|
|
|
fontFace, fontScale, task->color, thickness);
|
|
|
|
fontFace, fontScale, CheckUtil::GetDrawColor(task->drawImg, task->color), thickness);
|
|
|
|
height += lineHeight; // 下一行
|
|
|
|
height += lineHeight; // 下一行
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// cv::rectangle(task->drawImg, rtxt, cv::Scalar(255, 0, 0));
|
|
|
|
// cv::rectangle(task->drawImg, rtxt, cv::Scalar(255, 0, 0));
|
|
|
|
@ -1223,7 +1230,7 @@ int ImageResultJudge::DrawResultTask(std::shared_ptr<ImageResultJudge::DrawInfo>
|
|
|
|
cv::Point p(r.x, r.y);
|
|
|
|
cv::Point p(r.x, r.y);
|
|
|
|
if (task->cp.x - r.x > 30 || task->cp.y - r.y > 30)
|
|
|
|
if (task->cp.x - r.x > 30 || task->cp.y - r.y > 30)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cv::line(task->drawImg, p, task->cp, cv::Scalar(80, 0, 200));
|
|
|
|
cv::line(task->drawImg, p, task->cp, CheckUtil::GetDrawColor(task->drawImg, cv::Scalar(80, 0, 200)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// cv::circle(task->drawImg, task->cp, 3, task->color);
|
|
|
|
// cv::circle(task->drawImg, task->cp, 3, task->color);
|
|
|
|
|