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.

67 lines
2.2 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.

#ifndef _ImgMmPatch_HPP_
#define _ImgMmPatch_HPP_
// ============================================================================
// 【临时补丁】产品长度方向(y) 像素 -> 物理毫米 的分段换算
//
// 背景:产品沿长度方向运动/扫描时速率不恒定(尾端有拉伸),像素↔mm 不是单一
// 比例,实测标定出 5 段,每段斜率不同。
//
// 分段表(分段点 = 像素,**以产品顶边为 0 点**;斜率为 mm/px)见函数内
// yPx1..yPx5 / pmm1..pmm5,改标定只需改那一段(此处不重复写数值,避免两处不同步)。
// 分段点处前后两段取值相同,函数连续,不会在分段点跳变。
//
// 共用方(必须共用同一张表,否则"产品高度"和"缺陷坐标"会各用一把尺子):
// 1) 缺陷 y 物理坐标:ImageResultJudge::BuildDefectImage()
// 2) 产品物理高度 :ImgCheckAnalysisy::CalProductSize()
//
// 注:正式方案建议把这张分段表放进配置(json),由标定数据下发;这里先硬编码。
// ============================================================================
inline float PixelYToMm(float fYPixel)
{
// ================= 标定参数:改标定只需改这一段 =================
// 各段斜率(mm/px)
const float pmm1 = 0.016869;
const float pmm2 = 0.016463;
const float pmm3 = 0.016220;
const float pmm4 = 0.015669;
const float pmm5 = 0.014337;
// 各段起始像素(以产品顶边为 0 点)
const float yPx1 = 0.0f;
const float yPx2 = 10928.0f;
const float yPx3 = 17002.0f;
const float yPx4 = 23167.0f;
const float yPx5 = 29549.0f;
// 各段像素长度(px)
const float dPx1 = yPx2 - yPx1;
const float dPx2 = yPx3 - yPx2;
const float dPx3 = yPx4 - yPx3;
const float dPx4 = yPx5 - yPx4;
// 各段末端的累计物理长度(mm)
const float d1 = dPx1 * pmm1;
const float d2 = d1 + dPx2 * pmm2;
const float d3 = d2 + dPx3 * pmm3;
const float d4 = d3 + dPx4 * pmm4;
if (fYPixel < yPx2)
{
return fYPixel * pmm1;
}
if (fYPixel < yPx3)
{
return (fYPixel - yPx2) * pmm2 + d1;
}
if (fYPixel < yPx4)
{
return (fYPixel - yPx3) * pmm3 + d2;
}
if (fYPixel < yPx5)
{
return (fYPixel - yPx4) * pmm4 + d3;
}
return (fYPixel - yPx5) * pmm5 + d4;
}
#endif