From ac8edf474bbcd6ded5f136a57c0346e49bc15451 Mon Sep 17 00:00:00 2001 From: zqm Date: Fri, 9 Jan 2026 17:22:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E5=85=B3=E9=97=AD=E5=90=8E=E9=85=8D=E7=BD=AE=E6=9C=AA?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=92=8C=E6=B8=A9=E5=BA=A6=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E4=BF=AE=E6=AD=A3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Toprie/Toprie/Camera.cs | 14 ++++++- .../Toprie/Toprie/DeviceManager.cs | 38 +++++++++++++++---- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs index cf00e52..9ea705e 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs @@ -183,7 +183,15 @@ namespace JoyD.Windows.CS.Toprie public DetectionZone CurrentDetectionZone { get { return _detectionZone; } - set { _detectionZone = value; } + set + { + _detectionZone = value; + // 同时更新DeviceManager的检测区配置 + if (_deviceManager != null) + { + _deviceManager.DetectionZone = value; + } + } } /// @@ -3305,6 +3313,10 @@ namespace JoyD.Windows.CS.Toprie this.CurrentDetectionZone = JoyD.Windows.CS.Setting.Form.CurrentDetectionZone; // 保存修改后的检测区配置到文件 SaveMenuConfig(); + + // 重新加载测温区和温差数据,应用新的配置 + LoadZoneConfig(); + LoadTemperatureDiffConfig(); } catch (Exception ex) { diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs b/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs index b23e708..13ef3bc 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs @@ -308,6 +308,9 @@ namespace JoyD.Windows.CS.Toprie // 加载的温差配置 private TemperatureDiffConfig _loadedTemperatureDiffConfig = new TemperatureDiffConfig(); + // 检测区配置 + private DetectionZone _detectionZone = new DetectionZone(); + // 温度数据处理相关 private volatile byte[] _lastTemperatureFrame; // 存储最后一帧温度数据 private Thread _temperatureProcessingThread; // 温度数据处理线程 @@ -496,6 +499,16 @@ namespace JoyD.Windows.CS.Toprie } } + /// + /// 检测区配置属性 + /// 用于设置温度计算时的检测区位置 + /// + public DetectionZone DetectionZone + { + get { return _detectionZone; } + set { _detectionZone = value; } + } + /// /// 加载所有配置文件 /// @@ -2284,10 +2297,16 @@ namespace JoyD.Windows.CS.Toprie float sumTemp = 0; int count = 0; + // 将相对坐标转换为绝对坐标(考虑检测区位置) + int absoluteX = _detectionZone.X + zone.X; + int absoluteY = _detectionZone.Y + zone.Y; + int absoluteWidth = zone.Width; + int absoluteHeight = zone.Height; + // 计算测温区内的温度统计数据 - for (int y = zone.Y; y < zone.Y + zone.Height && y < temperatureData.RealTemperatureMatrix.GetLength(0); y++) + for (int y = absoluteY; y < absoluteY + absoluteHeight && y < temperatureData.RealTemperatureMatrix.GetLength(0); y++) { - for (int x = zone.X; x < zone.X + zone.Width && x < temperatureData.RealTemperatureMatrix.GetLength(1); x++) + for (int x = absoluteX; x < absoluteX + absoluteWidth && x < temperatureData.RealTemperatureMatrix.GetLength(1); x++) { float temp = temperatureData.RealTemperatureMatrix[y, x]; if (temp < minTemp) @@ -2330,21 +2349,24 @@ namespace JoyD.Windows.CS.Toprie { try { - Point pixel = pixelTemp.Key; + Point relativePixel = pixelTemp.Key; double configTemp = pixelTemp.Value; + // 将相对坐标转换为绝对坐标(考虑检测区位置) + Point absolutePixel = new Point(_detectionZone.X + relativePixel.X, _detectionZone.Y + relativePixel.Y); + // 检查像素点是否在温度矩阵范围内 - if (pixel.Y >= 0 && pixel.Y < temperatureData.RealTemperatureMatrix.GetLength(0) && - pixel.X >= 0 && pixel.X < temperatureData.RealTemperatureMatrix.GetLength(1)) + if (absolutePixel.Y >= 0 && absolutePixel.Y < temperatureData.RealTemperatureMatrix.GetLength(0) && + absolutePixel.X >= 0 && absolutePixel.X < temperatureData.RealTemperatureMatrix.GetLength(1)) { // 获取当前温度 - float currentTemp = temperatureData.RealTemperatureMatrix[pixel.Y, pixel.X]; + float currentTemp = temperatureData.RealTemperatureMatrix[absolutePixel.Y, absolutePixel.X]; // 计算温差 float diff = currentTemp - (float)configTemp; - // 添加到温度数据对象中 - temperatureData.TemperatureDiffs[pixel] = diff; + // 添加到温度数据对象中,使用相对坐标作为键 + temperatureData.TemperatureDiffs[relativePixel] = diff; } } catch (Exception ex)