using Bro.Common.Base; using Bro.Common.Helper; using Bro.Common.Model; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Bro.Device.SuakitProcessor { [Device("SuakitProcessor", "Suakit深度学习处理器", EnumHelper.DeviceAttributeType.InitialConfig)] public class SuakitProcessorInitialConfig : InitialConfigBase { [Category("检测配置")] [Description("检测配置集合")] [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] public List DetectionConfigs { get; set; } = new List(); [Category("检测配置")] [Description("GPU数量")] public int GPUNums { get; set; } = 1; [Category("检测配置")] [Description("是否启用队列优先级")] public bool IsEnablePriority { get; set; } [Category("缺陷配置")] [Description("缺陷定义集合")] [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] public List DefectList { get; set; } = new List(); //[Category("保存设置")] //[Description("采图保存目录")] //[Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))] //public string ImgDirectory { get; set; } //[Category("保存设置")] //[Description("图片保存天数")] //[Browsable(false)] //public int SaveImageDayLimit { get; set; } = 0; //[Category("保存设置")] //[Description("是否保存图片")] //public bool IsSaveImage { get; set; } = false; //[Category("保存设置")] //[Description("是否保存CSV产品数据")] //public bool IsSaveCSVData { get; set; } = false; } public class DetectionConfig : IComplexDisplay { [Browsable(false)] [ReadOnly(true)] public string Id { get; set; } = Guid.NewGuid().ToString(); [Category("标志配置")] [Description("检测配置名称")] public string Name { get; set; } [Category("网络配置")] [Description("网络适配图片大小")] [TypeConverter(typeof(ComplexObjectConvert))] [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))] public CustomizedPoint ImageSize { get; set; } = new CustomizedPoint(); [Category("网络配置")] [Description("网络适配图片通道数量")] public int ImageChannels { get; set; } = 1; [Category("网络配置")] [Description("网络文件路径,目前路径中不可含有中文字符")] [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))] public string NetPath { get; set; } [Category("网络配置")] [Description("缺陷信息配置集合")] [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] public List DefectSettingList { get; set; } = new List(); [Category("算法配置")] [Description("预处理算法文件路径配置")] [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))] public string HalconAlgorithemPath_Pre { get; set; } [Category("算法配置")] [Description("预处理输出结果的SPEC标准配置")] [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] public List OutputSpec_Pre { get; set; } = new List(); [Category("算法配置")] [Description("后处理算法文件路径配置")] [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))] public string HalconAlgorithemPath_After { get; set; } [Category("算法配置")] [Description("后处理输出结果的SPEC标准配置")] [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] public List OutputSpec_After { get; set; } = new List(); [Category("关联相机")] [Description("关联相机描述")] [TypeConverter(typeof(DeviceSelectorConverter))] public string CameraSource { get; set; } = ""; [Category("关联相机")] [Description("检测的优先级:值越大,优先级越高,越早处理")] public int Priority { get; set; } [JsonIgnore] [Browsable(false)] public static Dictionary CameraIdDict { get; set; } = new Dictionary(); public string GetDisplayText() { //return $"{Name}{(CameraIdDict.ContainsKey(CameraSource) ? ("_" + CameraIdDict[CameraSource]) : "")}"; return $"{Name}"; } } public class DefectDefinition : IComplexDisplay { [Category("缺陷定义")] [Description("缺陷编码")] [ReadOnly(true)] public string Id { get; set; } = Guid.NewGuid().ToString(); [Category("缺陷定义")] [Description("缺陷描述")] public string Description { get; set; } = ""; public string GetDisplayText() { return Description; } } public class DefectSetting : IComplexDisplay { [Category("缺陷信息")] [Description("缺陷信息")] //[TypeConverter(typeof(DefectIdNameConvert))] public string DefectId { get; set; } private string defectName = ""; [Browsable(false)] public string DefectName { get { if (string.IsNullOrEmpty(defectName)) { defectName = DefectSetting.DefectList.FirstOrDefault(u => u.Id == DefectId)?.Description; } return defectName; } } private float probability = 0; [Category("阈值配置(最低标准)")] [Description("最低标准可能性阈值,设置在0~1之间,缺陷不满足最低标准,判断为绝对OK")] public float Probability { get => probability; set { if (value < 0) { value = 0; } if (value > 1) { value = 1; } probability = value; } } private float uncertainty = 0; [Category("阈值配置(最低标准)")] [Description("最低标准不确定性阈值,设置在0~1之间")] public float Uncertainty { get => uncertainty; set { if (value < 0) { value = 0; } if (value > 1) { value = 1; } uncertainty = value; } } [Category("阈值配置(最低标准)")] [Description("最低标准缺陷大小阈值")] [TypeConverter(typeof(ComplexObjectConvert))] [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))] public CustomizedPoint MinDefectSize { get; set; } = new CustomizedPoint(); [Category("阈值配置(最低标准)")] [Description("最低标准缺陷长宽关系,true:必须长宽都满足;false:长或者宽有一个满足即可")] public bool IsMinDefectSizeAndCondition { get; set; } = true; [JsonIgnore] [Browsable(false)] public static List DefectList { get; set; } = new List(); ////二次检测标准 //[Category("阈值配置(二次检测)")] //[Description("二次检测配置集合")] //[TypeConverter(typeof(CollectionCountConvert))] //[Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] //public List SecondDefectRuleList { get; set; } = new List(); public string GetDisplayText() { if (!string.IsNullOrWhiteSpace(DefectId) && DefectList.Count > 0) { return DefectList.FirstOrDefault(u => u.Id == DefectId)?.Description ?? ""; } else { return ""; } } } [Device("SuakitProcessor", "Suakit深度学习处理器", EnumHelper.DeviceAttributeType.OperationConfig)] public class SuakitProcessorOperationConfig : OperationConfigBase { } }