//using Check.Main.Common; //using System; //using System.Collections.Generic; //using System.ComponentModel;// 需要引入此命名空间以使用 INotifyPropertyChanged //using System.Linq; //using System.Runtime.CompilerServices; //using System.Runtime.Serialization; //using System.Text; //using System.Threading.Tasks; using Check.Main.Common; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Windows.Forms.Design; using System.Drawing.Design; namespace Check.Main.Infer { public enum CheckModelType { [Description("分类")] Classification, [Description("检测")] ObjectDetection, [Description("OBB")] ObbDetection, [Description("分割")] Segmentation, [Description("位姿")] PoseEstimation } public enum AlgorithmType { [Description("传统算法")] Tradition = 0, [Description("深度学习")] DeepLearning, } public enum DetectDevice { [Description("CPU")] CPU = 0, [Description("GPU")] GPU, //[Description("VPU")] //VPU, } [Serializable] // 确保可被XML序列化 public class ModelSettings : INotifyPropertyChanged, ICloneable//类ModelSettings继承或实现两个接口:①提供一个事件,用于在属性值更改时发出通知;②提供一个方法,用于创建对象的独立副本 { //1. 实现 INotifyPropertyChanged 接口 public event PropertyChangedEventHandler PropertyChanged; private int _id; private string _name = "New Model"; private string _path = ""; private DetectDevice _checkDevice=DetectDevice.CPU; private AlgorithmType _mAType = AlgorithmType.Tradition; private CheckModelType _mType = CheckModelType.ObjectDetection; private bool _isEnabled = true; // 新增 HALCON 和 YOLO 的参数。10.22 private double _halconScoreThreshold = 0.5; private float _yoloConfidenceThreshold = 0.25f; private float _yoloNmsThreshold = 0.45f; [Category("基本信息"), DisplayName("模型编号"), Description("模型的唯一标识符,用于与相机编号对应。")] public int Id { get => _id; set { if (_id != value) { _id = value; OnPropertyChanged(); } } } [Category("基本信息"), DisplayName("模型名称"), Description("给模型起一个易于识别的别名。")] public string Name { get => _name; set { if (_name != value) { _name = value; OnPropertyChanged(); } } } [Category("基本信息"), DisplayName("算法类型"), Description("所使用的算法的类型。")] [TypeConverter(typeof(EnumDescriptionTypeConverter))] public AlgorithmType M_AType { get => _mAType; set { if (_mAType != value) { _mAType = value; OnPropertyChanged(); } } } [Category("基本信息"), DisplayName("推理设备"), Description("推理模型的设备。")] [TypeConverter(typeof(EnumDescriptionTypeConverter))] public DetectDevice CheckDevice { get => _checkDevice; set { if (_checkDevice != value) { _checkDevice = value; OnPropertyChanged(); } } } [Category("基本信息"), DisplayName("模型类型"), Description("推理模型的类型。")] [TypeConverter(typeof(EnumDescriptionTypeConverter))] public CheckModelType MType { get => _mType; set { if (_mType != value) { _mType = value; OnPropertyChanged(); } } } [Category("基本信息"), DisplayName("是否启用"), Description("是否在程序启动时是否启用模型")] public bool IsEnabled { get => _isEnabled; set { if (_isEnabled != value) { _isEnabled = value; OnPropertyChanged(); } } } [Category("文件"), DisplayName("模型路径"), Description("选择模型文件(.onnx, .bin, etc., .pt)。")] [Editor(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))] public string Path { get => _path; set { if (_path != value) { _path = value; OnPropertyChanged(); } } } [Category("模型参数"), DisplayName("HALCON得分阈值"), Description("HALCON模板匹配的得分阈值(0-1)。")] public double HalconScoreThreshold { get => _halconScoreThreshold; set { if (_halconScoreThreshold != value) { _halconScoreThreshold = value; OnPropertyChanged(); } } } [Category("模型参数"), DisplayName("YOLO置信度阈值"), Description("YOLO检测的置信度阈值(0-1)。")] public float YoloConfidenceThreshold { get => _yoloConfidenceThreshold; set { if (_yoloConfidenceThreshold != value) { _yoloConfidenceThreshold = value; OnPropertyChanged(); } } } [Category("模型参数"), DisplayName("YOLO NMS阈值"), Description("YOLO检测的非极大值抑制(NMS)阈值(0-1)。")] public float YoloNmsThreshold { get => _yoloNmsThreshold; set { if (_yoloNmsThreshold != value) { _yoloNmsThreshold = value; OnPropertyChanged(); } } } protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public object Clone() { return this.MemberwiseClone(); // 浅克隆对于这个类足够了 } } }