From bcffd7c2475c2c0ec019d34e75e224302114dfbb Mon Sep 17 00:00:00 2001 From: rain Date: Tue, 5 May 2026 11:02:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 头罩视野slove/头罩视野/Services/GetArea.cs | 41 ++++--------------- 头罩视野slove/头罩视野/Views/PageTest.xaml.cs | 20 ++++++--- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/头罩视野slove/头罩视野/Services/GetArea.cs b/头罩视野slove/头罩视野/Services/GetArea.cs index a9bd804..c609f0b 100644 --- a/头罩视野slove/头罩视野/Services/GetArea.cs +++ b/头罩视野slove/头罩视野/Services/GetArea.cs @@ -11,36 +11,15 @@ namespace 头罩视野.Services // 设备固定参数 - private static double R = 330; // 半球半径 - private static double angleStep = 10; // 每格角度 + public static double R = 330; // 半球半径 + public static double angleStep = 10; // 每格角度 // 定义参数(和你代码里一致) - private const int totalLights = 81; - //public const double standardArea = 140; + public const int totalLights = 81; - /// 有效亮度阈值:区分有效视野和噪声/遮挡的门槛设备标定经验值,≥12判定为有效视野 - public const int threshold = 12; + ///// 双目标准标定总面积:无面罩空标准头模的双目总实测面积国标总视野保存率计算的基准值,单位:cm² + //public const double StandardTotal = 10360; - /// 异常值差值阈值:过滤孤立尖峰噪声当前点与前后点差值均>30时,判定为异常值并插值修正 - public const int OutlierDiffThreshold = 30; - - /// 灯条通道总数:360°圆周采样点数量对应每点5°(360° ÷ 72 = 5°/点),符合国标GB2890-2022要求 - public const int lightNum = 72; - - /// 设备最大检测半径:理论上的最大视野半径单位:mm,用来计算理论圆面积 这个是我们自己的设备值 - public const int maxRadius_mm = 330; - - /// 单眼标准标定面积:无面罩空标准头模的单眼实测面积 国标视野保存率计算的基准值,单位:cm² - public const double standardArea = 5180; - - /// 双目标准标定总面积:无面罩空标准头模的双目总实测面积国标总视野保存率计算的基准值,单位:cm² - public const double StandardTotal = 10360; - - // 补充:用半径计算的单眼理论圆面积(供参考) 公式:π × 半径²,单位:cm² - public static readonly double standardAreaOus = Math.PI * maxRadius_mm * maxRadius_mm / 100; - - //双目重叠标准 - public static double StandardBinocular = 4150; //空白视野面积计算 public static readonly double _standardTotalArea = 2 * Math.PI * 330 * 330; @@ -51,9 +30,8 @@ namespace 头罩视野.Services return _standardTotalArea - binocularTotalArea; } - //下方视野 - // 固定参数:每一格灯代表 10 度(你的设备标准) - + //下方视野 下方视野角度 = 人眼到「最低亮灯条」的夹角 + /// /// 计算 下方视野角度(单位:度 °) /// @@ -71,7 +49,6 @@ namespace 头罩视野.Services angles.Add(angle); } } - // 没有亮灯返回 0 if (angles.Count == 0) return 0; @@ -85,7 +62,7 @@ namespace 头罩视野.Services { // 1. 总视野保存率 - double ratioTotal = binocularRate / StandardTotal; + double ratioTotal = binocularRate / _standardTotalArea; double gammaTotal = GetVisionGamma(ratioTotal); double totalRate = gammaTotal * ratioTotal * 100; return (totalRate); @@ -124,7 +101,7 @@ namespace 头罩视野.Services - // 传入:72个灯的亮灭数据(0=灭,1=亮) + // 传入:81个灯的亮灭数据(0=灭,1=亮) // 返回:椭圆面积 public static double CalculateEllipseArea(int[] lightData, List<(int m, int n)> lightPositions) { diff --git a/头罩视野slove/头罩视野/Views/PageTest.xaml.cs b/头罩视野slove/头罩视野/Views/PageTest.xaml.cs index bbfc654..a36de0f 100644 --- a/头罩视野slove/头罩视野/Views/PageTest.xaml.cs +++ b/头罩视野slove/头罩视野/Views/PageTest.xaml.cs @@ -191,6 +191,11 @@ namespace 头罩视野.Views // 1. 读取输入框 double stepAngle = double.Parse(fbspeed.Text); // 分辨角度 例:10 + if (double.TryParse(fbspeed.Text, out double step)) + { + // 直接赋值给计算页面的静态变量 + GetArea.angleStep = step; + } //double speed = double.Parse(zdangle.Text); // 转动速度 int[] lightData = DataList.Cast().ToArray(); // 1. 把DataList(List)转成方法需要的int[] // 1. 定义总和变量,初始为0 @@ -205,10 +210,15 @@ namespace 头罩视野.Views //2. 调用CalculateEllipseArea,传入两个参数 double area = GetArea.CalculateEllipseArea(lightData, _lightPositions); totalArea += area; - //double bottomViewAngle = GetArea.CalculateBottomViewAngle(lightData, _lightPositions); - //totalBottomViewAngle += bottomViewAngle; + double bottomViewAngle = GetArea.CalculateBottomViewAngle(lightData, _lightPositions); + totalBottomViewAngle += bottomViewAngle; } - UpdateVisionResults(totalArea, totalBottomViewAngle); + isFinished = _modbusMaster.ReadCoils(1, 102, 1)[0]; + if (isFinished) + { + Button_Click_Stop(null, null); + UpdateVisionResults(totalArea, totalBottomViewAngle); + } } //页面渲染值 @@ -236,8 +246,8 @@ namespace 头罩视野.Views } //// 4. 计算下方视野面积 - //int botViAnInt = (int)Math.Round(BotViAn); - //xfsyarea.Text = botViAnInt.ToString("0.0"); // 下方视野 + int botViAnInt = (int)Math.Round(BotViAn); + xfsyarea.Text = botViAnInt.ToString("0.0"); // 下方视野 // 5. 计算视野保存率(双目) if (double.TryParse(smsyarea.Text, out double totalAreaForRate))