workpieceHolePositioning version 1.4.7 :

修正问题:在进行异物检测时,计算ZSliceTh时。添加Z计算的保护,防止异常值混入
This commit is contained in:
jerryzeng 2026-04-25 09:36:41 +08:00
parent 0e2fe3e8e1
commit 36798e8754
2 changed files with 23 additions and 9 deletions

View File

@ -17,7 +17,8 @@
//version 1.4.4 : 对1.4.3一个小的修正, 不影响结果
//version 1.4.5 : 添加异物检测通过errCode输出“有异物”和“无产品”结果
//version 1.4.6 : 修正问题4个孔组成工作时需要4个孔的高度基本一致。
std::string m_strVersion = "1.4.6";
//version 1.4.7 : 修正问题在进行异物检测时计算ZSliceTh时。添加Z计算的保护防止异常值混入
std::string m_strVersion = "1.4.7";
const char* wd_workpieceHolePositioningVersion(void)
{
return m_strVersion.c_str();
@ -139,7 +140,7 @@ int angleConditionDistanceSearch(
return result;
}
double _getMeanZ(std::vector<std::vector<double>>& quantiValue, SVzNL3DPoint seed, SVzNLRect& roi2D, double rectR)
double _getMeanZ(std::vector<std::vector<double>>& quantiValue, SVzNL3DPoint seed, SVzNLRect& roi2D, double rectR, double zRange)
{
int cols = (int)quantiValue.size();
int rows = (int)quantiValue[0].size();
@ -149,6 +150,7 @@ double _getMeanZ(std::vector<std::vector<double>>& quantiValue, SVzNL3DPoint see
int win = (int)rectR;
int hist = 0;
double zSum = 0;
double refZ = seed.z;
for (int i = -win; i <= win; i++)
{
for (int j = -win; j <= win; j++)
@ -159,8 +161,12 @@ double _getMeanZ(std::vector<std::vector<double>>& quantiValue, SVzNL3DPoint see
{
if (quantiValue[qx][qy] > 1e-4)
{
zSum += quantiValue[qx][qy];
hist++;
double zDiff = abs(quantiValue[qx][qy] - refZ);
if (zDiff < zRange)
{
zSum += quantiValue[qx][qy];
hist++;
}
}
}
}
@ -864,10 +870,18 @@ void wd_workpieceHolePositioning(
SVzNL3DPoint center_p1p3 = { (p1.center.x + p3.center.x) / 2,(p1.center.y + p3.center.y) / 2, (p1.center.z + p3.center.z) / 2 };
SVzNL3DPoint center_p2p3 = { (p2.center.x + p3.center.x) / 2,(p2.center.y + p3.center.y) / 2, (p2.center.z + p3.center.z) / 2 };
double rectR = 5.0;
double z1 = _getMeanZ(quantiValue, center_p0p1, roi2D, rectR);
double z2 = _getMeanZ(quantiValue, center_p0p2, roi2D, rectR);
double z3 = _getMeanZ(quantiValue, center_p1p3, roi2D, rectR);
double z4 = _getMeanZ(quantiValue, center_p2p3, roi2D, rectR);
double z1 = _getMeanZ(quantiValue, center_p0p1, roi2D, rectR, workpiecePara.H/2);
if (z1 < 1e-4)
z1 = center_p0p1.z;
double z2 = _getMeanZ(quantiValue, center_p0p2, roi2D, rectR, workpiecePara.H / 2);
if (z2 < 1e-4)
z2 = center_p0p2.z;
double z3 = _getMeanZ(quantiValue, center_p1p3, roi2D, rectR, workpiecePara.H / 2);
if (z3 < 1e-4)
z3 = center_p1p3.z;
double z4 = _getMeanZ(quantiValue, center_p2p3, roi2D, rectR, workpiecePara.H / 2);
if (z4 < 1e-4)
z4 = center_p2p3.z;
p0.center.z = (z1 + z2) / 2;
p1.center.z = (z1 + z3) / 2;

View File

@ -566,7 +566,7 @@ void TuoPuFa_holePosition_test(void)
};
SVzNLRange fileIdx[TPF_TEST_GROUP] = {
{6,6}, {1, 16}, {9,9}
{6,6}, {1, 16}, {13,13}
};
const char* ver = wd_workpieceHolePositioningVersion();