|
|
|
|
@ -891,6 +891,7 @@ int ImgCheckAnalysisy::CheckRun()
|
|
|
|
|
4、计算值与标准值(x_standard/y_standard)做差取平均,平均差超过 offset(x_offset) → 偏移 */
|
|
|
|
|
{
|
|
|
|
|
Function_Support_Det &supportDet = m_pbaseCheckFunction->supportDet;
|
|
|
|
|
m_SupportDrawInfo.Reset(); // 清空本帧绘制信息(未开启/计算无效时不绘制)
|
|
|
|
|
if (supportDet.bDetSupport)
|
|
|
|
|
{
|
|
|
|
|
const cv::Mat &bigmask = m_pEdge_Align_Result->bigmask;
|
|
|
|
|
@ -1008,6 +1009,15 @@ int ImgCheckAnalysisy::CheckRun()
|
|
|
|
|
float fDiff = fabs(fDist - fStandard);
|
|
|
|
|
fSumDiff += fDiff;
|
|
|
|
|
nDiffNum++;
|
|
|
|
|
// 记录该方向绘制信息:|实测-标准|超限差(x_offset)则绘制为红色
|
|
|
|
|
{
|
|
|
|
|
Support_Draw_Info_::Edge_Draw_ edgeDraw;
|
|
|
|
|
edgeDraw.strEdge = strEdge;
|
|
|
|
|
edgeDraw.fDist = fDist;
|
|
|
|
|
edgeDraw.fStandard = fStandard;
|
|
|
|
|
edgeDraw.bExceed = (fDiff > supportDet.x_offset);
|
|
|
|
|
m_SupportDrawInfo.edgeList.push_back(edgeDraw);
|
|
|
|
|
}
|
|
|
|
|
sprintf(strTmp, "%s(%.1f/%.1f) ", strEdge.c_str(), fDist, fStandard);
|
|
|
|
|
strSelect += strTmp;
|
|
|
|
|
sprintf(strTmp, "%.1f ", fDiff);
|
|
|
|
|
@ -1017,6 +1027,13 @@ int ImgCheckAnalysisy::CheckRun()
|
|
|
|
|
float fAvgDiff = (nDiffNum > 0) ? (fSumDiff / nDiffNum) : 0.0f;
|
|
|
|
|
bool bOffset = (nDiffNum > 0) && (fAvgDiff > supportDet.x_offset);
|
|
|
|
|
|
|
|
|
|
// 记录绘制信息(DrawResult_Step_1 用):支架中心十字 + 各方向距离
|
|
|
|
|
m_SupportDrawInfo.bValid = true;
|
|
|
|
|
m_SupportDrawInfo.bOffset = bOffset;
|
|
|
|
|
m_SupportDrawInfo.rpRect = rpRect;
|
|
|
|
|
m_SupportDrawInfo.rsRect = rsRect;
|
|
|
|
|
m_SupportDrawInfo.ptCenter = cv::Point2f(fCx, fCy);
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, "支架检测",
|
|
|
|
|
"rp [%d %d %d %d] rs [%d %d %d %d] scale (%.4f %.4f) center (%.1f %.1f) dL %.1f dR %.1f dT %.1f dB %.1f | select %s diff %s avgDiff %.1f limit %.1f ng %d",
|
|
|
|
|
rpRect.x, rpRect.y, rpRect.width, rpRect.height,
|
|
|
|
|
@ -2343,21 +2360,7 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
|
float fs_resize_y = m_pImageAllResult->resultImg.rows * 1.0f / m_pImageAllResult->detImg.rows;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 绘制m_inner_rroi(蓝色),原图坐标 -> 检测图(裁剪) -> 结果图
|
|
|
|
|
{
|
|
|
|
|
cv::Point2f vertices[4];
|
|
|
|
|
m_inner_rroi.points(vertices);
|
|
|
|
|
std::vector<cv::Point> draw_pts;
|
|
|
|
|
draw_pts.reserve(4);
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
cv::Point2f detPt = MatAffinePoint(m_matSrc2Det, vertices[i]);
|
|
|
|
|
draw_pts.emplace_back(cvRound(detPt.x * fs_resize_x),
|
|
|
|
|
cvRound(detPt.y * fs_resize_y));
|
|
|
|
|
}
|
|
|
|
|
cv::polylines(m_CheckResult_shareP->resultimg, draw_pts, true,
|
|
|
|
|
CheckUtil::GetDrawColor(m_CheckResult_shareP->resultimg, cv::Scalar(255, 0, 0)), 1);
|
|
|
|
|
}
|
|
|
|
|
// 注:不再绘制 inner 定位蓝色框(m_inner_rroi 为大轮廓裁剪子图局部坐标,直接映射会缺裁剪原点偏移)
|
|
|
|
|
|
|
|
|
|
if (m_pbaseCheckFunction && m_pbaseCheckFunction->markLine.region.size() > 1)
|
|
|
|
|
{
|
|
|
|
|
@ -2400,6 +2403,63 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 支架偏移检测绘制:支架中心十字(绿=正常/红=偏移NG)+ 支架到边缘的距离(绿=正常/红=超标准)
|
|
|
|
|
if (m_SupportDrawInfo.bValid && !m_CheckResult_shareP->resultimg.empty())
|
|
|
|
|
{
|
|
|
|
|
// 支架中心:原图坐标 -> 检测图(裁剪) -> 结果图
|
|
|
|
|
cv::Point2f detPt = MatAffinePoint(m_matSrc2Det, m_SupportDrawInfo.ptCenter);
|
|
|
|
|
cv::Point pCenter(cvRound(detPt.x * fs_resize_x), cvRound(detPt.y * fs_resize_y));
|
|
|
|
|
|
|
|
|
|
// 支架中心十字:NG 红色 / 正常绿色
|
|
|
|
|
cv::Scalar colorCross = m_SupportDrawInfo.bOffset ? cv::Scalar(0, 0, 255) : cv::Scalar(0, 255, 0);
|
|
|
|
|
colorCross = CheckUtil::GetDrawColor(m_CheckResult_shareP->resultimg, colorCross);
|
|
|
|
|
const int nCrossLen = 40; // 结果图上十字半长(px)
|
|
|
|
|
cv::line(m_CheckResult_shareP->resultimg, cv::Point(pCenter.x - nCrossLen, pCenter.y), cv::Point(pCenter.x + nCrossLen, pCenter.y), colorCross, 2);
|
|
|
|
|
cv::line(m_CheckResult_shareP->resultimg, cv::Point(pCenter.x, pCenter.y - nCrossLen), cv::Point(pCenter.x, pCenter.y + nCrossLen), colorCross, 2);
|
|
|
|
|
|
|
|
|
|
// 支架到边缘的距离:中心 -> 产品区域对应边缘连线 + 实测/标准(像素)文字
|
|
|
|
|
char strTxt[64];
|
|
|
|
|
for (size_t i = 0; i < m_SupportDrawInfo.edgeList.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
const Support_Draw_Info_::Edge_Draw_ &edgeDraw = m_SupportDrawInfo.edgeList[i];
|
|
|
|
|
cv::Point2f ptEdge = m_SupportDrawInfo.ptCenter;
|
|
|
|
|
if (edgeDraw.strEdge == "left")
|
|
|
|
|
{
|
|
|
|
|
ptEdge.x = (float)m_SupportDrawInfo.rpRect.x;
|
|
|
|
|
}
|
|
|
|
|
else if (edgeDraw.strEdge == "right")
|
|
|
|
|
{
|
|
|
|
|
ptEdge.x = (float)(m_SupportDrawInfo.rpRect.x + m_SupportDrawInfo.rpRect.width);
|
|
|
|
|
}
|
|
|
|
|
else if (edgeDraw.strEdge == "up")
|
|
|
|
|
{
|
|
|
|
|
ptEdge.y = (float)m_SupportDrawInfo.rpRect.y;
|
|
|
|
|
}
|
|
|
|
|
else if (edgeDraw.strEdge == "down")
|
|
|
|
|
{
|
|
|
|
|
ptEdge.y = (float)(m_SupportDrawInfo.rpRect.y + m_SupportDrawInfo.rpRect.height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::Point2f detEdge = MatAffinePoint(m_matSrc2Det, ptEdge);
|
|
|
|
|
cv::Point pEdge(cvRound(detEdge.x * fs_resize_x), cvRound(detEdge.y * fs_resize_y));
|
|
|
|
|
|
|
|
|
|
// 超标准红色 / 正常绿色
|
|
|
|
|
cv::Scalar colorEdge = edgeDraw.bExceed ? cv::Scalar(0, 0, 255) : cv::Scalar(0, 255, 0);
|
|
|
|
|
colorEdge = CheckUtil::GetDrawColor(m_CheckResult_shareP->resultimg, colorEdge);
|
|
|
|
|
cv::line(m_CheckResult_shareP->resultimg, pCenter, pEdge, colorEdge, 2);
|
|
|
|
|
|
|
|
|
|
// 距离文字:实测/标准(原图像素)
|
|
|
|
|
snprintf(strTxt, sizeof(strTxt), "%s %.0f/%.0f", edgeDraw.strEdge.c_str(), edgeDraw.fDist, edgeDraw.fStandard);
|
|
|
|
|
cv::putText(m_CheckResult_shareP->resultimg, strTxt,
|
|
|
|
|
cv::Point((pCenter.x + pEdge.x) / 2 + 6, (pCenter.y + pEdge.y) / 2 - 6),
|
|
|
|
|
cv::FONT_HERSHEY_SIMPLEX, 0.8, colorEdge, 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// cv::imwrite("sss.png", m_CheckResult_shareP->resultimg);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|