领胜LDS 键盘AOI检测项目
xcd
2020-06-24 d6c577e17ee7bb5331dd51d803f9b42441b0f0e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
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<DetectionConfig>), typeof(UITypeEditor))]
        public List<DetectionConfig> DetectionConfigs { get; set; } = new List<DetectionConfig>();
 
        [Category("检测配置")]
        [Description("GPU数量")]
        public int GPUNums { get; set; } = 1;
 
        [Category("检测配置")]
        [Description("是否启用队列优先级")]
        public bool IsEnablePriority { get; set; }
 
        [Category("缺陷配置")]
        [Description("缺陷定义集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<DefectDefinition>), typeof(UITypeEditor))]
        public List<DefectDefinition> DefectList { get; set; } = new List<DefectDefinition>();
 
        //[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<DefectSetting>), typeof(UITypeEditor))]
        public List<DefectSetting> DefectSettingList { get; set; } = new List<DefectSetting>();
 
        [Category("算法配置")]
        [Description("预处理算法文件路径配置")]
        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
        public string HalconAlgorithemPath_Pre { get; set; }
 
        [Category("算法配置")]
        [Description("预处理输出结果的SPEC标准配置")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<Spec>), typeof(UITypeEditor))]
        public List<Spec> OutputSpec_Pre { get; set; } = new List<Spec>();
 
        [Category("算法配置")]
        [Description("后处理算法文件路径配置")]
        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
        public string HalconAlgorithemPath_After { get; set; }
 
        [Category("算法配置")]
        [Description("后处理输出结果的SPEC标准配置")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<Spec>), typeof(UITypeEditor))]
        public List<Spec> OutputSpec_After { get; set; } = new List<Spec>();
 
        [Category("关联相机")]
        [Description("关联相机描述")]
        [TypeConverter(typeof(DeviceSelectorConverter<CameraBase>))]
        public string CameraSource { get; set; } = "";
 
        [Category("关联相机")]
        [Description("检测的优先级:值越大,优先级越高,越早处理")]
        public int Priority { get; set; }
 
        [JsonIgnore]
        [Browsable(false)]
        public static Dictionary<string, string> CameraIdDict { get; set; } = new Dictionary<string, string>();
 
        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<DefectDefinition> DefectList { get; set; } = new List<DefectDefinition>();
 
        ////二次检测标准
        //[Category("阈值配置(二次检测)")]
        //[Description("二次检测配置集合")]
        //[TypeConverter(typeof(CollectionCountConvert))]
        //[Editor(typeof(ComplexCollectionEditor<SecondDefectRule>), typeof(UITypeEditor))]
        //public List<SecondDefectRule> SecondDefectRuleList { get; set; } = new List<SecondDefectRule>();
 
        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
    {
    }
}