修复设置窗口关闭后配置未应用和温度计算坐标修正问题

This commit is contained in:
zqm
2026-01-09 17:22:37 +08:00
parent c1efddde74
commit ac8edf474b
2 changed files with 43 additions and 9 deletions

View File

@@ -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;
}
}
}
/// <summary>
@@ -3305,6 +3313,10 @@ namespace JoyD.Windows.CS.Toprie
this.CurrentDetectionZone = JoyD.Windows.CS.Setting.Form.CurrentDetectionZone;
// 保存修改后的检测区配置到文件
SaveMenuConfig();
// 重新加载测温区和温差数据,应用新的配置
LoadZoneConfig();
LoadTemperatureDiffConfig();
}
catch (Exception ex)
{

View File

@@ -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
}
}
/// <summary>
/// 检测区配置属性
/// 用于设置温度计算时的检测区位置
/// </summary>
public DetectionZone DetectionZone
{
get { return _detectionZone; }
set { _detectionZone = value; }
}
/// <summary>
/// 加载所有配置文件
/// </summary>
@@ -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)