This commit is contained in:
2025-03-18 14:25:41 +08:00
58 changed files with 1088 additions and 535 deletions

View File

@ -6,7 +6,10 @@ using System.Text.RegularExpressions;
using System.Text;
using System.Drawing.Design;
using AntdUI;
using System.Text.Json.Serialization;
using static DH.Commons.Enums.EnumHelper;
using System.Collections.ObjectModel;
namespace DH.Commons.Enums
@ -117,20 +120,20 @@ namespace DH.Commons.Enums
/// </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; }//识别到对象的 显示信息
@ -151,10 +154,10 @@ namespace DH.Commons.Enums
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>();
@ -178,8 +181,8 @@ namespace DH.Commons.Enums
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)
@ -204,18 +207,18 @@ namespace DH.Commons.Enums
}
public class DetectStationResult
{
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string Pid { get; set; }
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string TempPid { get; set; }
/// <summary>
/// 检测工位名称
/// </summary>
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string DetectName { get; set; }
@ -262,9 +265,9 @@ namespace DH.Commons.Enums
public int StationDetectElapsed { get; set; }
public static string NormalizeAndClean(string input)
{
#pragma warning disable CS8603 // 可能返回 null 引用
#pragma warning disable CS8603 // 可能返回 null 引用
if (input == null) return null;
#pragma warning restore CS8603 // 可能返回 null 引用
#pragma warning restore CS8603 // 可能返回 null 引用
// Step 1: 标准化字符编码为 Form C (规范组合)
string normalizedString = input.Normalize(NormalizationForm.FormC);
@ -289,6 +292,7 @@ namespace DH.Commons.Enums
[Category("关联相机")]
[DisplayName("相机源ID")]
[Description("关联相机的唯一标识符")]
[JsonPropertyName("camera_sourceId")]
//[TypeConverter(typeof(CollectionCountConvert))]
public string CameraSourceId
{
@ -462,193 +466,217 @@ namespace DH.Commons.Enums
return new CustomizedPoint(p1.X + p2.X, p1.Y + p2.Y);
}
}
// public class PreTreatParam
// {
// public class PreTreatParam
// {
// /// <summary>
// /// 参数名称
// /// </summary>
// ///
// [Category("预处理参数")]
// [DisplayName("参数名称")]
// [Description("参数名称")]
//#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
// public string Name { get; set; }
// /// <summary>
// /// 参数名称
// /// </summary>
// ///
// [Category("预处理参数")]
// [DisplayName("参数名称")]
// [Description("参数名称")]
//
// public string Name { get; set; }
// /// <summary>
// /// 参数值
// /// </summary>
// ///
// [Category("预处理参数")]
// [DisplayName("参数值")]
// [Description("参数值")]
//#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
// public string Value { get; set; }
// /// <summary>
// /// 参数值
// /// </summary>
// ///
// [Category("预处理参数")]
// [DisplayName("参数值")]
// [Description("参数值")]
//
// public string Value { get; set; }
// }
public class DetectionConfig
// }
public class DetectionConfig : NotifyProperty
{
#region
[JsonPropertyName("id")]
[ReadOnly(true)]
public string Id { get; set; } = Guid.NewGuid().ToString();
public string Id { get; private set; } = Guid.NewGuid().ToString();
[Category("检测配置")]
[DisplayName("检测配置名称")]
[Description("检测配置名称")]
[JsonPropertyName("name")]
public string Name { get; set; }
#endregion
#region
[Category("关联相机")]
[DisplayName("关联相机")]
[Description("关联相机描述")]
[JsonPropertyName("camera_source_id")]
public string CameraSourceId { get; set; } = "";
[Category("关联相机集合")]
[DisplayName("关联相机集合")]
[Description("关联相机描述")]
//[TypeConverter(typeof(DeviceIdSelectorConverter<CameraBase>))]
public List<RelatedCamera> CameraCollects { get; set; } = new List<RelatedCamera>();
[JsonPropertyName("camera_Collects")]
public List<RelatedCamera> CameraCollects { get; set; } = new();
#endregion
#region
[Category("启用配置")]
[DisplayName("是否启用GPU检测")]
[Description("是否启用GPU检测")]
public bool IsEnableGPU { get; set; } = false;
[JsonPropertyName("is_enable_gpu")]
public bool IsEnableGPU { get; set; }
[Category("启用配置")]
[DisplayName("是否混料模型")]
[Description("是否混料模型")]
public bool IsMixModel { get; set; } = false;
[JsonPropertyName("is_mixModel")]
public bool IsMixModel { get; set; }
[Category("启用配置")]
[DisplayName("是否启用该检测")]
[Description("是否启用该检测")]
[JsonPropertyName("is_enabled")]
public bool IsEnabled { get; set; }
[Category("启用配置")]
[DisplayName("是否加入检测工位")]
[Description("是否加入检测工位")]
public bool IsAddStation { get; set; } = true;
[DisplayName("是否启用预处理")]
[JsonPropertyName("is_PreEnabled")]
public bool IsPreEnabled { get; set; }
// public bool IsAddStation { get; set; } = true;
private bool _isAddStation;
[Category("启用配置")]
[DisplayName("是否加入检测工位")]
[JsonPropertyName("is_addstation")]
public bool IsAddStation
{
get => _isAddStation;
set
{
if (_isAddStation != value)
{
_isAddStation = value;
OnPropertyChanged(nameof(IsAddStation));
}
}
}
#endregion
#region
[Category("1.预处理(视觉算子)")]
[DisplayName("预处理-算法文件路径")]
// [Description("预处理算法文件路径配置")][Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
[JsonPropertyName("halcon_algorithemPath_pre")]
public string HalconAlgorithemPath_Pre { get; set; }
// [Category("1.预处理(视觉算子)")]
//[DisplayName("预处理-输出结果的SPEC标准")]
//[Description("预处理输出结果的SPEC标准配置")]
// public List<IndexedSpec> OutputSpec_Pre { get; set; } = new List<IndexedSpec>();
[Category("1.预处理(视觉算子)")]
[DisplayName("预处理-参数列表")]
[Description("预处理-参数列表")]
public List<PreTreatParam> PreTreatParams { get; set; } = new List<PreTreatParam>();
[JsonPropertyName("pre_treatParams")]
public List<PreTreatParam> PreTreatParams { get; set; } = new();
[Category("1.预处理(视觉算子)")]
[DisplayName("预处理-输出参数列表")]
[Description("预处理-输出参数列表")]
public List<PreTreatParam> OUTPreTreatParams { get; set; } = new List<PreTreatParam>();
[JsonPropertyName("out_preTreatParams")]
public List<PreTreatParam> OUTPreTreatParams { get; set; } = new();
#endregion
#region
[Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型类型")]
[Description("模型类型ImageClassification-图片分类ObjectDetection目标检测Segmentation-图像分割")]
//[TypeConverter(typeof(EnumDescriptionConverter<MLModelType>))]
[DisplayName("模型类型")]
[JsonPropertyName("model_Type")]
public MLModelType ModelType { get; set; } = MLModelType.ObjectDetection;
//[Category("2.中检测(深度学习)")]
//[DisplayName("中检测-GPU索引")]
//[Description("GPU索引")]
//public int GPUIndex { get; set; } = 0;
[Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型文件路径")]
[Description("中处理 深度学习模型文件路径,路径中不可含有中文字符,一般情况可以只配置中检测模型,当需要先用预检测过滤一次时,请先配置好与预检测相关配置")]
[DisplayName("模型文件路径")]
[JsonPropertyName("model_Path")]
public string ModelPath { get; set; }
[Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型宽度")]
[Description("中处理-模型宽度")]
[DisplayName("模型宽度")]
[JsonPropertyName("model_Width")]
public int ModelWidth { get; set; } = 640;
[Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型高度")]
[Description("中处理-模型高度")]
[DisplayName("模型高度")]
[JsonPropertyName("model_Height")]
public int ModelHeight { get; set; } = 640;
[Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型节点名称")]
[Description("中处理-模型节点名称")]
[DisplayName("模型节点名称")]
[JsonPropertyName("model_outNodeName")]
public string ModeloutNodeName { get; set; } = "output0";
[Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型置信度")]
[Description("中处理-模型置信度")]
[DisplayName("模型置信度")]
[JsonPropertyName("model_confThreshold")]
public float ModelconfThreshold { get; set; } = 0.5f;
[Category("2.中检测(深度学习)")]
[DisplayName("中检测-模型标签路径")]
[Description("中处理-模型标签路径")]
[DisplayName("模型标签路径")]
[JsonPropertyName("in_lablepath")]
public string in_lable_path { get; set; }
#endregion
#region
// public List<SizeTreatParam> PreTreatCollects { get; set; } = new();
private List<SizeTreatParam> _preTreatParams = new();
[Category("1.尺寸测量集合")]
[DisplayName("尺寸测量集合")]
[JsonPropertyName("Pre_TreatCollects")]
public List<SizeTreatParam> PreTreatCollects
{
get => _preTreatParams;
set
{
if (_preTreatParams != value)
{
_preTreatParams = value;
OnPropertyChanged(nameof(PreTreatCollects));
}
}
}
#endregion
#region
[Category("4.最终过滤(逻辑过滤)")]
[DisplayName("过滤器集合")]
[Description("最后的逻辑过滤:可根据 识别出对象的 宽度、高度、面积、得分来设置最终检测结果,同一识别目标同一判定,多项过滤器之间为“或”关系")]
public List<DetectionFilter> DetectionFilterList { get; set; } = new List<DetectionFilter>();
[JsonPropertyName("detection_filterList")]
public List<DetectionFilter> DetectionFilterList { get; set; } = new();
#endregion
#region
[JsonPropertyName("Detection_LableList")]
public List<DetectionLable> DetectionLableList { get; set; } = new();
/// <summary>
/// 标签集合
/// </summary>
public List<DetectionLable> DetectionLableList { get; set; } = new List<DetectionLable>();
//[Category("深度学习配置")]
//[DisplayName("检测配置标签")]
//[Description("检测配置标签关联")]
//public List<DetectConfigLabel> DetectConfigLabelList { get; set; } = new List<DetectConfigLabel>();
[Category("显示配置")]
[DisplayName("显示位置")]
[Description("检测信息显示位置。左上角为11向右向下为正方向")]
// [TypeConverter(typeof(ComplexObjectConvert))]
// [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
public CustomizedPoint ShowLocation { get; set; } = new CustomizedPoint();
[JsonPropertyName("Show_Location")]
public CustomizedPoint ShowLocation { get; set; } = new();
#endregion
//public event PropertyChangedEventHandler PropertyChanged;
public DetectionConfig()
//protected virtual void OnPropertyChanged(string propertyName)
//{
// PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
//}
#region
public DetectionConfig() { }
public DetectionConfig(string name, MLModelType modelType, string modelPath, bool isEnableGPU, string sCameraSourceId)
{
}
public DetectionConfig(string name, MLModelType modelType, string modelPath, bool isEnableGPU,string sCameraSourceId)
{
ModelPath = modelPath ?? string.Empty;
Name = name;
ModelType = modelType;
ModelPath = modelPath ?? string.Empty;
IsEnableGPU = isEnableGPU;
Id = Guid.NewGuid().ToString();
CameraSourceId = sCameraSourceId;
Id = Guid.NewGuid().ToString();
}
#endregion
}
//大改预处理类
@ -660,6 +688,7 @@ namespace DH.Commons.Enums
private bool _selected = false;
public bool Selected
{
get { return _selected; }
@ -670,6 +699,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(Selected));
}
}
[JsonPropertyName("name")]
private string _name;
public string Name
{
@ -684,6 +714,7 @@ namespace DH.Commons.Enums
private string _value;
[JsonPropertyName("value")]
public string Value
{
get { return _value; }
@ -698,7 +729,9 @@ namespace DH.Commons.Enums
private CellLink[] cellLinks;
public CellLink[] CellLinks
{
get { return cellLinks; }
get {
return cellLinks; }
set
{
if (cellLinks == value) return;
@ -737,7 +770,7 @@ namespace DH.Commons.Enums
}
[JsonPropertyName("labelId")]
public string LabelId
{
get { return _labelId; }
@ -748,7 +781,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(LabelId));
}
}
[JsonPropertyName("labelName")]
public string LabelName
{
get { return _labelName; }
@ -759,7 +792,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(LabelName));
}
}
[JsonPropertyName("maxSource")]
public double MaxSource
{
get { return _maxSource; }
@ -771,6 +804,7 @@ namespace DH.Commons.Enums
}
}
[JsonPropertyName("minSource")]
public double MinSource
{
get { return _minSource; }
@ -781,7 +815,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(MinSource));
}
}
[JsonPropertyName("maxArea")]
public double MaxArea
{
get { return _maxArea; }
@ -792,7 +826,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(MaxArea));
}
}
[JsonPropertyName("minArea")]
public double MinArea
{
get { return _minArea; }
@ -803,7 +837,7 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(MinArea));
}
}
[JsonPropertyName("_resultState")]
public ResultState ResultState
{
get { return _resultState; }
@ -814,11 +848,13 @@ namespace DH.Commons.Enums
OnPropertyChanged(nameof(ResultState));
}
}
private CellLink[] cellLinks;
public CellLink[] CellLinks
{
get { return cellLinks; }
get {
return cellLinks; }
set
{
if (cellLinks == value) return;
@ -827,6 +863,60 @@ namespace DH.Commons.Enums
}
}
}
public class PreTreatCollect
{
[Category("尺寸测量集合")]
[DisplayName("预处理-算法文件路径")]
[Description("预处理算法文件路径配置")]
[JsonPropertyName("halconPath_Pre")]
// [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
public string HalconPath_Pre { get; set; }
[Category("尺寸测量集合")]
[DisplayName("输入参数列表")]
[Description("输入参数列表")]
[JsonPropertyName("preParams")]
// [TypeConverter(typeof(CollectionCountConvert))]
// [Editor(typeof(ComplexCollectionEditor<PreTreatParam>), typeof(UITypeEditor))]
public List<PreTreatParam> PreParams { get; set; } = new List<PreTreatParam>();
[Category("尺寸测量集合")]
[DisplayName("输出参数列表")]
[Description("输出参数列表")]
[JsonPropertyName("outPreParams")]
// [TypeConverter(typeof(CollectionCountConvert))]
// [Editor(typeof(ComplexCollectionEditor<PreTreatParam>), typeof(UITypeEditor))]
public List<PreTreatParam> outPreParams { get; set; } = new List<PreTreatParam>();
[Category("尺寸测量集合")]
[DisplayName("预处理-名称")]
[Description("预处理名称")]
[JsonPropertyName("preName")]
public string PreName { get; set; }
[Category("尺寸测量集合")]
[DisplayName("预处理-启用")]
[Description("预处理启用")]
[JsonPropertyName("preIsEnable")]
public bool PreIsEnable { get; set; } = false;
[Category("尺寸测量集合")]
[DisplayName("类型")]
[Description("类型")]
[JsonPropertyName("preType")]
// [TypeConverter(typeof(EnumDescriptionConverter<SizeEnum>))]
public SizeEnum PreType { get; set; }
[Category("尺寸测量集合")]
[DisplayName("阈值")]
[Description("阈值")]
[JsonPropertyName("prePix")]
public int PrePix { get; set; }
}
public class SizeTreatParam : NotifyProperty
{
@ -923,16 +1013,16 @@ namespace DH.Commons.Enums
}
}
public string PrePath
{
get { return _prePath; }
set
{
if (_prePath.Equals(value)) return;
_prePath = value;
OnPropertyChanged(nameof(PrePath));
}
}
//public string PrePath
//{
// get { return _prePath; }
// set
// {
// if (_prePath.Equals(value)) return;
// _prePath = value;
// OnPropertyChanged(nameof(PrePath));
// }
//}
private CellLink[] cellLinks;
@ -987,7 +1077,7 @@ namespace DH.Commons.Enums
[DisplayName("检测项标签")]
[Description("检测标签Id")]
//[TypeConverter(typeof(DetectionLabelConverter))]
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string LabelId { get; set; }

