#ifndef _ImgMmPatch_HPP_ #define _ImgMmPatch_HPP_ // ============================================================================ // 【临时补丁】产品长度方向(y) 像素 -> 物理毫米 的分段换算 // // 背景:产品沿长度方向运动/扫描时速率不恒定(尾端有拉伸),像素↔mm 不是单一 // 比例,实测标定出 5 段,每段斜率不同。 // // 分段表(分段点 = 像素,**以产品顶边为 0 点**;斜率为 mm/px): // 0 ~ 10928 0.016869 // 10928 ~ 17002 0.016463 (6074px ↔ 100mm) // 17002 ~ 23167 0.016220 (6165px ↔ 100mm) // 23167 ~ 29549 0.015669 (6382px ↔ 100mm) // >= 29549 0.014337 // 分段点处前后两段取值相同,函数连续,不会在分段点跳变。 // // 共用方(必须共用同一张表,否则"产品高度"和"缺陷坐标"会各用一把尺子): // 1) 缺陷 y 物理坐标:ImageResultJudge::BuildDefectImage() // 2) 产品物理高度 :ImgCheckAnalysisy::CalProductSize() // // 注:正式方案建议把这张分段表放进配置(json),由标定数据下发;这里先硬编码。 // ============================================================================ inline float PixelYToMm(float fYPixel) { // 各段末端的累计物理长度(mm) const float d1 = 10928 * 0.016869; const float d2 = 6074 * 0.016463; const float d3 = 6165 * 0.016220; const float d4 = 6382 * 0.015669; if (fYPixel < 10928.0f) { return fYPixel * 0.016869; } if (fYPixel < 17002.0f) { return (fYPixel - 10928.0f) * 0.016463 + d1; } if (fYPixel < 23167.0f) { return (fYPixel - 10928.0f - 6074.0f) * 0.016220 + d1 + d2; } if (fYPixel < 29549.0f) { return (fYPixel - 10928.0f - 6074.0f - 6165.0f) * 0.015669 + d1 + d2 + d3; } return (fYPixel - 10928.0f - 6074.0f - 6165.0f - 6382.0f) * 0.014337 + d1 + d2 + d3 + d4; } #endif