保存图片更新试试

This commit is contained in:
2025-04-02 14:41:26 +08:00
parent 409089e2ca
commit babc40d36a
6 changed files with 472 additions and 43 deletions

View File

@ -9,6 +9,7 @@ using AntdUI;
using static DH.Commons.Enums.EnumHelper;
using System.Text.Json.Serialization;
using DH.Commons.Enums;
using System.Drawing.Imaging;
namespace DH.Commons.Base
{
@ -104,20 +105,20 @@ namespace DH.Commons.Base
/// </summary>
public class DetectionResultDetail
{
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string LabelBGR { get; set; }//识别到对象的标签BGR
public int LabelNo { get; set; } // 识别到对象的标签索引
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string LabelName { get; set; }//识别到对象的标签名称
public double Score { get; set; }//识别目标结果的可能性、得分
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string LabelDisplay { get; set; }//识别到对象的 显示信息
@ -138,10 +139,10 @@ namespace DH.Commons.Base
public class MLResult
{
public bool IsSuccess = false;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string ResultMessage;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public Bitmap ResultMap;
public List<DetectionResultDetail> ResultDetails = new List<DetectionResultDetail>();
@ -165,8 +166,7 @@ namespace DH.Commons.Base
public bool IsGPU;
public int GPUId;
public float Score_thre;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public MLInit(string modelFile, bool isGPU, int gpuId, float score_thre)
@ -191,7 +191,25 @@ namespace DH.Commons.Base
}
public class DetectStationResult
{
public string Pid { get; set; }
public DateTime ImageTime { get; set; } = DateTime.Now;
private string id = "";
public string Id
{
get
{
if (string.IsNullOrWhiteSpace(id))
{
id = ImageTime.ToString("HHmmssfff");
}
return id;
}
set
{
id = value;
}
}
public string Pid { get; set; }
public string TempPid { get; set; }
@ -237,35 +255,24 @@ namespace DH.Commons.Base
/// 预处理阶段已经NG
/// </summary>
public bool IsPreTreatNG { get; set; } = false;
/// <summary>
/// 检测原图
/// </summary>
public Bitmap DetectionOriginImage { get; set; }
/// <summary>
/// 目标检测NG
/// </summary>
public bool IsObjectDetectNG { get; set; } = false;
public ImageFormat ImageFormat { get; set; } = ImageFormat.Jpeg;
public DateTime EndTime { get; set; }
public string ImageSaveDirectory { get; set; }
public int StationDetectElapsed { get; set; }
public static string NormalizeAndClean(string input)
{
public bool SaveOKOriginal = false;
public bool SaveNGOriginal = false;
public bool SaveOKDetect = false;
public bool SaveNGDetect = false;
if (input == null) return null;
// Step 1: 标准化字符编码为 Form C (规范组合)
string normalizedString = input.Normalize(NormalizationForm.FormC);
// Step 2: 移除所有空白字符,包括制表符和换行符
string withoutWhitespace = Regex.Replace(normalizedString, @"\s+", "");
// Step 3: 移除控制字符 (Unicode 控制字符,范围 \u0000 - \u001F 和 \u007F)
string withoutControlChars = Regex.Replace(withoutWhitespace, @"[\u0000-\u001F\u007F]+", "");
// Step 4: 移除特殊的不可见字符(如零宽度空格等)
string cleanedString = Regex.Replace(withoutControlChars, @"[\u200B\u200C\u200D\uFEFF]+", "");
return cleanedString;
}
}
public class RelatedCamera : NotifyProperty
@ -502,7 +509,7 @@ namespace DH.Commons.Base
private AntList<SizeTreatParam> _sizeTreatParamList = new AntList<SizeTreatParam>();
private CustomizedPoint _showLocation = new CustomizedPoint();
private string _imageSaveDirectory;
private bool _saveOKOriginal = false;
private bool _saveNGOriginal = false;
private bool _saveOKDetect = false;
@ -620,7 +627,19 @@ namespace DH.Commons.Base
OnPropertyChanged(nameof(IsAddStation));
}
}
[Category("图片保存")]
[DisplayName("图片保存文件夹")]
[Description("图片保存文件夹")]
public virtual string ImageSaveDirectory
{
get => _imageSaveDirectory;
set
{
if (_imageSaveDirectory == value) return;
_imageSaveDirectory = value;
OnPropertyChanged(nameof(ImageSaveDirectory));
}
}
[Category("1.预处理(视觉算子)")]
[DisplayName("预处理-算法文件路径")]
public string HalconAlgorithemPath_Pre