View File

@ -674,31 +674,31 @@ namespace DH.Commons.Enums
Warning = 8,
}
public enum ResultState
{
[Description("NA")]
NA = -5,
[Description("尺寸NG")]
SizeNG = -4,
[Description("检测NG")]
DetectNG = -3,
//public enum ResultState
//{
// [Description("NA")]
// NA = -5,
// [Description("尺寸NG")]
// SizeNG = -4,
// [Description("检测NG")]
// DetectNG = -3,
//[Description("检测不足TBD")]
// ShortageTBD = -2,
[Description("检测结果TBD")]
ResultTBD = -1,
[Description("OK")]
OK = 1,
// [Description("NG")]
// NG = 2,
//统计结果
[Description("A类NG")]
A_NG = 25,
[Description("B类NG")]
B_NG = 26,
[Description("C类NG")]
C_NG = 27,
}
// //[Description("检测不足TBD")]
// // ShortageTBD = -2,
// [Description("检测结果TBD")]
// ResultTBD = -1,
// [Description("OK")]
// OK = 1,
// // [Description("NG")]
// // NG = 2,
// //统计结果
// [Description("A类NG")]
// A_NG = 25,
// [Description("B类NG")]
// B_NG = 26,
// [Description("C类NG")]
// C_NG = 27,
//}
public enum HikCameraType
{
[Description("HikCamera-Gige")]

View File

@ -571,8 +571,8 @@ namespace DH.Commons.Enums
}
//分别基于像素GetPixel和SetPixel、基于内存、基于指针这三种方法增强图片对比度
// 第一种方法:像素提取法速度慢 基于像素400-600ms
//分别基于像素GetPixel和SetPixel、基于内存、基于指针这三种方法增强图片对比度
// 第一种方法:像素提取法 速度慢 基于像素400-600ms
public static Bitmap MethodBaseOnPixel(Bitmap bitmap, int degree)
{
Color curColor;

View File

@ -108,7 +108,7 @@ namespace DH.Commons.Enums
                DataGridViewCheckboxHeaderEventArgs ex = new DataGridViewCheckboxHeaderEventArgs();
ex.CheckedState = _checked;
object sender = new object();//此处不代表选择的列头checkbox只是作为参数传递因为列头checkbox是绘制出来的无法获得它的实例
object sender = new object();//此处不代表选择的列头checkbox只是作为参数传递 因为列头checkbox是绘制出来的无法获得它的实例
                if (OnCheckBoxClicked != null)
{