diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index e4ddfe3..c5571c7 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -109,9 +109,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) @@ -173,9 +173,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index e4ddfe3..c5571c7 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -109,9 +109,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) @@ -173,9 +173,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index 40e4ec9..ab18cb6 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -28,9 +28,9 @@ return _cameraController; } - public void timerCamera_Tick(Object sender, EventArgs myEventArgs) + public void TimerCamera_Tick(Object sender, EventArgs myEventArgs) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); //准备相机列表 uint numDevices = 0; numDevices = DeviceListAcq(); @@ -38,9 +38,9 @@ if (numDevices == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("没有检测到相机!", "提示"); + MessageBox.Show("[timerCamera_Tick]没有检测到相机!", "提示"); else - MessageBox.Show("No Device!", "提示"); + MessageBox.Show("[timerCamera_Tick]No Device!", "提示"); return; } @@ -71,7 +71,7 @@ nRet = CameraOperator.EnumDevices(MyCamera.MV_USB_DEVICE, ref ProMemory.m_pDeviceList); if (0 != nRet) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); return 0; } @@ -86,9 +86,9 @@ if (ProMemory.m_pDeviceList.nDeviceNum == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("无设备!", "提示"); + MessageBox.Show("[ConnectCamera]连接相机时无设备!", "提示"); else - MessageBox.Show("No Device!", "Meaasge"); + MessageBox.Show("[ConnectCamera]No Device!", "Meaasge"); return; } @@ -104,9 +104,9 @@ if (MyCamera.MV_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("相机打开失败!","提示"); + MessageBox.Show("[ConnectCamera]相机打开失败!", "提示"); else - MessageBox.Show("No Device!", "Message"); + MessageBox.Show("[ConnectCamera]No Device!", "Message"); return; } @@ -115,44 +115,48 @@ m_pOperator.SetEnumValue("TriggerMode", 0); //注册回调函数 - ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance().SaveImage); + ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance.SaveImage); nRet = m_pOperator.RegisterImageCallBack(ProMemory.ImageCallback, IntPtr.Zero); if (CameraOperator.CO_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("注册回调失败!", "提示"); + MessageBox.Show("[ConnectCamera]注册回调失败!", "提示"); else - MessageBox.Show("regist failed", "message"); + MessageBox.Show("[ConnectCamera]regist failed", "message"); } - ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(getException); + ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(GetException); int exNet = m_pOperator.RegisterExceptionCallBack(ProMemory.CallBackFunc, IntPtr.Zero); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); MessageBox.Show("ConnectCamera:" + e.Message); } } - private void getException(uint nMsgType, IntPtr pUser) + private void GetException(uint nMsgType, IntPtr pUser) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); ShutdownHelper.Restart(); //LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save success!"); } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed" + ex.Message); } } + /** + * 待机 + * 持续监测感应模块,有外触发到来则重新开始工作 + */ public void ContinuousShot_TriggerOn() { try @@ -160,16 +164,20 @@ ProMemory.isWait = true; ProMemory.jobRuning = false; - stopGrabbing(); + // 先停止取流 + StopGrabbing(); //GC.Collect(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + + // 循环检测是否有外触发,重新开始工作 while (ProMemory.isWait) { - if (ProMemory.IoControllService.getSensorVal() == 1) //通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + // 通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + if (ProMemory.IoControllService.getSensorVal() == 1) { - //外触发到来,开始采集 - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); + // 外触发到来,开始采集 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); ProMemory.IoControllService.YellowOn(); ProMemory.isWait = false; Grabbing(); @@ -178,28 +186,30 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); MessageBox.Show("ContinuousShot_TriggerOn:" + e.Message); } } - //普通模式开始采集 + /** + * 正常工作 + */ public void ContinuousShot_TriggerOff() { try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来当前线程:" + Thread.CurrentThread.Name); - //重置界面 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来,当前线程:" + Thread.CurrentThread.Name); + + // 重置界面 if (ProMemory.formType == "1") Form1.GetInstance().ReInitialize(); else if (ProMemory.formType == "2") Form2.GetInstance().ReInitialize(); ProMemory.IoControllService.YellowOn(); Grabbing(); - } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); } } @@ -216,7 +226,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); MessageBox.Show("CloseCamera:" + e.Message); } } @@ -226,7 +236,7 @@ { if (ProMemory.isSyning) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中,暂停取流"); return; } //ProMemory.jobRuning = true; @@ -241,7 +251,9 @@ { nRet = m_pOperator.StopGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "停止取流失败;"; + } else { msg += "停止取流成功;"; @@ -251,7 +263,9 @@ nRet = m_pOperator.StartGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "开始取流失败;"; + } else { msg += "开始取流成功;"; @@ -260,32 +274,48 @@ } } + // 视频画面显示在界面上 int playRet = 0; - if (ProMemory.formType == "1") m_pOperator.Display(Form1.GetInstance().picLive.Handle); - else if (ProMemory.formType == "2") m_pOperator.Display(Form2.GetInstance().picLive.Handle); + if (ProMemory.formType == "1") + { + m_pOperator.Display(Form1.GetInstance().picLive.Handle); + } + else if (ProMemory.formType == "2") + { + m_pOperator.Display(Form2.GetInstance().picLive.Handle); + } if (MyCamera.MV_OK != playRet) - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + } - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 ProMemory.findingEyes = true; + ProMemory.identifyConfig.FlagWorking = true; } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); } finally { } } - private void stopGrabbing() + private void StopGrabbing() { - int nRet = m_pOperator.StopGrabbing(); - if (ProMemory.formType == "1") Form1.GetInstance().picLive.Image = null; - else if (ProMemory.formType == "2") Form2.GetInstance().picLive.Image = null; + m_pOperator.StopGrabbing(); + if (ProMemory.formType == "1") + { + Form1.GetInstance().picLive.Image = null; + } + else if (ProMemory.formType == "2") + { + Form2.GetInstance().picLive.Image = null; + } ProMemory.m_bGrabbing = false; } diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index e4ddfe3..c5571c7 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -109,9 +109,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) @@ -173,9 +173,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index 40e4ec9..ab18cb6 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -28,9 +28,9 @@ return _cameraController; } - public void timerCamera_Tick(Object sender, EventArgs myEventArgs) + public void TimerCamera_Tick(Object sender, EventArgs myEventArgs) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); //准备相机列表 uint numDevices = 0; numDevices = DeviceListAcq(); @@ -38,9 +38,9 @@ if (numDevices == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("没有检测到相机!", "提示"); + MessageBox.Show("[timerCamera_Tick]没有检测到相机!", "提示"); else - MessageBox.Show("No Device!", "提示"); + MessageBox.Show("[timerCamera_Tick]No Device!", "提示"); return; } @@ -71,7 +71,7 @@ nRet = CameraOperator.EnumDevices(MyCamera.MV_USB_DEVICE, ref ProMemory.m_pDeviceList); if (0 != nRet) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); return 0; } @@ -86,9 +86,9 @@ if (ProMemory.m_pDeviceList.nDeviceNum == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("无设备!", "提示"); + MessageBox.Show("[ConnectCamera]连接相机时无设备!", "提示"); else - MessageBox.Show("No Device!", "Meaasge"); + MessageBox.Show("[ConnectCamera]No Device!", "Meaasge"); return; } @@ -104,9 +104,9 @@ if (MyCamera.MV_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("相机打开失败!","提示"); + MessageBox.Show("[ConnectCamera]相机打开失败!", "提示"); else - MessageBox.Show("No Device!", "Message"); + MessageBox.Show("[ConnectCamera]No Device!", "Message"); return; } @@ -115,44 +115,48 @@ m_pOperator.SetEnumValue("TriggerMode", 0); //注册回调函数 - ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance().SaveImage); + ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance.SaveImage); nRet = m_pOperator.RegisterImageCallBack(ProMemory.ImageCallback, IntPtr.Zero); if (CameraOperator.CO_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("注册回调失败!", "提示"); + MessageBox.Show("[ConnectCamera]注册回调失败!", "提示"); else - MessageBox.Show("regist failed", "message"); + MessageBox.Show("[ConnectCamera]regist failed", "message"); } - ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(getException); + ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(GetException); int exNet = m_pOperator.RegisterExceptionCallBack(ProMemory.CallBackFunc, IntPtr.Zero); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); MessageBox.Show("ConnectCamera:" + e.Message); } } - private void getException(uint nMsgType, IntPtr pUser) + private void GetException(uint nMsgType, IntPtr pUser) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); ShutdownHelper.Restart(); //LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save success!"); } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed" + ex.Message); } } + /** + * 待机 + * 持续监测感应模块,有外触发到来则重新开始工作 + */ public void ContinuousShot_TriggerOn() { try @@ -160,16 +164,20 @@ ProMemory.isWait = true; ProMemory.jobRuning = false; - stopGrabbing(); + // 先停止取流 + StopGrabbing(); //GC.Collect(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + + // 循环检测是否有外触发,重新开始工作 while (ProMemory.isWait) { - if (ProMemory.IoControllService.getSensorVal() == 1) //通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + // 通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + if (ProMemory.IoControllService.getSensorVal() == 1) { - //外触发到来,开始采集 - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); + // 外触发到来,开始采集 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); ProMemory.IoControllService.YellowOn(); ProMemory.isWait = false; Grabbing(); @@ -178,28 +186,30 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); MessageBox.Show("ContinuousShot_TriggerOn:" + e.Message); } } - //普通模式开始采集 + /** + * 正常工作 + */ public void ContinuousShot_TriggerOff() { try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来当前线程:" + Thread.CurrentThread.Name); - //重置界面 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来,当前线程:" + Thread.CurrentThread.Name); + + // 重置界面 if (ProMemory.formType == "1") Form1.GetInstance().ReInitialize(); else if (ProMemory.formType == "2") Form2.GetInstance().ReInitialize(); ProMemory.IoControllService.YellowOn(); Grabbing(); - } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); } } @@ -216,7 +226,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); MessageBox.Show("CloseCamera:" + e.Message); } } @@ -226,7 +236,7 @@ { if (ProMemory.isSyning) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中,暂停取流"); return; } //ProMemory.jobRuning = true; @@ -241,7 +251,9 @@ { nRet = m_pOperator.StopGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "停止取流失败;"; + } else { msg += "停止取流成功;"; @@ -251,7 +263,9 @@ nRet = m_pOperator.StartGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "开始取流失败;"; + } else { msg += "开始取流成功;"; @@ -260,32 +274,48 @@ } } + // 视频画面显示在界面上 int playRet = 0; - if (ProMemory.formType == "1") m_pOperator.Display(Form1.GetInstance().picLive.Handle); - else if (ProMemory.formType == "2") m_pOperator.Display(Form2.GetInstance().picLive.Handle); + if (ProMemory.formType == "1") + { + m_pOperator.Display(Form1.GetInstance().picLive.Handle); + } + else if (ProMemory.formType == "2") + { + m_pOperator.Display(Form2.GetInstance().picLive.Handle); + } if (MyCamera.MV_OK != playRet) - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + } - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 ProMemory.findingEyes = true; + ProMemory.identifyConfig.FlagWorking = true; } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); } finally { } } - private void stopGrabbing() + private void StopGrabbing() { - int nRet = m_pOperator.StopGrabbing(); - if (ProMemory.formType == "1") Form1.GetInstance().picLive.Image = null; - else if (ProMemory.formType == "2") Form2.GetInstance().picLive.Image = null; + m_pOperator.StopGrabbing(); + if (ProMemory.formType == "1") + { + Form1.GetInstance().picLive.Image = null; + } + else if (ProMemory.formType == "2") + { + Form2.GetInstance().picLive.Image = null; + } ProMemory.m_bGrabbing = false; } diff --git a/irisRefactor/IrisThread/FindEyesTh.cs b/irisRefactor/IrisThread/FindEyesTh.cs index baa4137..aaee4b3 100644 --- a/irisRefactor/IrisThread/FindEyesTh.cs +++ b/irisRefactor/IrisThread/FindEyesTh.cs @@ -35,13 +35,13 @@ while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning) { //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index e4ddfe3..c5571c7 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -109,9 +109,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) @@ -173,9 +173,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index 40e4ec9..ab18cb6 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -28,9 +28,9 @@ return _cameraController; } - public void timerCamera_Tick(Object sender, EventArgs myEventArgs) + public void TimerCamera_Tick(Object sender, EventArgs myEventArgs) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); //准备相机列表 uint numDevices = 0; numDevices = DeviceListAcq(); @@ -38,9 +38,9 @@ if (numDevices == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("没有检测到相机!", "提示"); + MessageBox.Show("[timerCamera_Tick]没有检测到相机!", "提示"); else - MessageBox.Show("No Device!", "提示"); + MessageBox.Show("[timerCamera_Tick]No Device!", "提示"); return; } @@ -71,7 +71,7 @@ nRet = CameraOperator.EnumDevices(MyCamera.MV_USB_DEVICE, ref ProMemory.m_pDeviceList); if (0 != nRet) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); return 0; } @@ -86,9 +86,9 @@ if (ProMemory.m_pDeviceList.nDeviceNum == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("无设备!", "提示"); + MessageBox.Show("[ConnectCamera]连接相机时无设备!", "提示"); else - MessageBox.Show("No Device!", "Meaasge"); + MessageBox.Show("[ConnectCamera]No Device!", "Meaasge"); return; } @@ -104,9 +104,9 @@ if (MyCamera.MV_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("相机打开失败!","提示"); + MessageBox.Show("[ConnectCamera]相机打开失败!", "提示"); else - MessageBox.Show("No Device!", "Message"); + MessageBox.Show("[ConnectCamera]No Device!", "Message"); return; } @@ -115,44 +115,48 @@ m_pOperator.SetEnumValue("TriggerMode", 0); //注册回调函数 - ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance().SaveImage); + ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance.SaveImage); nRet = m_pOperator.RegisterImageCallBack(ProMemory.ImageCallback, IntPtr.Zero); if (CameraOperator.CO_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("注册回调失败!", "提示"); + MessageBox.Show("[ConnectCamera]注册回调失败!", "提示"); else - MessageBox.Show("regist failed", "message"); + MessageBox.Show("[ConnectCamera]regist failed", "message"); } - ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(getException); + ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(GetException); int exNet = m_pOperator.RegisterExceptionCallBack(ProMemory.CallBackFunc, IntPtr.Zero); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); MessageBox.Show("ConnectCamera:" + e.Message); } } - private void getException(uint nMsgType, IntPtr pUser) + private void GetException(uint nMsgType, IntPtr pUser) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); ShutdownHelper.Restart(); //LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save success!"); } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed" + ex.Message); } } + /** + * 待机 + * 持续监测感应模块,有外触发到来则重新开始工作 + */ public void ContinuousShot_TriggerOn() { try @@ -160,16 +164,20 @@ ProMemory.isWait = true; ProMemory.jobRuning = false; - stopGrabbing(); + // 先停止取流 + StopGrabbing(); //GC.Collect(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + + // 循环检测是否有外触发,重新开始工作 while (ProMemory.isWait) { - if (ProMemory.IoControllService.getSensorVal() == 1) //通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + // 通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + if (ProMemory.IoControllService.getSensorVal() == 1) { - //外触发到来,开始采集 - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); + // 外触发到来,开始采集 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); ProMemory.IoControllService.YellowOn(); ProMemory.isWait = false; Grabbing(); @@ -178,28 +186,30 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); MessageBox.Show("ContinuousShot_TriggerOn:" + e.Message); } } - //普通模式开始采集 + /** + * 正常工作 + */ public void ContinuousShot_TriggerOff() { try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来当前线程:" + Thread.CurrentThread.Name); - //重置界面 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来,当前线程:" + Thread.CurrentThread.Name); + + // 重置界面 if (ProMemory.formType == "1") Form1.GetInstance().ReInitialize(); else if (ProMemory.formType == "2") Form2.GetInstance().ReInitialize(); ProMemory.IoControllService.YellowOn(); Grabbing(); - } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); } } @@ -216,7 +226,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); MessageBox.Show("CloseCamera:" + e.Message); } } @@ -226,7 +236,7 @@ { if (ProMemory.isSyning) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中,暂停取流"); return; } //ProMemory.jobRuning = true; @@ -241,7 +251,9 @@ { nRet = m_pOperator.StopGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "停止取流失败;"; + } else { msg += "停止取流成功;"; @@ -251,7 +263,9 @@ nRet = m_pOperator.StartGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "开始取流失败;"; + } else { msg += "开始取流成功;"; @@ -260,32 +274,48 @@ } } + // 视频画面显示在界面上 int playRet = 0; - if (ProMemory.formType == "1") m_pOperator.Display(Form1.GetInstance().picLive.Handle); - else if (ProMemory.formType == "2") m_pOperator.Display(Form2.GetInstance().picLive.Handle); + if (ProMemory.formType == "1") + { + m_pOperator.Display(Form1.GetInstance().picLive.Handle); + } + else if (ProMemory.formType == "2") + { + m_pOperator.Display(Form2.GetInstance().picLive.Handle); + } if (MyCamera.MV_OK != playRet) - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + } - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 ProMemory.findingEyes = true; + ProMemory.identifyConfig.FlagWorking = true; } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); } finally { } } - private void stopGrabbing() + private void StopGrabbing() { - int nRet = m_pOperator.StopGrabbing(); - if (ProMemory.formType == "1") Form1.GetInstance().picLive.Image = null; - else if (ProMemory.formType == "2") Form2.GetInstance().picLive.Image = null; + m_pOperator.StopGrabbing(); + if (ProMemory.formType == "1") + { + Form1.GetInstance().picLive.Image = null; + } + else if (ProMemory.formType == "2") + { + Form2.GetInstance().picLive.Image = null; + } ProMemory.m_bGrabbing = false; } diff --git a/irisRefactor/IrisThread/FindEyesTh.cs b/irisRefactor/IrisThread/FindEyesTh.cs index baa4137..aaee4b3 100644 --- a/irisRefactor/IrisThread/FindEyesTh.cs +++ b/irisRefactor/IrisThread/FindEyesTh.cs @@ -35,13 +35,13 @@ while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning) { //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs new file mode 100644 index 0000000..32e9240 --- /dev/null +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -0,0 +1,104 @@ +using irisHelper; +using irisRefactor.FrmService; +using System; +using System.Diagnostics; +using System.Reflection; +using System.Threading; + +namespace irisRefactor.IrisThread +{ + public class IdentifyTh + { + private static readonly IdentifyTh identiyfTh = new IdentifyTh(); + private IdentifyTh() { } + public static IdentifyTh GetInstance + { + get => identiyfTh; + } + + public void Identify() + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); + ProMemory.irisConfig.IdentifyAccess = true; + + // 用于计算操作耗时 + Stopwatch sw = new Stopwatch(); + + try + { + int iMatchNumber = 0; + float iHammingDistance = 1; + int iLeftRight = 0; + + while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && + ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + { + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); + if (ProMemory.irisConfig.Q4.Count > 0) + { + lock (ProMemory.irisConfig.Q4) + { + if (ProMemory.irisConfig.Q4.Count > 0) + { + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + } + } + if (ProMemory.irisConfig.QualifiedIrisBuffer != null) + { + //加载匹配列表 + sw.Restart(); + iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "识别[" + iMatchNumber + "]:" + sw.ElapsedMilliseconds); + } + } + } + + // ProMemory.timer2.Dispose();//停止计时器 + + + //跳出循环,条件是时间到、匹配成功或者正在关闭程序 + ProMemory.irisConfig.AssessThreadRun = false; + ProMemory.irisConfig.EyeFinderThreadRun = false; + + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + //匹配成功 + if (iMatchNumber > 0) + { + string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId + if (ProMemory.formType == "1") + Form1.GetInstance().Success(personId); + else if (ProMemory.formType == "2") + Form2.GetInstance().Success(personId); + //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); + Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); + } + //匹配失败 + else + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().failure(); + //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + } + + + ProMemory.jobRuning = false; + ProMemory.cameraController.ContinuousShot_TriggerOff(); + + } + catch (Exception ex) + { + LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); + } + } + + + } +} \ No newline at end of file diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index e4ddfe3..c5571c7 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -109,9 +109,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) @@ -173,9 +173,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index 40e4ec9..ab18cb6 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -28,9 +28,9 @@ return _cameraController; } - public void timerCamera_Tick(Object sender, EventArgs myEventArgs) + public void TimerCamera_Tick(Object sender, EventArgs myEventArgs) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); //准备相机列表 uint numDevices = 0; numDevices = DeviceListAcq(); @@ -38,9 +38,9 @@ if (numDevices == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("没有检测到相机!", "提示"); + MessageBox.Show("[timerCamera_Tick]没有检测到相机!", "提示"); else - MessageBox.Show("No Device!", "提示"); + MessageBox.Show("[timerCamera_Tick]No Device!", "提示"); return; } @@ -71,7 +71,7 @@ nRet = CameraOperator.EnumDevices(MyCamera.MV_USB_DEVICE, ref ProMemory.m_pDeviceList); if (0 != nRet) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); return 0; } @@ -86,9 +86,9 @@ if (ProMemory.m_pDeviceList.nDeviceNum == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("无设备!", "提示"); + MessageBox.Show("[ConnectCamera]连接相机时无设备!", "提示"); else - MessageBox.Show("No Device!", "Meaasge"); + MessageBox.Show("[ConnectCamera]No Device!", "Meaasge"); return; } @@ -104,9 +104,9 @@ if (MyCamera.MV_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("相机打开失败!","提示"); + MessageBox.Show("[ConnectCamera]相机打开失败!", "提示"); else - MessageBox.Show("No Device!", "Message"); + MessageBox.Show("[ConnectCamera]No Device!", "Message"); return; } @@ -115,44 +115,48 @@ m_pOperator.SetEnumValue("TriggerMode", 0); //注册回调函数 - ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance().SaveImage); + ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance.SaveImage); nRet = m_pOperator.RegisterImageCallBack(ProMemory.ImageCallback, IntPtr.Zero); if (CameraOperator.CO_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("注册回调失败!", "提示"); + MessageBox.Show("[ConnectCamera]注册回调失败!", "提示"); else - MessageBox.Show("regist failed", "message"); + MessageBox.Show("[ConnectCamera]regist failed", "message"); } - ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(getException); + ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(GetException); int exNet = m_pOperator.RegisterExceptionCallBack(ProMemory.CallBackFunc, IntPtr.Zero); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); MessageBox.Show("ConnectCamera:" + e.Message); } } - private void getException(uint nMsgType, IntPtr pUser) + private void GetException(uint nMsgType, IntPtr pUser) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); ShutdownHelper.Restart(); //LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save success!"); } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed" + ex.Message); } } + /** + * 待机 + * 持续监测感应模块,有外触发到来则重新开始工作 + */ public void ContinuousShot_TriggerOn() { try @@ -160,16 +164,20 @@ ProMemory.isWait = true; ProMemory.jobRuning = false; - stopGrabbing(); + // 先停止取流 + StopGrabbing(); //GC.Collect(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + + // 循环检测是否有外触发,重新开始工作 while (ProMemory.isWait) { - if (ProMemory.IoControllService.getSensorVal() == 1) //通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + // 通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + if (ProMemory.IoControllService.getSensorVal() == 1) { - //外触发到来,开始采集 - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); + // 外触发到来,开始采集 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); ProMemory.IoControllService.YellowOn(); ProMemory.isWait = false; Grabbing(); @@ -178,28 +186,30 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); MessageBox.Show("ContinuousShot_TriggerOn:" + e.Message); } } - //普通模式开始采集 + /** + * 正常工作 + */ public void ContinuousShot_TriggerOff() { try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来当前线程:" + Thread.CurrentThread.Name); - //重置界面 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来,当前线程:" + Thread.CurrentThread.Name); + + // 重置界面 if (ProMemory.formType == "1") Form1.GetInstance().ReInitialize(); else if (ProMemory.formType == "2") Form2.GetInstance().ReInitialize(); ProMemory.IoControllService.YellowOn(); Grabbing(); - } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); } } @@ -216,7 +226,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); MessageBox.Show("CloseCamera:" + e.Message); } } @@ -226,7 +236,7 @@ { if (ProMemory.isSyning) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中,暂停取流"); return; } //ProMemory.jobRuning = true; @@ -241,7 +251,9 @@ { nRet = m_pOperator.StopGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "停止取流失败;"; + } else { msg += "停止取流成功;"; @@ -251,7 +263,9 @@ nRet = m_pOperator.StartGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "开始取流失败;"; + } else { msg += "开始取流成功;"; @@ -260,32 +274,48 @@ } } + // 视频画面显示在界面上 int playRet = 0; - if (ProMemory.formType == "1") m_pOperator.Display(Form1.GetInstance().picLive.Handle); - else if (ProMemory.formType == "2") m_pOperator.Display(Form2.GetInstance().picLive.Handle); + if (ProMemory.formType == "1") + { + m_pOperator.Display(Form1.GetInstance().picLive.Handle); + } + else if (ProMemory.formType == "2") + { + m_pOperator.Display(Form2.GetInstance().picLive.Handle); + } if (MyCamera.MV_OK != playRet) - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + } - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 ProMemory.findingEyes = true; + ProMemory.identifyConfig.FlagWorking = true; } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); } finally { } } - private void stopGrabbing() + private void StopGrabbing() { - int nRet = m_pOperator.StopGrabbing(); - if (ProMemory.formType == "1") Form1.GetInstance().picLive.Image = null; - else if (ProMemory.formType == "2") Form2.GetInstance().picLive.Image = null; + m_pOperator.StopGrabbing(); + if (ProMemory.formType == "1") + { + Form1.GetInstance().picLive.Image = null; + } + else if (ProMemory.formType == "2") + { + Form2.GetInstance().picLive.Image = null; + } ProMemory.m_bGrabbing = false; } diff --git a/irisRefactor/IrisThread/FindEyesTh.cs b/irisRefactor/IrisThread/FindEyesTh.cs index baa4137..aaee4b3 100644 --- a/irisRefactor/IrisThread/FindEyesTh.cs +++ b/irisRefactor/IrisThread/FindEyesTh.cs @@ -35,13 +35,13 @@ while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning) { //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs new file mode 100644 index 0000000..32e9240 --- /dev/null +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -0,0 +1,104 @@ +using irisHelper; +using irisRefactor.FrmService; +using System; +using System.Diagnostics; +using System.Reflection; +using System.Threading; + +namespace irisRefactor.IrisThread +{ + public class IdentifyTh + { + private static readonly IdentifyTh identiyfTh = new IdentifyTh(); + private IdentifyTh() { } + public static IdentifyTh GetInstance + { + get => identiyfTh; + } + + public void Identify() + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); + ProMemory.irisConfig.IdentifyAccess = true; + + // 用于计算操作耗时 + Stopwatch sw = new Stopwatch(); + + try + { + int iMatchNumber = 0; + float iHammingDistance = 1; + int iLeftRight = 0; + + while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && + ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + { + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); + if (ProMemory.irisConfig.Q4.Count > 0) + { + lock (ProMemory.irisConfig.Q4) + { + if (ProMemory.irisConfig.Q4.Count > 0) + { + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + } + } + if (ProMemory.irisConfig.QualifiedIrisBuffer != null) + { + //加载匹配列表 + sw.Restart(); + iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "识别[" + iMatchNumber + "]:" + sw.ElapsedMilliseconds); + } + } + } + + // ProMemory.timer2.Dispose();//停止计时器 + + + //跳出循环,条件是时间到、匹配成功或者正在关闭程序 + ProMemory.irisConfig.AssessThreadRun = false; + ProMemory.irisConfig.EyeFinderThreadRun = false; + + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + //匹配成功 + if (iMatchNumber > 0) + { + string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId + if (ProMemory.formType == "1") + Form1.GetInstance().Success(personId); + else if (ProMemory.formType == "2") + Form2.GetInstance().Success(personId); + //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); + Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); + } + //匹配失败 + else + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().failure(); + //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + } + + + ProMemory.jobRuning = false; + ProMemory.cameraController.ContinuousShot_TriggerOff(); + + } + catch (Exception ex) + { + LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); + } + } + + + } +} \ No newline at end of file diff --git a/irisRefactor/IrisThread/IdentiyfTh.cs b/irisRefactor/IrisThread/IdentiyfTh.cs deleted file mode 100644 index 99878de..0000000 --- a/irisRefactor/IrisThread/IdentiyfTh.cs +++ /dev/null @@ -1,100 +0,0 @@ -using irisHelper; -using irisRefactor.FrmService; -using System; -using System.Reflection; -using System.Threading; - -namespace irisRefactor.IrisThread -{ - public class IdentiyfTh - { - private static IdentiyfTh _identiyfTh = null; - private IdentiyfTh() { - } - public static IdentiyfTh GetInstance() - { - if (_identiyfTh == null) - _identiyfTh = new IdentiyfTh(); - - return _identiyfTh; - - } - - public void Identify() - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify"); - ProMemory.irisConfig.IdentifyAccess = true; - - try - { - int iMatchNumber = 0; - float iHammingDistance = 1; - int iLeftRight = 0; - - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) - { - lock (ProMemory.irisConfig.Q4) - { - if (ProMemory.irisConfig.Q4.Count > 0) - { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); - } - } - if (ProMemory.irisConfig.QualifiedIrisBuffer != null) - { - //加载匹配列表 - iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); - } - } - } - - // ProMemory.timer2.Dispose();//停止计时器 - - //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; - - if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) - ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); - - //匹配成功 - if (iMatchNumber > 0) - { - string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId - if (ProMemory.formType == "1") - Form1.GetInstance().Success(personId); - else if (ProMemory.formType == "2") - Form2.GetInstance().Success(personId); - //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); - Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); - } - //匹配失败 - else - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); - - if (ProMemory.formType == "1") - Form1.GetInstance().failure(); - else if (ProMemory.formType == "2") - Form2.GetInstance().failure(); - //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); - Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); - } - - ProMemory.jobRuning = false; - ProMemory.cameraController.ContinuousShot_TriggerOff(); - - } - catch (Exception ex) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); - } - } - - - } -} \ No newline at end of file diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index e4ddfe3..c5571c7 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -109,9 +109,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) @@ -173,9 +173,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index 40e4ec9..ab18cb6 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -28,9 +28,9 @@ return _cameraController; } - public void timerCamera_Tick(Object sender, EventArgs myEventArgs) + public void TimerCamera_Tick(Object sender, EventArgs myEventArgs) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); //准备相机列表 uint numDevices = 0; numDevices = DeviceListAcq(); @@ -38,9 +38,9 @@ if (numDevices == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("没有检测到相机!", "提示"); + MessageBox.Show("[timerCamera_Tick]没有检测到相机!", "提示"); else - MessageBox.Show("No Device!", "提示"); + MessageBox.Show("[timerCamera_Tick]No Device!", "提示"); return; } @@ -71,7 +71,7 @@ nRet = CameraOperator.EnumDevices(MyCamera.MV_USB_DEVICE, ref ProMemory.m_pDeviceList); if (0 != nRet) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); return 0; } @@ -86,9 +86,9 @@ if (ProMemory.m_pDeviceList.nDeviceNum == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("无设备!", "提示"); + MessageBox.Show("[ConnectCamera]连接相机时无设备!", "提示"); else - MessageBox.Show("No Device!", "Meaasge"); + MessageBox.Show("[ConnectCamera]No Device!", "Meaasge"); return; } @@ -104,9 +104,9 @@ if (MyCamera.MV_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("相机打开失败!","提示"); + MessageBox.Show("[ConnectCamera]相机打开失败!", "提示"); else - MessageBox.Show("No Device!", "Message"); + MessageBox.Show("[ConnectCamera]No Device!", "Message"); return; } @@ -115,44 +115,48 @@ m_pOperator.SetEnumValue("TriggerMode", 0); //注册回调函数 - ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance().SaveImage); + ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance.SaveImage); nRet = m_pOperator.RegisterImageCallBack(ProMemory.ImageCallback, IntPtr.Zero); if (CameraOperator.CO_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("注册回调失败!", "提示"); + MessageBox.Show("[ConnectCamera]注册回调失败!", "提示"); else - MessageBox.Show("regist failed", "message"); + MessageBox.Show("[ConnectCamera]regist failed", "message"); } - ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(getException); + ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(GetException); int exNet = m_pOperator.RegisterExceptionCallBack(ProMemory.CallBackFunc, IntPtr.Zero); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); MessageBox.Show("ConnectCamera:" + e.Message); } } - private void getException(uint nMsgType, IntPtr pUser) + private void GetException(uint nMsgType, IntPtr pUser) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); ShutdownHelper.Restart(); //LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save success!"); } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed" + ex.Message); } } + /** + * 待机 + * 持续监测感应模块,有外触发到来则重新开始工作 + */ public void ContinuousShot_TriggerOn() { try @@ -160,16 +164,20 @@ ProMemory.isWait = true; ProMemory.jobRuning = false; - stopGrabbing(); + // 先停止取流 + StopGrabbing(); //GC.Collect(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + + // 循环检测是否有外触发,重新开始工作 while (ProMemory.isWait) { - if (ProMemory.IoControllService.getSensorVal() == 1) //通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + // 通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + if (ProMemory.IoControllService.getSensorVal() == 1) { - //外触发到来,开始采集 - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); + // 外触发到来,开始采集 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); ProMemory.IoControllService.YellowOn(); ProMemory.isWait = false; Grabbing(); @@ -178,28 +186,30 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); MessageBox.Show("ContinuousShot_TriggerOn:" + e.Message); } } - //普通模式开始采集 + /** + * 正常工作 + */ public void ContinuousShot_TriggerOff() { try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来当前线程:" + Thread.CurrentThread.Name); - //重置界面 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来,当前线程:" + Thread.CurrentThread.Name); + + // 重置界面 if (ProMemory.formType == "1") Form1.GetInstance().ReInitialize(); else if (ProMemory.formType == "2") Form2.GetInstance().ReInitialize(); ProMemory.IoControllService.YellowOn(); Grabbing(); - } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); } } @@ -216,7 +226,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); MessageBox.Show("CloseCamera:" + e.Message); } } @@ -226,7 +236,7 @@ { if (ProMemory.isSyning) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中,暂停取流"); return; } //ProMemory.jobRuning = true; @@ -241,7 +251,9 @@ { nRet = m_pOperator.StopGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "停止取流失败;"; + } else { msg += "停止取流成功;"; @@ -251,7 +263,9 @@ nRet = m_pOperator.StartGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "开始取流失败;"; + } else { msg += "开始取流成功;"; @@ -260,32 +274,48 @@ } } + // 视频画面显示在界面上 int playRet = 0; - if (ProMemory.formType == "1") m_pOperator.Display(Form1.GetInstance().picLive.Handle); - else if (ProMemory.formType == "2") m_pOperator.Display(Form2.GetInstance().picLive.Handle); + if (ProMemory.formType == "1") + { + m_pOperator.Display(Form1.GetInstance().picLive.Handle); + } + else if (ProMemory.formType == "2") + { + m_pOperator.Display(Form2.GetInstance().picLive.Handle); + } if (MyCamera.MV_OK != playRet) - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + } - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 ProMemory.findingEyes = true; + ProMemory.identifyConfig.FlagWorking = true; } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); } finally { } } - private void stopGrabbing() + private void StopGrabbing() { - int nRet = m_pOperator.StopGrabbing(); - if (ProMemory.formType == "1") Form1.GetInstance().picLive.Image = null; - else if (ProMemory.formType == "2") Form2.GetInstance().picLive.Image = null; + m_pOperator.StopGrabbing(); + if (ProMemory.formType == "1") + { + Form1.GetInstance().picLive.Image = null; + } + else if (ProMemory.formType == "2") + { + Form2.GetInstance().picLive.Image = null; + } ProMemory.m_bGrabbing = false; } diff --git a/irisRefactor/IrisThread/FindEyesTh.cs b/irisRefactor/IrisThread/FindEyesTh.cs index baa4137..aaee4b3 100644 --- a/irisRefactor/IrisThread/FindEyesTh.cs +++ b/irisRefactor/IrisThread/FindEyesTh.cs @@ -35,13 +35,13 @@ while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning) { //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs new file mode 100644 index 0000000..32e9240 --- /dev/null +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -0,0 +1,104 @@ +using irisHelper; +using irisRefactor.FrmService; +using System; +using System.Diagnostics; +using System.Reflection; +using System.Threading; + +namespace irisRefactor.IrisThread +{ + public class IdentifyTh + { + private static readonly IdentifyTh identiyfTh = new IdentifyTh(); + private IdentifyTh() { } + public static IdentifyTh GetInstance + { + get => identiyfTh; + } + + public void Identify() + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); + ProMemory.irisConfig.IdentifyAccess = true; + + // 用于计算操作耗时 + Stopwatch sw = new Stopwatch(); + + try + { + int iMatchNumber = 0; + float iHammingDistance = 1; + int iLeftRight = 0; + + while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && + ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + { + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); + if (ProMemory.irisConfig.Q4.Count > 0) + { + lock (ProMemory.irisConfig.Q4) + { + if (ProMemory.irisConfig.Q4.Count > 0) + { + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + } + } + if (ProMemory.irisConfig.QualifiedIrisBuffer != null) + { + //加载匹配列表 + sw.Restart(); + iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "识别[" + iMatchNumber + "]:" + sw.ElapsedMilliseconds); + } + } + } + + // ProMemory.timer2.Dispose();//停止计时器 + + + //跳出循环,条件是时间到、匹配成功或者正在关闭程序 + ProMemory.irisConfig.AssessThreadRun = false; + ProMemory.irisConfig.EyeFinderThreadRun = false; + + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + //匹配成功 + if (iMatchNumber > 0) + { + string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId + if (ProMemory.formType == "1") + Form1.GetInstance().Success(personId); + else if (ProMemory.formType == "2") + Form2.GetInstance().Success(personId); + //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); + Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); + } + //匹配失败 + else + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().failure(); + //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + } + + + ProMemory.jobRuning = false; + ProMemory.cameraController.ContinuousShot_TriggerOff(); + + } + catch (Exception ex) + { + LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); + } + } + + + } +} \ No newline at end of file diff --git a/irisRefactor/IrisThread/IdentiyfTh.cs b/irisRefactor/IrisThread/IdentiyfTh.cs deleted file mode 100644 index 99878de..0000000 --- a/irisRefactor/IrisThread/IdentiyfTh.cs +++ /dev/null @@ -1,100 +0,0 @@ -using irisHelper; -using irisRefactor.FrmService; -using System; -using System.Reflection; -using System.Threading; - -namespace irisRefactor.IrisThread -{ - public class IdentiyfTh - { - private static IdentiyfTh _identiyfTh = null; - private IdentiyfTh() { - } - public static IdentiyfTh GetInstance() - { - if (_identiyfTh == null) - _identiyfTh = new IdentiyfTh(); - - return _identiyfTh; - - } - - public void Identify() - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify"); - ProMemory.irisConfig.IdentifyAccess = true; - - try - { - int iMatchNumber = 0; - float iHammingDistance = 1; - int iLeftRight = 0; - - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) - { - lock (ProMemory.irisConfig.Q4) - { - if (ProMemory.irisConfig.Q4.Count > 0) - { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); - } - } - if (ProMemory.irisConfig.QualifiedIrisBuffer != null) - { - //加载匹配列表 - iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); - } - } - } - - // ProMemory.timer2.Dispose();//停止计时器 - - //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; - - if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) - ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); - - //匹配成功 - if (iMatchNumber > 0) - { - string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId - if (ProMemory.formType == "1") - Form1.GetInstance().Success(personId); - else if (ProMemory.formType == "2") - Form2.GetInstance().Success(personId); - //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); - Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); - } - //匹配失败 - else - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); - - if (ProMemory.formType == "1") - Form1.GetInstance().failure(); - else if (ProMemory.formType == "2") - Form2.GetInstance().failure(); - //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); - Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); - } - - ProMemory.jobRuning = false; - ProMemory.cameraController.ContinuousShot_TriggerOff(); - - } - catch (Exception ex) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); - } - } - - - } -} \ No newline at end of file diff --git a/irisRefactor/IrisThread/ImageQualityAssessTh.cs b/irisRefactor/IrisThread/ImageQualityAssessTh.cs index b21ca9d..0650491 100644 --- a/irisRefactor/IrisThread/ImageQualityAssessTh.cs +++ b/irisRefactor/IrisThread/ImageQualityAssessTh.cs @@ -105,7 +105,7 @@ ProMemory.irisConfig.Key_Identify = 1; ProMemory.irisConfig.IdentifyThreadRun = true; - Thread m_IdentifyThread = new Thread(IdentiyfTh.GetInstance().Identify); + Thread m_IdentifyThread = new Thread(IdentifyTh.GetInstance.Identify); m_IdentifyThread.Name = "Identify"; m_IdentifyThread.Start(); } @@ -136,7 +136,7 @@ if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) { Form1.GetInstance().obtainTemp(); - Form1.GetInstance().failure(); + Form1.GetInstance().Failure(); } else { Form2.GetInstance().failure(); diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index e4ddfe3..c5571c7 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -109,9 +109,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) @@ -173,9 +173,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index 40e4ec9..ab18cb6 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -28,9 +28,9 @@ return _cameraController; } - public void timerCamera_Tick(Object sender, EventArgs myEventArgs) + public void TimerCamera_Tick(Object sender, EventArgs myEventArgs) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); //准备相机列表 uint numDevices = 0; numDevices = DeviceListAcq(); @@ -38,9 +38,9 @@ if (numDevices == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("没有检测到相机!", "提示"); + MessageBox.Show("[timerCamera_Tick]没有检测到相机!", "提示"); else - MessageBox.Show("No Device!", "提示"); + MessageBox.Show("[timerCamera_Tick]No Device!", "提示"); return; } @@ -71,7 +71,7 @@ nRet = CameraOperator.EnumDevices(MyCamera.MV_USB_DEVICE, ref ProMemory.m_pDeviceList); if (0 != nRet) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); return 0; } @@ -86,9 +86,9 @@ if (ProMemory.m_pDeviceList.nDeviceNum == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("无设备!", "提示"); + MessageBox.Show("[ConnectCamera]连接相机时无设备!", "提示"); else - MessageBox.Show("No Device!", "Meaasge"); + MessageBox.Show("[ConnectCamera]No Device!", "Meaasge"); return; } @@ -104,9 +104,9 @@ if (MyCamera.MV_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("相机打开失败!","提示"); + MessageBox.Show("[ConnectCamera]相机打开失败!", "提示"); else - MessageBox.Show("No Device!", "Message"); + MessageBox.Show("[ConnectCamera]No Device!", "Message"); return; } @@ -115,44 +115,48 @@ m_pOperator.SetEnumValue("TriggerMode", 0); //注册回调函数 - ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance().SaveImage); + ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance.SaveImage); nRet = m_pOperator.RegisterImageCallBack(ProMemory.ImageCallback, IntPtr.Zero); if (CameraOperator.CO_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("注册回调失败!", "提示"); + MessageBox.Show("[ConnectCamera]注册回调失败!", "提示"); else - MessageBox.Show("regist failed", "message"); + MessageBox.Show("[ConnectCamera]regist failed", "message"); } - ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(getException); + ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(GetException); int exNet = m_pOperator.RegisterExceptionCallBack(ProMemory.CallBackFunc, IntPtr.Zero); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); MessageBox.Show("ConnectCamera:" + e.Message); } } - private void getException(uint nMsgType, IntPtr pUser) + private void GetException(uint nMsgType, IntPtr pUser) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); ShutdownHelper.Restart(); //LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save success!"); } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed" + ex.Message); } } + /** + * 待机 + * 持续监测感应模块,有外触发到来则重新开始工作 + */ public void ContinuousShot_TriggerOn() { try @@ -160,16 +164,20 @@ ProMemory.isWait = true; ProMemory.jobRuning = false; - stopGrabbing(); + // 先停止取流 + StopGrabbing(); //GC.Collect(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + + // 循环检测是否有外触发,重新开始工作 while (ProMemory.isWait) { - if (ProMemory.IoControllService.getSensorVal() == 1) //通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + // 通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + if (ProMemory.IoControllService.getSensorVal() == 1) { - //外触发到来,开始采集 - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); + // 外触发到来,开始采集 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); ProMemory.IoControllService.YellowOn(); ProMemory.isWait = false; Grabbing(); @@ -178,28 +186,30 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); MessageBox.Show("ContinuousShot_TriggerOn:" + e.Message); } } - //普通模式开始采集 + /** + * 正常工作 + */ public void ContinuousShot_TriggerOff() { try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来当前线程:" + Thread.CurrentThread.Name); - //重置界面 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来,当前线程:" + Thread.CurrentThread.Name); + + // 重置界面 if (ProMemory.formType == "1") Form1.GetInstance().ReInitialize(); else if (ProMemory.formType == "2") Form2.GetInstance().ReInitialize(); ProMemory.IoControllService.YellowOn(); Grabbing(); - } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); } } @@ -216,7 +226,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); MessageBox.Show("CloseCamera:" + e.Message); } } @@ -226,7 +236,7 @@ { if (ProMemory.isSyning) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中,暂停取流"); return; } //ProMemory.jobRuning = true; @@ -241,7 +251,9 @@ { nRet = m_pOperator.StopGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "停止取流失败;"; + } else { msg += "停止取流成功;"; @@ -251,7 +263,9 @@ nRet = m_pOperator.StartGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "开始取流失败;"; + } else { msg += "开始取流成功;"; @@ -260,32 +274,48 @@ } } + // 视频画面显示在界面上 int playRet = 0; - if (ProMemory.formType == "1") m_pOperator.Display(Form1.GetInstance().picLive.Handle); - else if (ProMemory.formType == "2") m_pOperator.Display(Form2.GetInstance().picLive.Handle); + if (ProMemory.formType == "1") + { + m_pOperator.Display(Form1.GetInstance().picLive.Handle); + } + else if (ProMemory.formType == "2") + { + m_pOperator.Display(Form2.GetInstance().picLive.Handle); + } if (MyCamera.MV_OK != playRet) - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + } - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 ProMemory.findingEyes = true; + ProMemory.identifyConfig.FlagWorking = true; } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); } finally { } } - private void stopGrabbing() + private void StopGrabbing() { - int nRet = m_pOperator.StopGrabbing(); - if (ProMemory.formType == "1") Form1.GetInstance().picLive.Image = null; - else if (ProMemory.formType == "2") Form2.GetInstance().picLive.Image = null; + m_pOperator.StopGrabbing(); + if (ProMemory.formType == "1") + { + Form1.GetInstance().picLive.Image = null; + } + else if (ProMemory.formType == "2") + { + Form2.GetInstance().picLive.Image = null; + } ProMemory.m_bGrabbing = false; } diff --git a/irisRefactor/IrisThread/FindEyesTh.cs b/irisRefactor/IrisThread/FindEyesTh.cs index baa4137..aaee4b3 100644 --- a/irisRefactor/IrisThread/FindEyesTh.cs +++ b/irisRefactor/IrisThread/FindEyesTh.cs @@ -35,13 +35,13 @@ while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning) { //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs new file mode 100644 index 0000000..32e9240 --- /dev/null +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -0,0 +1,104 @@ +using irisHelper; +using irisRefactor.FrmService; +using System; +using System.Diagnostics; +using System.Reflection; +using System.Threading; + +namespace irisRefactor.IrisThread +{ + public class IdentifyTh + { + private static readonly IdentifyTh identiyfTh = new IdentifyTh(); + private IdentifyTh() { } + public static IdentifyTh GetInstance + { + get => identiyfTh; + } + + public void Identify() + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); + ProMemory.irisConfig.IdentifyAccess = true; + + // 用于计算操作耗时 + Stopwatch sw = new Stopwatch(); + + try + { + int iMatchNumber = 0; + float iHammingDistance = 1; + int iLeftRight = 0; + + while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && + ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + { + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); + if (ProMemory.irisConfig.Q4.Count > 0) + { + lock (ProMemory.irisConfig.Q4) + { + if (ProMemory.irisConfig.Q4.Count > 0) + { + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + } + } + if (ProMemory.irisConfig.QualifiedIrisBuffer != null) + { + //加载匹配列表 + sw.Restart(); + iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "识别[" + iMatchNumber + "]:" + sw.ElapsedMilliseconds); + } + } + } + + // ProMemory.timer2.Dispose();//停止计时器 + + + //跳出循环,条件是时间到、匹配成功或者正在关闭程序 + ProMemory.irisConfig.AssessThreadRun = false; + ProMemory.irisConfig.EyeFinderThreadRun = false; + + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + //匹配成功 + if (iMatchNumber > 0) + { + string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId + if (ProMemory.formType == "1") + Form1.GetInstance().Success(personId); + else if (ProMemory.formType == "2") + Form2.GetInstance().Success(personId); + //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); + Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); + } + //匹配失败 + else + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().failure(); + //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + } + + + ProMemory.jobRuning = false; + ProMemory.cameraController.ContinuousShot_TriggerOff(); + + } + catch (Exception ex) + { + LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); + } + } + + + } +} \ No newline at end of file diff --git a/irisRefactor/IrisThread/IdentiyfTh.cs b/irisRefactor/IrisThread/IdentiyfTh.cs deleted file mode 100644 index 99878de..0000000 --- a/irisRefactor/IrisThread/IdentiyfTh.cs +++ /dev/null @@ -1,100 +0,0 @@ -using irisHelper; -using irisRefactor.FrmService; -using System; -using System.Reflection; -using System.Threading; - -namespace irisRefactor.IrisThread -{ - public class IdentiyfTh - { - private static IdentiyfTh _identiyfTh = null; - private IdentiyfTh() { - } - public static IdentiyfTh GetInstance() - { - if (_identiyfTh == null) - _identiyfTh = new IdentiyfTh(); - - return _identiyfTh; - - } - - public void Identify() - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify"); - ProMemory.irisConfig.IdentifyAccess = true; - - try - { - int iMatchNumber = 0; - float iHammingDistance = 1; - int iLeftRight = 0; - - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) - { - lock (ProMemory.irisConfig.Q4) - { - if (ProMemory.irisConfig.Q4.Count > 0) - { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); - } - } - if (ProMemory.irisConfig.QualifiedIrisBuffer != null) - { - //加载匹配列表 - iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); - } - } - } - - // ProMemory.timer2.Dispose();//停止计时器 - - //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; - - if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) - ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); - - //匹配成功 - if (iMatchNumber > 0) - { - string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId - if (ProMemory.formType == "1") - Form1.GetInstance().Success(personId); - else if (ProMemory.formType == "2") - Form2.GetInstance().Success(personId); - //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); - Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); - } - //匹配失败 - else - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); - - if (ProMemory.formType == "1") - Form1.GetInstance().failure(); - else if (ProMemory.formType == "2") - Form2.GetInstance().failure(); - //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); - Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); - } - - ProMemory.jobRuning = false; - ProMemory.cameraController.ContinuousShot_TriggerOff(); - - } - catch (Exception ex) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); - } - } - - - } -} \ No newline at end of file diff --git a/irisRefactor/IrisThread/ImageQualityAssessTh.cs b/irisRefactor/IrisThread/ImageQualityAssessTh.cs index b21ca9d..0650491 100644 --- a/irisRefactor/IrisThread/ImageQualityAssessTh.cs +++ b/irisRefactor/IrisThread/ImageQualityAssessTh.cs @@ -105,7 +105,7 @@ ProMemory.irisConfig.Key_Identify = 1; ProMemory.irisConfig.IdentifyThreadRun = true; - Thread m_IdentifyThread = new Thread(IdentiyfTh.GetInstance().Identify); + Thread m_IdentifyThread = new Thread(IdentifyTh.GetInstance.Identify); m_IdentifyThread.Name = "Identify"; m_IdentifyThread.Start(); } @@ -136,7 +136,7 @@ if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) { Form1.GetInstance().obtainTemp(); - Form1.GetInstance().failure(); + Form1.GetInstance().Failure(); } else { Form2.GetInstance().failure(); diff --git a/irisRefactor/IrisThread/PreIdentifyTh.cs b/irisRefactor/IrisThread/PreIdentifyTh.cs index 90d4848..1ed042a 100644 --- a/irisRefactor/IrisThread/PreIdentifyTh.cs +++ b/irisRefactor/IrisThread/PreIdentifyTh.cs @@ -1,5 +1,4 @@ using irisHelper; -using irisRefactor.FrmService; using System; using System.Diagnostics; using System.Reflection; @@ -15,41 +14,39 @@ */ class PreIdentifyTh { - private PreIdentifyTh() - { + private PreIdentifyTh() { } - } - - private static readonly PreIdentifyTh _preIdentifyTh = new PreIdentifyTh(); + private static readonly PreIdentifyTh preIdentifyTh = new PreIdentifyTh(); - public static PreIdentifyTh GetInstance { get => _preIdentifyTh; } + public static PreIdentifyTh GetInstance { get => preIdentifyTh; } public void FindEyes() { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify -- FindEyes"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify Thread Started"); - ProMemory.Tag_SleepTimer = 0; + //ProMemory.Tag_SleepTimer = 0; + //ProMemory.irisConfig.EyeFinderThreadRun = true; // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); - try + // 没有在休眠中;没有数据同步中 + while (ProMemory.isWait == false && ProMemory.isSyning == false) { - // 条件:找眼线程在运行中;休眠线程标志为0;不在数据同步;连续未找到眼睛数小于100 - while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning && ProMemory.identifyConfig.Count_NoEyeLast <= 100) + // 没有正在执行的找眼、识别线程 + if (ProMemory.identifyConfig.FlagFindingEye == false) { - //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } - if (ProMemory.irisConfig.FaceBuffer != null) + try { unsafe { @@ -69,20 +66,35 @@ sw.Restart(); mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 sw.Stop(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "找眼[" + mark + "]:" + sw.ElapsedMilliseconds); int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; - // 找到1个或者2个眼睛 if (mark == 1 || mark == 2) { // 1.持续没有找到眼的计数器清零 - ProMemory.identifyConfig.Count_NoEyeLast = 0; + ProMemory.identifyConfig.CountNoEyeLast = 0; - // 2.黄灯闪烁 - //ProMemory.IoControllService.setYellowFlash(true); - //Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); - //flashThrd.Start(); + ProMemory.identifyConfig.FlagFoundEye = true; + + // 一次识别过程中首次找到眼,标记开始一次新的识别 + if (ProMemory.identifyConfig.IdentifyTaskId == "") + { + ProMemory.identifyConfig.IdentifyTaskId = DateTime.Now.ToString("yyyyMMddHHmmss"); + + // 2.黄灯闪烁 + ProMemory.IoControllService.setYellowFlash(true); + Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + flashThrd.Start(); + + // 开启识别线程 + ProMemory.irisConfig.Key_Identify = 1; + ProMemory.irisConfig.IdentifyThreadRun = true; + + // 初始化识别线程 + Thread thIdentify = new Thread(IdentifyTh.GetInstance.Identify); + thIdentify.Start(); + } // 3.质量评估 int score = 0; @@ -104,7 +116,7 @@ sw.Restart(); score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 sw.Stop(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次质量评估操作[" + score + "]:" + sw.ElapsedMilliseconds); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "质量评估[" + score + "]:" + sw.ElapsedMilliseconds); } } } @@ -128,74 +140,200 @@ } } - - if (ProMemory.irisConfig.Key_Identify == 0) - { - ProMemory.irisConfig.Key_Identify = 1; - ProMemory.irisConfig.IdentifyThreadRun = true; - Thread m_IdentifyThread = new Thread(IdentiyfTh.GetInstance().Identify); - m_IdentifyThread.Name = "Identify"; - m_IdentifyThread.Start(); - } - + //if (ProMemory.irisConfig.Key_Identify == 0) + //{ + // ProMemory.irisConfig.Key_Identify = 1; + + // ProMemory.irisConfig.IdentifyThreadRun = true; + + // // 初始化识别线程 + // Thread thIdentify = new Thread(IdentifyTh.GetInstance.Identify); + // thIdentify.Start(); + //} + } Marshal.FreeHGlobal(ptrIrisFace); } else { - ProMemory.identifyConfig.Count_NoEyeLast++; + ProMemory.identifyConfig.CountNoEyeLast++; } } - - Marshal.FreeHGlobal(ptrFace); } - } - - lock (ProMemory.irisConfig.Q2) + } + catch (Exception ex) { - if (ProMemory.irisConfig.Q2.Count >= 30) - { - ProMemory.irisConfig.Q2.Clear(); //手动控制堆栈容量 - } - } - - lock (ProMemory.irisConfig.Q3) - { - if (ProMemory.irisConfig.Q3.Count >= 30) - { - ProMemory.irisConfig.Q3.Clear(); //手动控制堆栈容量 - } - } - } - } - - //if (ProMemory.Tag_SleepTimer == 1) //待机时间到,仍未找到眼睛 - if (ProMemory.identifyConfig.Count_NoEyeLast > 100) - { - if (ProMemory.m_bGrabbing) - { - if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 - { - if (ProMemory.formType == "1") - Form1.GetInstance().ReInitializeToSleep(); - else if (ProMemory.formType == "2") - Form2.GetInstance().ReInitializeToSleep(); - Thread.Sleep(200); - ProMemory.cameraController.ContinuousShot_TriggerOn(); - } - else //已再次触发,继续下一轮识别 - { - ProMemory.cameraController.ContinuousShot_TriggerOff(); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); } } } } - catch (Exception ex) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); - } + + //try + //{ + // // 条件:找眼线程在运行中;休眠线程标志为0;不在数据同步;连续未找到眼睛数小于100 + // while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning && ProMemory.identifyConfig.CountNoEyeLast <= 100) + // { + // //M++; + // if (ProMemory.irisConfig.QueueFace.Count > 0) + // { + // lock (ProMemory.irisConfig.QueueFace) + // { + // if (ProMemory.irisConfig.QueueFace.Count > 0) + // { + // ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); + // } + // } + + // if (ProMemory.irisConfig.FaceBuffer != null) + // { + // unsafe + // { + // // 申请内存,复制内存 + // IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); + // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); + + // // mark = 找到的眼睛数量 + // int mark; + // // 左右眼睛的定位参数:x,y,r + // int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; + + // fixed (int* pos = &posvec[0]) + // { + // int* ptrPos = pos; + + // sw.Restart(); + // mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 + // sw.Stop(); + // LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + + // int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; + + // // 找到1个或者2个眼睛 + // if (mark == 1 || mark == 2) + // { + // // 1.持续没有找到眼的计数器清零 + // ProMemory.identifyConfig.CountNoEyeLast = 0; + + // // 2.黄灯闪烁 + // //ProMemory.IoControllService.setYellowFlash(true); + // //Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + // //flashThrd.Start(); + + // // 3.质量评估 + // int score = 0; + // Byte[] irisBytesL = new byte[640 * 480]; + // Byte[] irisBytesR = new byte[640 * 480]; + + // IntPtr ptrIrisFace = Marshal.AllocHGlobal(1280 * 960); + // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrIrisFace, 1280 * 960); + + // unsafe + // { + // fixed (byte* irisL = &irisBytesL[0]) + // { + // fixed (byte* irisR = &irisBytesR[0]) + // { + // byte* ptrIrisL = irisL; + // byte* ptrIrisR = irisR; + + // sw.Restart(); + // score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 + // sw.Stop(); + // LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次质量评估操作[" + score + "]:" + sw.ElapsedMilliseconds); + // } + // } + // } + + + // if (score > 0) + // { + // if (score == 1) + // { + // lock (ProMemory.irisConfig.Q4) + // { + // ProMemory.irisConfig.Q4.Push(irisBytesL); + // } + // } + // else if (score == 2) + // { + // lock (ProMemory.irisConfig.Q4) + // { + // ProMemory.irisConfig.Q4.Push(irisBytesL); + // ProMemory.irisConfig.Q4.Push(irisBytesR); + // } + // } + + + // if (ProMemory.irisConfig.Key_Identify == 0) + // { + // ProMemory.irisConfig.Key_Identify = 1; + + // ProMemory.irisConfig.IdentifyThreadRun = true; + // //Thread m_IdentifyThread = new Thread(IdentifyTh.GetInstance().Identify); + // //m_IdentifyThread.Name = "Identify"; + // //m_IdentifyThread.Start(); + // } + + // } + + // Marshal.FreeHGlobal(ptrIrisFace); + // } + // else + // { + // ProMemory.identifyConfig.CountNoEyeLast++; + // } + // } + + // Marshal.FreeHGlobal(ptrFace); + // } + // } + + // lock (ProMemory.irisConfig.Q2) + // { + // if (ProMemory.irisConfig.Q2.Count >= 30) + // { + // ProMemory.irisConfig.Q2.Clear(); //手动控制堆栈容量 + // } + // } + + // lock (ProMemory.irisConfig.Q3) + // { + // if (ProMemory.irisConfig.Q3.Count >= 30) + // { + // ProMemory.irisConfig.Q3.Clear(); //手动控制堆栈容量 + // } + // } + // } + // } + + // //if (ProMemory.Tag_SleepTimer == 1) //待机时间到,仍未找到眼睛 + // if (ProMemory.identifyConfig.CountNoEyeLast > 100) + // { + // if (ProMemory.m_bGrabbing) + // { + // if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 + // { + // if (ProMemory.formType == "1") + // Form1.GetInstance().ReInitializeToSleep(); + // else if (ProMemory.formType == "2") + // Form2.GetInstance().ReInitializeToSleep(); + // Thread.Sleep(200); + // ProMemory.cameraController.ContinuousShot_TriggerOn(); + // } + // else //已再次触发,继续下一轮识别 + // { + // ProMemory.cameraController.ContinuousShot_TriggerOff(); + // } + // } + // } + //} + //catch (Exception ex) + //{ + // LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); + //} } } } diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index e4ddfe3..c5571c7 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -109,9 +109,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) @@ -173,9 +173,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index 40e4ec9..ab18cb6 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -28,9 +28,9 @@ return _cameraController; } - public void timerCamera_Tick(Object sender, EventArgs myEventArgs) + public void TimerCamera_Tick(Object sender, EventArgs myEventArgs) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); //准备相机列表 uint numDevices = 0; numDevices = DeviceListAcq(); @@ -38,9 +38,9 @@ if (numDevices == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("没有检测到相机!", "提示"); + MessageBox.Show("[timerCamera_Tick]没有检测到相机!", "提示"); else - MessageBox.Show("No Device!", "提示"); + MessageBox.Show("[timerCamera_Tick]No Device!", "提示"); return; } @@ -71,7 +71,7 @@ nRet = CameraOperator.EnumDevices(MyCamera.MV_USB_DEVICE, ref ProMemory.m_pDeviceList); if (0 != nRet) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); return 0; } @@ -86,9 +86,9 @@ if (ProMemory.m_pDeviceList.nDeviceNum == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("无设备!", "提示"); + MessageBox.Show("[ConnectCamera]连接相机时无设备!", "提示"); else - MessageBox.Show("No Device!", "Meaasge"); + MessageBox.Show("[ConnectCamera]No Device!", "Meaasge"); return; } @@ -104,9 +104,9 @@ if (MyCamera.MV_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("相机打开失败!","提示"); + MessageBox.Show("[ConnectCamera]相机打开失败!", "提示"); else - MessageBox.Show("No Device!", "Message"); + MessageBox.Show("[ConnectCamera]No Device!", "Message"); return; } @@ -115,44 +115,48 @@ m_pOperator.SetEnumValue("TriggerMode", 0); //注册回调函数 - ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance().SaveImage); + ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance.SaveImage); nRet = m_pOperator.RegisterImageCallBack(ProMemory.ImageCallback, IntPtr.Zero); if (CameraOperator.CO_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("注册回调失败!", "提示"); + MessageBox.Show("[ConnectCamera]注册回调失败!", "提示"); else - MessageBox.Show("regist failed", "message"); + MessageBox.Show("[ConnectCamera]regist failed", "message"); } - ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(getException); + ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(GetException); int exNet = m_pOperator.RegisterExceptionCallBack(ProMemory.CallBackFunc, IntPtr.Zero); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); MessageBox.Show("ConnectCamera:" + e.Message); } } - private void getException(uint nMsgType, IntPtr pUser) + private void GetException(uint nMsgType, IntPtr pUser) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); ShutdownHelper.Restart(); //LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save success!"); } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed" + ex.Message); } } + /** + * 待机 + * 持续监测感应模块,有外触发到来则重新开始工作 + */ public void ContinuousShot_TriggerOn() { try @@ -160,16 +164,20 @@ ProMemory.isWait = true; ProMemory.jobRuning = false; - stopGrabbing(); + // 先停止取流 + StopGrabbing(); //GC.Collect(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + + // 循环检测是否有外触发,重新开始工作 while (ProMemory.isWait) { - if (ProMemory.IoControllService.getSensorVal() == 1) //通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + // 通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + if (ProMemory.IoControllService.getSensorVal() == 1) { - //外触发到来,开始采集 - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); + // 外触发到来,开始采集 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); ProMemory.IoControllService.YellowOn(); ProMemory.isWait = false; Grabbing(); @@ -178,28 +186,30 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); MessageBox.Show("ContinuousShot_TriggerOn:" + e.Message); } } - //普通模式开始采集 + /** + * 正常工作 + */ public void ContinuousShot_TriggerOff() { try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来当前线程:" + Thread.CurrentThread.Name); - //重置界面 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来,当前线程:" + Thread.CurrentThread.Name); + + // 重置界面 if (ProMemory.formType == "1") Form1.GetInstance().ReInitialize(); else if (ProMemory.formType == "2") Form2.GetInstance().ReInitialize(); ProMemory.IoControllService.YellowOn(); Grabbing(); - } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); } } @@ -216,7 +226,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); MessageBox.Show("CloseCamera:" + e.Message); } } @@ -226,7 +236,7 @@ { if (ProMemory.isSyning) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中,暂停取流"); return; } //ProMemory.jobRuning = true; @@ -241,7 +251,9 @@ { nRet = m_pOperator.StopGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "停止取流失败;"; + } else { msg += "停止取流成功;"; @@ -251,7 +263,9 @@ nRet = m_pOperator.StartGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "开始取流失败;"; + } else { msg += "开始取流成功;"; @@ -260,32 +274,48 @@ } } + // 视频画面显示在界面上 int playRet = 0; - if (ProMemory.formType == "1") m_pOperator.Display(Form1.GetInstance().picLive.Handle); - else if (ProMemory.formType == "2") m_pOperator.Display(Form2.GetInstance().picLive.Handle); + if (ProMemory.formType == "1") + { + m_pOperator.Display(Form1.GetInstance().picLive.Handle); + } + else if (ProMemory.formType == "2") + { + m_pOperator.Display(Form2.GetInstance().picLive.Handle); + } if (MyCamera.MV_OK != playRet) - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + } - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 ProMemory.findingEyes = true; + ProMemory.identifyConfig.FlagWorking = true; } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); } finally { } } - private void stopGrabbing() + private void StopGrabbing() { - int nRet = m_pOperator.StopGrabbing(); - if (ProMemory.formType == "1") Form1.GetInstance().picLive.Image = null; - else if (ProMemory.formType == "2") Form2.GetInstance().picLive.Image = null; + m_pOperator.StopGrabbing(); + if (ProMemory.formType == "1") + { + Form1.GetInstance().picLive.Image = null; + } + else if (ProMemory.formType == "2") + { + Form2.GetInstance().picLive.Image = null; + } ProMemory.m_bGrabbing = false; } diff --git a/irisRefactor/IrisThread/FindEyesTh.cs b/irisRefactor/IrisThread/FindEyesTh.cs index baa4137..aaee4b3 100644 --- a/irisRefactor/IrisThread/FindEyesTh.cs +++ b/irisRefactor/IrisThread/FindEyesTh.cs @@ -35,13 +35,13 @@ while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning) { //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs new file mode 100644 index 0000000..32e9240 --- /dev/null +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -0,0 +1,104 @@ +using irisHelper; +using irisRefactor.FrmService; +using System; +using System.Diagnostics; +using System.Reflection; +using System.Threading; + +namespace irisRefactor.IrisThread +{ + public class IdentifyTh + { + private static readonly IdentifyTh identiyfTh = new IdentifyTh(); + private IdentifyTh() { } + public static IdentifyTh GetInstance + { + get => identiyfTh; + } + + public void Identify() + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); + ProMemory.irisConfig.IdentifyAccess = true; + + // 用于计算操作耗时 + Stopwatch sw = new Stopwatch(); + + try + { + int iMatchNumber = 0; + float iHammingDistance = 1; + int iLeftRight = 0; + + while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && + ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + { + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); + if (ProMemory.irisConfig.Q4.Count > 0) + { + lock (ProMemory.irisConfig.Q4) + { + if (ProMemory.irisConfig.Q4.Count > 0) + { + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + } + } + if (ProMemory.irisConfig.QualifiedIrisBuffer != null) + { + //加载匹配列表 + sw.Restart(); + iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "识别[" + iMatchNumber + "]:" + sw.ElapsedMilliseconds); + } + } + } + + // ProMemory.timer2.Dispose();//停止计时器 + + + //跳出循环,条件是时间到、匹配成功或者正在关闭程序 + ProMemory.irisConfig.AssessThreadRun = false; + ProMemory.irisConfig.EyeFinderThreadRun = false; + + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + //匹配成功 + if (iMatchNumber > 0) + { + string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId + if (ProMemory.formType == "1") + Form1.GetInstance().Success(personId); + else if (ProMemory.formType == "2") + Form2.GetInstance().Success(personId); + //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); + Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); + } + //匹配失败 + else + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().failure(); + //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + } + + + ProMemory.jobRuning = false; + ProMemory.cameraController.ContinuousShot_TriggerOff(); + + } + catch (Exception ex) + { + LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); + } + } + + + } +} \ No newline at end of file diff --git a/irisRefactor/IrisThread/IdentiyfTh.cs b/irisRefactor/IrisThread/IdentiyfTh.cs deleted file mode 100644 index 99878de..0000000 --- a/irisRefactor/IrisThread/IdentiyfTh.cs +++ /dev/null @@ -1,100 +0,0 @@ -using irisHelper; -using irisRefactor.FrmService; -using System; -using System.Reflection; -using System.Threading; - -namespace irisRefactor.IrisThread -{ - public class IdentiyfTh - { - private static IdentiyfTh _identiyfTh = null; - private IdentiyfTh() { - } - public static IdentiyfTh GetInstance() - { - if (_identiyfTh == null) - _identiyfTh = new IdentiyfTh(); - - return _identiyfTh; - - } - - public void Identify() - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify"); - ProMemory.irisConfig.IdentifyAccess = true; - - try - { - int iMatchNumber = 0; - float iHammingDistance = 1; - int iLeftRight = 0; - - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) - { - lock (ProMemory.irisConfig.Q4) - { - if (ProMemory.irisConfig.Q4.Count > 0) - { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); - } - } - if (ProMemory.irisConfig.QualifiedIrisBuffer != null) - { - //加载匹配列表 - iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); - } - } - } - - // ProMemory.timer2.Dispose();//停止计时器 - - //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; - - if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) - ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); - - //匹配成功 - if (iMatchNumber > 0) - { - string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId - if (ProMemory.formType == "1") - Form1.GetInstance().Success(personId); - else if (ProMemory.formType == "2") - Form2.GetInstance().Success(personId); - //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); - Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); - } - //匹配失败 - else - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); - - if (ProMemory.formType == "1") - Form1.GetInstance().failure(); - else if (ProMemory.formType == "2") - Form2.GetInstance().failure(); - //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); - Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); - } - - ProMemory.jobRuning = false; - ProMemory.cameraController.ContinuousShot_TriggerOff(); - - } - catch (Exception ex) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); - } - } - - - } -} \ No newline at end of file diff --git a/irisRefactor/IrisThread/ImageQualityAssessTh.cs b/irisRefactor/IrisThread/ImageQualityAssessTh.cs index b21ca9d..0650491 100644 --- a/irisRefactor/IrisThread/ImageQualityAssessTh.cs +++ b/irisRefactor/IrisThread/ImageQualityAssessTh.cs @@ -105,7 +105,7 @@ ProMemory.irisConfig.Key_Identify = 1; ProMemory.irisConfig.IdentifyThreadRun = true; - Thread m_IdentifyThread = new Thread(IdentiyfTh.GetInstance().Identify); + Thread m_IdentifyThread = new Thread(IdentifyTh.GetInstance.Identify); m_IdentifyThread.Name = "Identify"; m_IdentifyThread.Start(); } @@ -136,7 +136,7 @@ if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) { Form1.GetInstance().obtainTemp(); - Form1.GetInstance().failure(); + Form1.GetInstance().Failure(); } else { Form2.GetInstance().failure(); diff --git a/irisRefactor/IrisThread/PreIdentifyTh.cs b/irisRefactor/IrisThread/PreIdentifyTh.cs index 90d4848..1ed042a 100644 --- a/irisRefactor/IrisThread/PreIdentifyTh.cs +++ b/irisRefactor/IrisThread/PreIdentifyTh.cs @@ -1,5 +1,4 @@ using irisHelper; -using irisRefactor.FrmService; using System; using System.Diagnostics; using System.Reflection; @@ -15,41 +14,39 @@ */ class PreIdentifyTh { - private PreIdentifyTh() - { + private PreIdentifyTh() { } - } - - private static readonly PreIdentifyTh _preIdentifyTh = new PreIdentifyTh(); + private static readonly PreIdentifyTh preIdentifyTh = new PreIdentifyTh(); - public static PreIdentifyTh GetInstance { get => _preIdentifyTh; } + public static PreIdentifyTh GetInstance { get => preIdentifyTh; } public void FindEyes() { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify -- FindEyes"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify Thread Started"); - ProMemory.Tag_SleepTimer = 0; + //ProMemory.Tag_SleepTimer = 0; + //ProMemory.irisConfig.EyeFinderThreadRun = true; // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); - try + // 没有在休眠中;没有数据同步中 + while (ProMemory.isWait == false && ProMemory.isSyning == false) { - // 条件:找眼线程在运行中;休眠线程标志为0;不在数据同步;连续未找到眼睛数小于100 - while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning && ProMemory.identifyConfig.Count_NoEyeLast <= 100) + // 没有正在执行的找眼、识别线程 + if (ProMemory.identifyConfig.FlagFindingEye == false) { - //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } - if (ProMemory.irisConfig.FaceBuffer != null) + try { unsafe { @@ -69,20 +66,35 @@ sw.Restart(); mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 sw.Stop(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "找眼[" + mark + "]:" + sw.ElapsedMilliseconds); int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; - // 找到1个或者2个眼睛 if (mark == 1 || mark == 2) { // 1.持续没有找到眼的计数器清零 - ProMemory.identifyConfig.Count_NoEyeLast = 0; + ProMemory.identifyConfig.CountNoEyeLast = 0; - // 2.黄灯闪烁 - //ProMemory.IoControllService.setYellowFlash(true); - //Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); - //flashThrd.Start(); + ProMemory.identifyConfig.FlagFoundEye = true; + + // 一次识别过程中首次找到眼,标记开始一次新的识别 + if (ProMemory.identifyConfig.IdentifyTaskId == "") + { + ProMemory.identifyConfig.IdentifyTaskId = DateTime.Now.ToString("yyyyMMddHHmmss"); + + // 2.黄灯闪烁 + ProMemory.IoControllService.setYellowFlash(true); + Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + flashThrd.Start(); + + // 开启识别线程 + ProMemory.irisConfig.Key_Identify = 1; + ProMemory.irisConfig.IdentifyThreadRun = true; + + // 初始化识别线程 + Thread thIdentify = new Thread(IdentifyTh.GetInstance.Identify); + thIdentify.Start(); + } // 3.质量评估 int score = 0; @@ -104,7 +116,7 @@ sw.Restart(); score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 sw.Stop(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次质量评估操作[" + score + "]:" + sw.ElapsedMilliseconds); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "质量评估[" + score + "]:" + sw.ElapsedMilliseconds); } } } @@ -128,74 +140,200 @@ } } - - if (ProMemory.irisConfig.Key_Identify == 0) - { - ProMemory.irisConfig.Key_Identify = 1; - ProMemory.irisConfig.IdentifyThreadRun = true; - Thread m_IdentifyThread = new Thread(IdentiyfTh.GetInstance().Identify); - m_IdentifyThread.Name = "Identify"; - m_IdentifyThread.Start(); - } - + //if (ProMemory.irisConfig.Key_Identify == 0) + //{ + // ProMemory.irisConfig.Key_Identify = 1; + + // ProMemory.irisConfig.IdentifyThreadRun = true; + + // // 初始化识别线程 + // Thread thIdentify = new Thread(IdentifyTh.GetInstance.Identify); + // thIdentify.Start(); + //} + } Marshal.FreeHGlobal(ptrIrisFace); } else { - ProMemory.identifyConfig.Count_NoEyeLast++; + ProMemory.identifyConfig.CountNoEyeLast++; } } - - Marshal.FreeHGlobal(ptrFace); } - } - - lock (ProMemory.irisConfig.Q2) + } + catch (Exception ex) { - if (ProMemory.irisConfig.Q2.Count >= 30) - { - ProMemory.irisConfig.Q2.Clear(); //手动控制堆栈容量 - } - } - - lock (ProMemory.irisConfig.Q3) - { - if (ProMemory.irisConfig.Q3.Count >= 30) - { - ProMemory.irisConfig.Q3.Clear(); //手动控制堆栈容量 - } - } - } - } - - //if (ProMemory.Tag_SleepTimer == 1) //待机时间到,仍未找到眼睛 - if (ProMemory.identifyConfig.Count_NoEyeLast > 100) - { - if (ProMemory.m_bGrabbing) - { - if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 - { - if (ProMemory.formType == "1") - Form1.GetInstance().ReInitializeToSleep(); - else if (ProMemory.formType == "2") - Form2.GetInstance().ReInitializeToSleep(); - Thread.Sleep(200); - ProMemory.cameraController.ContinuousShot_TriggerOn(); - } - else //已再次触发,继续下一轮识别 - { - ProMemory.cameraController.ContinuousShot_TriggerOff(); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); } } } } - catch (Exception ex) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); - } + + //try + //{ + // // 条件:找眼线程在运行中;休眠线程标志为0;不在数据同步;连续未找到眼睛数小于100 + // while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning && ProMemory.identifyConfig.CountNoEyeLast <= 100) + // { + // //M++; + // if (ProMemory.irisConfig.QueueFace.Count > 0) + // { + // lock (ProMemory.irisConfig.QueueFace) + // { + // if (ProMemory.irisConfig.QueueFace.Count > 0) + // { + // ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); + // } + // } + + // if (ProMemory.irisConfig.FaceBuffer != null) + // { + // unsafe + // { + // // 申请内存,复制内存 + // IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); + // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); + + // // mark = 找到的眼睛数量 + // int mark; + // // 左右眼睛的定位参数:x,y,r + // int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; + + // fixed (int* pos = &posvec[0]) + // { + // int* ptrPos = pos; + + // sw.Restart(); + // mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 + // sw.Stop(); + // LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + + // int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; + + // // 找到1个或者2个眼睛 + // if (mark == 1 || mark == 2) + // { + // // 1.持续没有找到眼的计数器清零 + // ProMemory.identifyConfig.CountNoEyeLast = 0; + + // // 2.黄灯闪烁 + // //ProMemory.IoControllService.setYellowFlash(true); + // //Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + // //flashThrd.Start(); + + // // 3.质量评估 + // int score = 0; + // Byte[] irisBytesL = new byte[640 * 480]; + // Byte[] irisBytesR = new byte[640 * 480]; + + // IntPtr ptrIrisFace = Marshal.AllocHGlobal(1280 * 960); + // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrIrisFace, 1280 * 960); + + // unsafe + // { + // fixed (byte* irisL = &irisBytesL[0]) + // { + // fixed (byte* irisR = &irisBytesR[0]) + // { + // byte* ptrIrisL = irisL; + // byte* ptrIrisR = irisR; + + // sw.Restart(); + // score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 + // sw.Stop(); + // LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次质量评估操作[" + score + "]:" + sw.ElapsedMilliseconds); + // } + // } + // } + + + // if (score > 0) + // { + // if (score == 1) + // { + // lock (ProMemory.irisConfig.Q4) + // { + // ProMemory.irisConfig.Q4.Push(irisBytesL); + // } + // } + // else if (score == 2) + // { + // lock (ProMemory.irisConfig.Q4) + // { + // ProMemory.irisConfig.Q4.Push(irisBytesL); + // ProMemory.irisConfig.Q4.Push(irisBytesR); + // } + // } + + + // if (ProMemory.irisConfig.Key_Identify == 0) + // { + // ProMemory.irisConfig.Key_Identify = 1; + + // ProMemory.irisConfig.IdentifyThreadRun = true; + // //Thread m_IdentifyThread = new Thread(IdentifyTh.GetInstance().Identify); + // //m_IdentifyThread.Name = "Identify"; + // //m_IdentifyThread.Start(); + // } + + // } + + // Marshal.FreeHGlobal(ptrIrisFace); + // } + // else + // { + // ProMemory.identifyConfig.CountNoEyeLast++; + // } + // } + + // Marshal.FreeHGlobal(ptrFace); + // } + // } + + // lock (ProMemory.irisConfig.Q2) + // { + // if (ProMemory.irisConfig.Q2.Count >= 30) + // { + // ProMemory.irisConfig.Q2.Clear(); //手动控制堆栈容量 + // } + // } + + // lock (ProMemory.irisConfig.Q3) + // { + // if (ProMemory.irisConfig.Q3.Count >= 30) + // { + // ProMemory.irisConfig.Q3.Clear(); //手动控制堆栈容量 + // } + // } + // } + // } + + // //if (ProMemory.Tag_SleepTimer == 1) //待机时间到,仍未找到眼睛 + // if (ProMemory.identifyConfig.CountNoEyeLast > 100) + // { + // if (ProMemory.m_bGrabbing) + // { + // if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 + // { + // if (ProMemory.formType == "1") + // Form1.GetInstance().ReInitializeToSleep(); + // else if (ProMemory.formType == "2") + // Form2.GetInstance().ReInitializeToSleep(); + // Thread.Sleep(200); + // ProMemory.cameraController.ContinuousShot_TriggerOn(); + // } + // else //已再次触发,继续下一轮识别 + // { + // ProMemory.cameraController.ContinuousShot_TriggerOff(); + // } + // } + // } + //} + //catch (Exception ex) + //{ + // LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); + //} } } } diff --git a/irisRefactor/IrisThread/SaveImageTh.cs b/irisRefactor/IrisThread/SaveImageTh.cs index ab978b4..f0ec820 100644 --- a/irisRefactor/IrisThread/SaveImageTh.cs +++ b/irisRefactor/IrisThread/SaveImageTh.cs @@ -13,14 +13,12 @@ public class SaveImageTh { - private static SaveImageTh _saveImageTh = null; + private static readonly SaveImageTh saveImageTh = new SaveImageTh(); private SaveImageTh() { } - public static SaveImageTh GetInstance() + public static SaveImageTh GetInstance { - if (_saveImageTh == null) - _saveImageTh = new SaveImageTh(); + get => saveImageTh; - return _saveImageTh; } //图象采集回调函数 //pData [out] 保存图像数据的缓存地址 @@ -30,7 +28,7 @@ { try { - //1.取出采集到的图像 + // 1.取出采集到的图像 int ylength = pFrameInfo.nWidth * pFrameInfo.nHeight; byte[] imgBytes = new byte[ylength]; Marshal.Copy(pData, imgBytes, 0, ylength); @@ -38,47 +36,26 @@ if (image == null) return; - //2.对图像进行人眼搜索处理 - // 条件:未处在待机状态;正在取流过程;没有进行数据同步 - if (ProMemory.isWait == false && ProMemory.findingEyes && !ProMemory.isSyning) + //2.将图像存入堆栈中 + // 条件:未在待机状态 + if (ProMemory.isWait == false) { + // 开启工作线程 + ProMemory.identifyConfig.FlagWorking = true; + try { - //将图片放入堆栈1 - lock (ProMemory.irisConfig.Q1) + // 将图片放入堆栈1 + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Push(imgBytes); - // LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Q1.Push:" + ProMemory.irisConfig.Q1.Count); + ProMemory.irisConfig.QueueFace.Push(imgBytes); + // LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q1.Push:" + ProMemory.irisConfig.QueueFace.Count); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程push q1 :" + ee); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程push q1 :" + ee); } - - // 条件:找眼线程未开启;未处于待机状态 - if (ProMemory.irisConfig.Key_FindEyes == 0 && !ProMemory.isWait) - { - // 标记进入找眼线程 - /* - ProMemory.irisConfig.Key_FindEyes = 1; - ProMemory.irisConfig.EyeFinderThreadRun = true; - - // 新建线程进行找眼 - Thread m_EyeFinderThread = new Thread(FindEyesTh.GetInstance().FindEyes); - m_EyeFinderThread.Name = "FindEyes"; - m_EyeFinderThread.Start(); - */ - - // 开启工作线程 - ProMemory.identifyConfig.Flag_Working = 1; - ProMemory.irisConfig.Key_FindEyes = 1; - ProMemory.irisConfig.EyeFinderThreadRun = true; - Thread th_PreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes); - th_PreIdentify.Name = "FindEyes"; - th_PreIdentify.Start(); - } - } //释放内存 @@ -86,22 +63,22 @@ //image = null; try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count >= 30) + if (ProMemory.irisConfig.QueueFace.Count >= 30) { - ProMemory.irisConfig.Q1.Clear(); //手动控制堆栈容量 + ProMemory.irisConfig.QueueFace.Clear(); //手动控制堆栈容量 } } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程clear q1 :" + ee); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程clear q1 :" + ee); } } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "图像采集线程CatchError:" + ex); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "图像采集线程CatchError:" + ex); } } diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index e4ddfe3..c5571c7 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -109,9 +109,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) @@ -173,9 +173,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index 40e4ec9..ab18cb6 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -28,9 +28,9 @@ return _cameraController; } - public void timerCamera_Tick(Object sender, EventArgs myEventArgs) + public void TimerCamera_Tick(Object sender, EventArgs myEventArgs) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); //准备相机列表 uint numDevices = 0; numDevices = DeviceListAcq(); @@ -38,9 +38,9 @@ if (numDevices == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("没有检测到相机!", "提示"); + MessageBox.Show("[timerCamera_Tick]没有检测到相机!", "提示"); else - MessageBox.Show("No Device!", "提示"); + MessageBox.Show("[timerCamera_Tick]No Device!", "提示"); return; } @@ -71,7 +71,7 @@ nRet = CameraOperator.EnumDevices(MyCamera.MV_USB_DEVICE, ref ProMemory.m_pDeviceList); if (0 != nRet) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); return 0; } @@ -86,9 +86,9 @@ if (ProMemory.m_pDeviceList.nDeviceNum == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("无设备!", "提示"); + MessageBox.Show("[ConnectCamera]连接相机时无设备!", "提示"); else - MessageBox.Show("No Device!", "Meaasge"); + MessageBox.Show("[ConnectCamera]No Device!", "Meaasge"); return; } @@ -104,9 +104,9 @@ if (MyCamera.MV_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("相机打开失败!","提示"); + MessageBox.Show("[ConnectCamera]相机打开失败!", "提示"); else - MessageBox.Show("No Device!", "Message"); + MessageBox.Show("[ConnectCamera]No Device!", "Message"); return; } @@ -115,44 +115,48 @@ m_pOperator.SetEnumValue("TriggerMode", 0); //注册回调函数 - ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance().SaveImage); + ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance.SaveImage); nRet = m_pOperator.RegisterImageCallBack(ProMemory.ImageCallback, IntPtr.Zero); if (CameraOperator.CO_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("注册回调失败!", "提示"); + MessageBox.Show("[ConnectCamera]注册回调失败!", "提示"); else - MessageBox.Show("regist failed", "message"); + MessageBox.Show("[ConnectCamera]regist failed", "message"); } - ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(getException); + ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(GetException); int exNet = m_pOperator.RegisterExceptionCallBack(ProMemory.CallBackFunc, IntPtr.Zero); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); MessageBox.Show("ConnectCamera:" + e.Message); } } - private void getException(uint nMsgType, IntPtr pUser) + private void GetException(uint nMsgType, IntPtr pUser) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); ShutdownHelper.Restart(); //LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save success!"); } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed" + ex.Message); } } + /** + * 待机 + * 持续监测感应模块,有外触发到来则重新开始工作 + */ public void ContinuousShot_TriggerOn() { try @@ -160,16 +164,20 @@ ProMemory.isWait = true; ProMemory.jobRuning = false; - stopGrabbing(); + // 先停止取流 + StopGrabbing(); //GC.Collect(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + + // 循环检测是否有外触发,重新开始工作 while (ProMemory.isWait) { - if (ProMemory.IoControllService.getSensorVal() == 1) //通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + // 通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + if (ProMemory.IoControllService.getSensorVal() == 1) { - //外触发到来,开始采集 - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); + // 外触发到来,开始采集 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); ProMemory.IoControllService.YellowOn(); ProMemory.isWait = false; Grabbing(); @@ -178,28 +186,30 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); MessageBox.Show("ContinuousShot_TriggerOn:" + e.Message); } } - //普通模式开始采集 + /** + * 正常工作 + */ public void ContinuousShot_TriggerOff() { try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来当前线程:" + Thread.CurrentThread.Name); - //重置界面 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来,当前线程:" + Thread.CurrentThread.Name); + + // 重置界面 if (ProMemory.formType == "1") Form1.GetInstance().ReInitialize(); else if (ProMemory.formType == "2") Form2.GetInstance().ReInitialize(); ProMemory.IoControllService.YellowOn(); Grabbing(); - } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); } } @@ -216,7 +226,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); MessageBox.Show("CloseCamera:" + e.Message); } } @@ -226,7 +236,7 @@ { if (ProMemory.isSyning) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中,暂停取流"); return; } //ProMemory.jobRuning = true; @@ -241,7 +251,9 @@ { nRet = m_pOperator.StopGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "停止取流失败;"; + } else { msg += "停止取流成功;"; @@ -251,7 +263,9 @@ nRet = m_pOperator.StartGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "开始取流失败;"; + } else { msg += "开始取流成功;"; @@ -260,32 +274,48 @@ } } + // 视频画面显示在界面上 int playRet = 0; - if (ProMemory.formType == "1") m_pOperator.Display(Form1.GetInstance().picLive.Handle); - else if (ProMemory.formType == "2") m_pOperator.Display(Form2.GetInstance().picLive.Handle); + if (ProMemory.formType == "1") + { + m_pOperator.Display(Form1.GetInstance().picLive.Handle); + } + else if (ProMemory.formType == "2") + { + m_pOperator.Display(Form2.GetInstance().picLive.Handle); + } if (MyCamera.MV_OK != playRet) - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + } - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 ProMemory.findingEyes = true; + ProMemory.identifyConfig.FlagWorking = true; } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); } finally { } } - private void stopGrabbing() + private void StopGrabbing() { - int nRet = m_pOperator.StopGrabbing(); - if (ProMemory.formType == "1") Form1.GetInstance().picLive.Image = null; - else if (ProMemory.formType == "2") Form2.GetInstance().picLive.Image = null; + m_pOperator.StopGrabbing(); + if (ProMemory.formType == "1") + { + Form1.GetInstance().picLive.Image = null; + } + else if (ProMemory.formType == "2") + { + Form2.GetInstance().picLive.Image = null; + } ProMemory.m_bGrabbing = false; } diff --git a/irisRefactor/IrisThread/FindEyesTh.cs b/irisRefactor/IrisThread/FindEyesTh.cs index baa4137..aaee4b3 100644 --- a/irisRefactor/IrisThread/FindEyesTh.cs +++ b/irisRefactor/IrisThread/FindEyesTh.cs @@ -35,13 +35,13 @@ while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning) { //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs new file mode 100644 index 0000000..32e9240 --- /dev/null +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -0,0 +1,104 @@ +using irisHelper; +using irisRefactor.FrmService; +using System; +using System.Diagnostics; +using System.Reflection; +using System.Threading; + +namespace irisRefactor.IrisThread +{ + public class IdentifyTh + { + private static readonly IdentifyTh identiyfTh = new IdentifyTh(); + private IdentifyTh() { } + public static IdentifyTh GetInstance + { + get => identiyfTh; + } + + public void Identify() + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); + ProMemory.irisConfig.IdentifyAccess = true; + + // 用于计算操作耗时 + Stopwatch sw = new Stopwatch(); + + try + { + int iMatchNumber = 0; + float iHammingDistance = 1; + int iLeftRight = 0; + + while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && + ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + { + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); + if (ProMemory.irisConfig.Q4.Count > 0) + { + lock (ProMemory.irisConfig.Q4) + { + if (ProMemory.irisConfig.Q4.Count > 0) + { + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + } + } + if (ProMemory.irisConfig.QualifiedIrisBuffer != null) + { + //加载匹配列表 + sw.Restart(); + iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "识别[" + iMatchNumber + "]:" + sw.ElapsedMilliseconds); + } + } + } + + // ProMemory.timer2.Dispose();//停止计时器 + + + //跳出循环,条件是时间到、匹配成功或者正在关闭程序 + ProMemory.irisConfig.AssessThreadRun = false; + ProMemory.irisConfig.EyeFinderThreadRun = false; + + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + //匹配成功 + if (iMatchNumber > 0) + { + string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId + if (ProMemory.formType == "1") + Form1.GetInstance().Success(personId); + else if (ProMemory.formType == "2") + Form2.GetInstance().Success(personId); + //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); + Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); + } + //匹配失败 + else + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().failure(); + //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + } + + + ProMemory.jobRuning = false; + ProMemory.cameraController.ContinuousShot_TriggerOff(); + + } + catch (Exception ex) + { + LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); + } + } + + + } +} \ No newline at end of file diff --git a/irisRefactor/IrisThread/IdentiyfTh.cs b/irisRefactor/IrisThread/IdentiyfTh.cs deleted file mode 100644 index 99878de..0000000 --- a/irisRefactor/IrisThread/IdentiyfTh.cs +++ /dev/null @@ -1,100 +0,0 @@ -using irisHelper; -using irisRefactor.FrmService; -using System; -using System.Reflection; -using System.Threading; - -namespace irisRefactor.IrisThread -{ - public class IdentiyfTh - { - private static IdentiyfTh _identiyfTh = null; - private IdentiyfTh() { - } - public static IdentiyfTh GetInstance() - { - if (_identiyfTh == null) - _identiyfTh = new IdentiyfTh(); - - return _identiyfTh; - - } - - public void Identify() - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify"); - ProMemory.irisConfig.IdentifyAccess = true; - - try - { - int iMatchNumber = 0; - float iHammingDistance = 1; - int iLeftRight = 0; - - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) - { - lock (ProMemory.irisConfig.Q4) - { - if (ProMemory.irisConfig.Q4.Count > 0) - { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); - } - } - if (ProMemory.irisConfig.QualifiedIrisBuffer != null) - { - //加载匹配列表 - iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); - } - } - } - - // ProMemory.timer2.Dispose();//停止计时器 - - //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; - - if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) - ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); - - //匹配成功 - if (iMatchNumber > 0) - { - string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId - if (ProMemory.formType == "1") - Form1.GetInstance().Success(personId); - else if (ProMemory.formType == "2") - Form2.GetInstance().Success(personId); - //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); - Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); - } - //匹配失败 - else - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); - - if (ProMemory.formType == "1") - Form1.GetInstance().failure(); - else if (ProMemory.formType == "2") - Form2.GetInstance().failure(); - //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); - Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); - } - - ProMemory.jobRuning = false; - ProMemory.cameraController.ContinuousShot_TriggerOff(); - - } - catch (Exception ex) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); - } - } - - - } -} \ No newline at end of file diff --git a/irisRefactor/IrisThread/ImageQualityAssessTh.cs b/irisRefactor/IrisThread/ImageQualityAssessTh.cs index b21ca9d..0650491 100644 --- a/irisRefactor/IrisThread/ImageQualityAssessTh.cs +++ b/irisRefactor/IrisThread/ImageQualityAssessTh.cs @@ -105,7 +105,7 @@ ProMemory.irisConfig.Key_Identify = 1; ProMemory.irisConfig.IdentifyThreadRun = true; - Thread m_IdentifyThread = new Thread(IdentiyfTh.GetInstance().Identify); + Thread m_IdentifyThread = new Thread(IdentifyTh.GetInstance.Identify); m_IdentifyThread.Name = "Identify"; m_IdentifyThread.Start(); } @@ -136,7 +136,7 @@ if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) { Form1.GetInstance().obtainTemp(); - Form1.GetInstance().failure(); + Form1.GetInstance().Failure(); } else { Form2.GetInstance().failure(); diff --git a/irisRefactor/IrisThread/PreIdentifyTh.cs b/irisRefactor/IrisThread/PreIdentifyTh.cs index 90d4848..1ed042a 100644 --- a/irisRefactor/IrisThread/PreIdentifyTh.cs +++ b/irisRefactor/IrisThread/PreIdentifyTh.cs @@ -1,5 +1,4 @@ using irisHelper; -using irisRefactor.FrmService; using System; using System.Diagnostics; using System.Reflection; @@ -15,41 +14,39 @@ */ class PreIdentifyTh { - private PreIdentifyTh() - { + private PreIdentifyTh() { } - } - - private static readonly PreIdentifyTh _preIdentifyTh = new PreIdentifyTh(); + private static readonly PreIdentifyTh preIdentifyTh = new PreIdentifyTh(); - public static PreIdentifyTh GetInstance { get => _preIdentifyTh; } + public static PreIdentifyTh GetInstance { get => preIdentifyTh; } public void FindEyes() { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify -- FindEyes"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify Thread Started"); - ProMemory.Tag_SleepTimer = 0; + //ProMemory.Tag_SleepTimer = 0; + //ProMemory.irisConfig.EyeFinderThreadRun = true; // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); - try + // 没有在休眠中;没有数据同步中 + while (ProMemory.isWait == false && ProMemory.isSyning == false) { - // 条件:找眼线程在运行中;休眠线程标志为0;不在数据同步;连续未找到眼睛数小于100 - while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning && ProMemory.identifyConfig.Count_NoEyeLast <= 100) + // 没有正在执行的找眼、识别线程 + if (ProMemory.identifyConfig.FlagFindingEye == false) { - //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } - if (ProMemory.irisConfig.FaceBuffer != null) + try { unsafe { @@ -69,20 +66,35 @@ sw.Restart(); mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 sw.Stop(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "找眼[" + mark + "]:" + sw.ElapsedMilliseconds); int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; - // 找到1个或者2个眼睛 if (mark == 1 || mark == 2) { // 1.持续没有找到眼的计数器清零 - ProMemory.identifyConfig.Count_NoEyeLast = 0; + ProMemory.identifyConfig.CountNoEyeLast = 0; - // 2.黄灯闪烁 - //ProMemory.IoControllService.setYellowFlash(true); - //Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); - //flashThrd.Start(); + ProMemory.identifyConfig.FlagFoundEye = true; + + // 一次识别过程中首次找到眼,标记开始一次新的识别 + if (ProMemory.identifyConfig.IdentifyTaskId == "") + { + ProMemory.identifyConfig.IdentifyTaskId = DateTime.Now.ToString("yyyyMMddHHmmss"); + + // 2.黄灯闪烁 + ProMemory.IoControllService.setYellowFlash(true); + Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + flashThrd.Start(); + + // 开启识别线程 + ProMemory.irisConfig.Key_Identify = 1; + ProMemory.irisConfig.IdentifyThreadRun = true; + + // 初始化识别线程 + Thread thIdentify = new Thread(IdentifyTh.GetInstance.Identify); + thIdentify.Start(); + } // 3.质量评估 int score = 0; @@ -104,7 +116,7 @@ sw.Restart(); score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 sw.Stop(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次质量评估操作[" + score + "]:" + sw.ElapsedMilliseconds); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "质量评估[" + score + "]:" + sw.ElapsedMilliseconds); } } } @@ -128,74 +140,200 @@ } } - - if (ProMemory.irisConfig.Key_Identify == 0) - { - ProMemory.irisConfig.Key_Identify = 1; - ProMemory.irisConfig.IdentifyThreadRun = true; - Thread m_IdentifyThread = new Thread(IdentiyfTh.GetInstance().Identify); - m_IdentifyThread.Name = "Identify"; - m_IdentifyThread.Start(); - } - + //if (ProMemory.irisConfig.Key_Identify == 0) + //{ + // ProMemory.irisConfig.Key_Identify = 1; + + // ProMemory.irisConfig.IdentifyThreadRun = true; + + // // 初始化识别线程 + // Thread thIdentify = new Thread(IdentifyTh.GetInstance.Identify); + // thIdentify.Start(); + //} + } Marshal.FreeHGlobal(ptrIrisFace); } else { - ProMemory.identifyConfig.Count_NoEyeLast++; + ProMemory.identifyConfig.CountNoEyeLast++; } } - - Marshal.FreeHGlobal(ptrFace); } - } - - lock (ProMemory.irisConfig.Q2) + } + catch (Exception ex) { - if (ProMemory.irisConfig.Q2.Count >= 30) - { - ProMemory.irisConfig.Q2.Clear(); //手动控制堆栈容量 - } - } - - lock (ProMemory.irisConfig.Q3) - { - if (ProMemory.irisConfig.Q3.Count >= 30) - { - ProMemory.irisConfig.Q3.Clear(); //手动控制堆栈容量 - } - } - } - } - - //if (ProMemory.Tag_SleepTimer == 1) //待机时间到,仍未找到眼睛 - if (ProMemory.identifyConfig.Count_NoEyeLast > 100) - { - if (ProMemory.m_bGrabbing) - { - if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 - { - if (ProMemory.formType == "1") - Form1.GetInstance().ReInitializeToSleep(); - else if (ProMemory.formType == "2") - Form2.GetInstance().ReInitializeToSleep(); - Thread.Sleep(200); - ProMemory.cameraController.ContinuousShot_TriggerOn(); - } - else //已再次触发,继续下一轮识别 - { - ProMemory.cameraController.ContinuousShot_TriggerOff(); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); } } } } - catch (Exception ex) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); - } + + //try + //{ + // // 条件:找眼线程在运行中;休眠线程标志为0;不在数据同步;连续未找到眼睛数小于100 + // while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning && ProMemory.identifyConfig.CountNoEyeLast <= 100) + // { + // //M++; + // if (ProMemory.irisConfig.QueueFace.Count > 0) + // { + // lock (ProMemory.irisConfig.QueueFace) + // { + // if (ProMemory.irisConfig.QueueFace.Count > 0) + // { + // ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); + // } + // } + + // if (ProMemory.irisConfig.FaceBuffer != null) + // { + // unsafe + // { + // // 申请内存,复制内存 + // IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); + // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); + + // // mark = 找到的眼睛数量 + // int mark; + // // 左右眼睛的定位参数:x,y,r + // int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; + + // fixed (int* pos = &posvec[0]) + // { + // int* ptrPos = pos; + + // sw.Restart(); + // mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 + // sw.Stop(); + // LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + + // int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; + + // // 找到1个或者2个眼睛 + // if (mark == 1 || mark == 2) + // { + // // 1.持续没有找到眼的计数器清零 + // ProMemory.identifyConfig.CountNoEyeLast = 0; + + // // 2.黄灯闪烁 + // //ProMemory.IoControllService.setYellowFlash(true); + // //Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + // //flashThrd.Start(); + + // // 3.质量评估 + // int score = 0; + // Byte[] irisBytesL = new byte[640 * 480]; + // Byte[] irisBytesR = new byte[640 * 480]; + + // IntPtr ptrIrisFace = Marshal.AllocHGlobal(1280 * 960); + // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrIrisFace, 1280 * 960); + + // unsafe + // { + // fixed (byte* irisL = &irisBytesL[0]) + // { + // fixed (byte* irisR = &irisBytesR[0]) + // { + // byte* ptrIrisL = irisL; + // byte* ptrIrisR = irisR; + + // sw.Restart(); + // score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 + // sw.Stop(); + // LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次质量评估操作[" + score + "]:" + sw.ElapsedMilliseconds); + // } + // } + // } + + + // if (score > 0) + // { + // if (score == 1) + // { + // lock (ProMemory.irisConfig.Q4) + // { + // ProMemory.irisConfig.Q4.Push(irisBytesL); + // } + // } + // else if (score == 2) + // { + // lock (ProMemory.irisConfig.Q4) + // { + // ProMemory.irisConfig.Q4.Push(irisBytesL); + // ProMemory.irisConfig.Q4.Push(irisBytesR); + // } + // } + + + // if (ProMemory.irisConfig.Key_Identify == 0) + // { + // ProMemory.irisConfig.Key_Identify = 1; + + // ProMemory.irisConfig.IdentifyThreadRun = true; + // //Thread m_IdentifyThread = new Thread(IdentifyTh.GetInstance().Identify); + // //m_IdentifyThread.Name = "Identify"; + // //m_IdentifyThread.Start(); + // } + + // } + + // Marshal.FreeHGlobal(ptrIrisFace); + // } + // else + // { + // ProMemory.identifyConfig.CountNoEyeLast++; + // } + // } + + // Marshal.FreeHGlobal(ptrFace); + // } + // } + + // lock (ProMemory.irisConfig.Q2) + // { + // if (ProMemory.irisConfig.Q2.Count >= 30) + // { + // ProMemory.irisConfig.Q2.Clear(); //手动控制堆栈容量 + // } + // } + + // lock (ProMemory.irisConfig.Q3) + // { + // if (ProMemory.irisConfig.Q3.Count >= 30) + // { + // ProMemory.irisConfig.Q3.Clear(); //手动控制堆栈容量 + // } + // } + // } + // } + + // //if (ProMemory.Tag_SleepTimer == 1) //待机时间到,仍未找到眼睛 + // if (ProMemory.identifyConfig.CountNoEyeLast > 100) + // { + // if (ProMemory.m_bGrabbing) + // { + // if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 + // { + // if (ProMemory.formType == "1") + // Form1.GetInstance().ReInitializeToSleep(); + // else if (ProMemory.formType == "2") + // Form2.GetInstance().ReInitializeToSleep(); + // Thread.Sleep(200); + // ProMemory.cameraController.ContinuousShot_TriggerOn(); + // } + // else //已再次触发,继续下一轮识别 + // { + // ProMemory.cameraController.ContinuousShot_TriggerOff(); + // } + // } + // } + //} + //catch (Exception ex) + //{ + // LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); + //} } } } diff --git a/irisRefactor/IrisThread/SaveImageTh.cs b/irisRefactor/IrisThread/SaveImageTh.cs index ab978b4..f0ec820 100644 --- a/irisRefactor/IrisThread/SaveImageTh.cs +++ b/irisRefactor/IrisThread/SaveImageTh.cs @@ -13,14 +13,12 @@ public class SaveImageTh { - private static SaveImageTh _saveImageTh = null; + private static readonly SaveImageTh saveImageTh = new SaveImageTh(); private SaveImageTh() { } - public static SaveImageTh GetInstance() + public static SaveImageTh GetInstance { - if (_saveImageTh == null) - _saveImageTh = new SaveImageTh(); + get => saveImageTh; - return _saveImageTh; } //图象采集回调函数 //pData [out] 保存图像数据的缓存地址 @@ -30,7 +28,7 @@ { try { - //1.取出采集到的图像 + // 1.取出采集到的图像 int ylength = pFrameInfo.nWidth * pFrameInfo.nHeight; byte[] imgBytes = new byte[ylength]; Marshal.Copy(pData, imgBytes, 0, ylength); @@ -38,47 +36,26 @@ if (image == null) return; - //2.对图像进行人眼搜索处理 - // 条件:未处在待机状态;正在取流过程;没有进行数据同步 - if (ProMemory.isWait == false && ProMemory.findingEyes && !ProMemory.isSyning) + //2.将图像存入堆栈中 + // 条件:未在待机状态 + if (ProMemory.isWait == false) { + // 开启工作线程 + ProMemory.identifyConfig.FlagWorking = true; + try { - //将图片放入堆栈1 - lock (ProMemory.irisConfig.Q1) + // 将图片放入堆栈1 + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Push(imgBytes); - // LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Q1.Push:" + ProMemory.irisConfig.Q1.Count); + ProMemory.irisConfig.QueueFace.Push(imgBytes); + // LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q1.Push:" + ProMemory.irisConfig.QueueFace.Count); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程push q1 :" + ee); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程push q1 :" + ee); } - - // 条件:找眼线程未开启;未处于待机状态 - if (ProMemory.irisConfig.Key_FindEyes == 0 && !ProMemory.isWait) - { - // 标记进入找眼线程 - /* - ProMemory.irisConfig.Key_FindEyes = 1; - ProMemory.irisConfig.EyeFinderThreadRun = true; - - // 新建线程进行找眼 - Thread m_EyeFinderThread = new Thread(FindEyesTh.GetInstance().FindEyes); - m_EyeFinderThread.Name = "FindEyes"; - m_EyeFinderThread.Start(); - */ - - // 开启工作线程 - ProMemory.identifyConfig.Flag_Working = 1; - ProMemory.irisConfig.Key_FindEyes = 1; - ProMemory.irisConfig.EyeFinderThreadRun = true; - Thread th_PreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes); - th_PreIdentify.Name = "FindEyes"; - th_PreIdentify.Start(); - } - } //释放内存 @@ -86,22 +63,22 @@ //image = null; try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count >= 30) + if (ProMemory.irisConfig.QueueFace.Count >= 30) { - ProMemory.irisConfig.Q1.Clear(); //手动控制堆栈容量 + ProMemory.irisConfig.QueueFace.Clear(); //手动控制堆栈容量 } } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程clear q1 :" + ee); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程clear q1 :" + ee); } } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "图像采集线程CatchError:" + ex); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "图像采集线程CatchError:" + ex); } } diff --git a/irisRefactor/ProMemory.cs b/irisRefactor/ProMemory.cs index 07d8bfa..1063f21 100644 --- a/irisRefactor/ProMemory.cs +++ b/irisRefactor/ProMemory.cs @@ -7,6 +7,7 @@ using irisMemory; using irisRefactor.IrisCamera; using irisRefactor.IrisScoket; +using irisRefactor.IrisThread; using MvCamCtrl.NET; using System; using System.Net; @@ -86,6 +87,7 @@ irisConfig = IrisConfig.GetInstance(); identifyConfig = IdentifyConfig.GetInstance; + // 相机控制 cameraController = CameraController.GetInstance(); //GetHostIPv4(); @@ -96,7 +98,7 @@ //检测并连接相机 proConfig.PDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST(); timerCamera = new System.Windows.Forms.Timer(); - timerCamera.Tick += new EventHandler(cameraController.timerCamera_Tick); + timerCamera.Tick += new EventHandler(cameraController.TimerCamera_Tick); timerCamera.Interval = 3000; timerCamera.Start(); @@ -106,6 +108,13 @@ //数据库链接 Thread connectServerThread = new Thread(connectDatabase); connectServerThread.Start(); + + // 初始化找眼预处理线程 + Thread thPreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes) + { + Name = "PreIdentifyThread" + }; + thPreIdentify.Start(); } catch (Exception ex) { LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ex.Message); diff --git a/irisHelper/LogHelper.cs b/irisHelper/LogHelper.cs index f9d985e..f45cd71 100644 --- a/irisHelper/LogHelper.cs +++ b/irisHelper/LogHelper.cs @@ -23,6 +23,28 @@ log.Info(msg); } + public static void WriteDebugLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Debug(msg); + } + public static void WriteInfoLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Info(msg); + } + + public static void WriteWarnLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Warn(msg); + } + + public static void WriteErrorLog(Type t, string msg) + { + log4net.ILog log = log4net.LogManager.GetLogger(t); + log.Error(msg); + } } } diff --git a/irisIoControll/Service/Impl/SusiControlImpl.cs b/irisIoControll/Service/Impl/SusiControlImpl.cs index 02e4ef0..4ff5137 100644 --- a/irisIoControll/Service/Impl/SusiControlImpl.cs +++ b/irisIoControll/Service/Impl/SusiControlImpl.cs @@ -34,7 +34,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } return re; } @@ -49,7 +49,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -62,7 +62,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -74,7 +74,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -87,7 +87,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -99,7 +99,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -116,7 +116,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } @@ -137,7 +137,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, e.Message.ToString()); } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index 5b3241e..c025b36 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -7,27 +7,44 @@ { public class IdentifyConfig { - // =1时表示在工作,从队列中取出图片调用找眼算法; + // =1时表示在工作,拍图; // =0时表示终端待机 - private int flag_Working; // 是否在找眼标志位,是否在工作标志位 - private int flag_FoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 + private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 + private volatile bool flagFindingEye; // 是否正在找眼标志位 + private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int count_NoEyeLast; // 连续没找到眼的次数 + private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + + private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() { - this.Flag_Working = 0; - this.Flag_FoundEye = 0; + this.InitConfig(); + } - this.Count_NoEyeLast = 0; + /** + * 初始化识别过程控制参数 + */ + public void InitConfig() + { + this.FlagWorking = false; + this.FlagFindingEye = false; + this.FlagFoundEye = false; + + this.CountNoEyeLast = 0; + + this.IdentifyTaskId = ""; } private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); - public int Flag_Working { get => flag_Working; set => flag_Working = value; } - public int Flag_FoundEye { get => flag_FoundEye; set => flag_FoundEye = value; } - public int Count_NoEyeLast { get => count_NoEyeLast; set => count_NoEyeLast = value; } - public static IdentifyConfig GetInstance { get => identifyConfig; } + + public bool FlagWorking { get => flagWorking; set => flagWorking = value; } + public bool FlagFindingEye { get => flagFindingEye; set => flagFindingEye = value; } + public bool FlagFoundEye { get => flagFoundEye; set => flagFoundEye = value; } + public int CountNoEyeLast { get => countNoEyeLast; set => countNoEyeLast = value; } + + public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d77b21d..d4188d5 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -7,7 +7,7 @@ { public class IrisConfig { - private static Stack q1; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ + private static Stack queueFace; /* 队列1:用于存放相机采集的面部图像,供搜索眼睛 */ private static Stack q2; /* 队列2:用于存放搜到眼睛的面部图像,供质量评估 */ private static Stack q3; /* 队列3:用于存放搜到眼睛的位置参数(x,y,r),供质量评估 */ private static Stack q4; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ @@ -31,16 +31,16 @@ private static IrisConfig _irisConfig; - public Stack Q1 + public Stack QueueFace { get { - return q1; + return queueFace; } set { - q1 = value; + queueFace = value; } } @@ -228,7 +228,7 @@ private IrisConfig() { - Q1 = new Stack(); + QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); Q4 = new Stack(); diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 5e64edc..7248348 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -118,7 +118,7 @@ - + diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index 8418b11..adbd758 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -138,9 +138,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -203,9 +203,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { @@ -247,7 +247,7 @@ /// /// 识别失败 /// - public void failure() + public void Failure() { if (ProMemory.isSyning) return; try @@ -359,7 +359,7 @@ } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "failure catch error: " + ex.Message); } } @@ -390,7 +390,7 @@ ProMemory.stringBuilder.Append("print person:"); ProMemory.stringBuilder.Append(name); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } Image image = null; @@ -532,13 +532,13 @@ ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, ProMemory.tempString.ToString(), devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "当前测温:"+ProMemory.tempString.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index e4ddfe3..c5571c7 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -109,9 +109,9 @@ try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) @@ -173,9 +173,9 @@ ProMemory.IoControllService.RedOff(); try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Clear(); + ProMemory.irisConfig.QueueFace.Clear(); } lock (ProMemory.irisConfig.Q2) { diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index 40e4ec9..ab18cb6 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -28,9 +28,9 @@ return _cameraController; } - public void timerCamera_Tick(Object sender, EventArgs myEventArgs) + public void TimerCamera_Tick(Object sender, EventArgs myEventArgs) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CameraTickBegin"); //准备相机列表 uint numDevices = 0; numDevices = DeviceListAcq(); @@ -38,9 +38,9 @@ if (numDevices == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("没有检测到相机!", "提示"); + MessageBox.Show("[timerCamera_Tick]没有检测到相机!", "提示"); else - MessageBox.Show("No Device!", "提示"); + MessageBox.Show("[timerCamera_Tick]No Device!", "提示"); return; } @@ -71,7 +71,7 @@ nRet = CameraOperator.EnumDevices(MyCamera.MV_USB_DEVICE, ref ProMemory.m_pDeviceList); if (0 != nRet) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DeviceListAcq :enum failed"); return 0; } @@ -86,9 +86,9 @@ if (ProMemory.m_pDeviceList.nDeviceNum == 0) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("无设备!", "提示"); + MessageBox.Show("[ConnectCamera]连接相机时无设备!", "提示"); else - MessageBox.Show("No Device!", "Meaasge"); + MessageBox.Show("[ConnectCamera]No Device!", "Meaasge"); return; } @@ -104,9 +104,9 @@ if (MyCamera.MV_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("相机打开失败!","提示"); + MessageBox.Show("[ConnectCamera]相机打开失败!", "提示"); else - MessageBox.Show("No Device!", "Message"); + MessageBox.Show("[ConnectCamera]No Device!", "Message"); return; } @@ -115,44 +115,48 @@ m_pOperator.SetEnumValue("TriggerMode", 0); //注册回调函数 - ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance().SaveImage); + ProMemory.ImageCallback = new MyCamera.cbOutputdelegate(SaveImageTh.GetInstance.SaveImage); nRet = m_pOperator.RegisterImageCallBack(ProMemory.ImageCallback, IntPtr.Zero); if (CameraOperator.CO_OK != nRet) { if (ProMemory.appConfig.Language == 1) - MessageBox.Show("注册回调失败!", "提示"); + MessageBox.Show("[ConnectCamera]注册回调失败!", "提示"); else - MessageBox.Show("regist failed", "message"); + MessageBox.Show("[ConnectCamera]regist failed", "message"); } - ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(getException); + ProMemory.CallBackFunc = new MyCamera.cbExceptiondelegate(GetException); int exNet = m_pOperator.RegisterExceptionCallBack(ProMemory.CallBackFunc, IntPtr.Zero); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "connect camera failed:" + e.Message); MessageBox.Show("ConnectCamera:" + e.Message); } } - private void getException(uint nMsgType, IntPtr pUser) + private void GetException(uint nMsgType, IntPtr pUser) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "Exception callback:" + nMsgType); try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "restart"); ShutdownHelper.Restart(); //LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save success!"); } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed"); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "camera save failed" + ex.Message); } } + /** + * 待机 + * 持续监测感应模块,有外触发到来则重新开始工作 + */ public void ContinuousShot_TriggerOn() { try @@ -160,16 +164,20 @@ ProMemory.isWait = true; ProMemory.jobRuning = false; - stopGrabbing(); + // 先停止取流 + StopGrabbing(); //GC.Collect(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "触发待机线程:" + Thread.CurrentThread.Name); + + // 循环检测是否有外触发,重新开始工作 while (ProMemory.isWait) { - if (ProMemory.IoControllService.getSensorVal() == 1) //通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + // 通过检测嵌入式板子输入端口0电平状态判断外触发是否到来 + if (ProMemory.IoControllService.getSensorVal() == 1) { - //外触发到来,开始采集 - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); + // 外触发到来,开始采集 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来"); ProMemory.IoControllService.YellowOn(); ProMemory.isWait = false; Grabbing(); @@ -178,28 +186,30 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发采集错误 :" + e); MessageBox.Show("ContinuousShot_TriggerOn:" + e.Message); } } - //普通模式开始采集 + /** + * 正常工作 + */ public void ContinuousShot_TriggerOff() { try { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来当前线程:" + Thread.CurrentThread.Name); - //重置界面 + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "外触发到来,当前线程:" + Thread.CurrentThread.Name); + + // 重置界面 if (ProMemory.formType == "1") Form1.GetInstance().ReInitialize(); else if (ProMemory.formType == "2") Form2.GetInstance().ReInitialize(); ProMemory.IoControllService.YellowOn(); Grabbing(); - } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "普通采集错误 :" + e); } } @@ -216,7 +226,7 @@ } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "断开相机错误:" + e); MessageBox.Show("CloseCamera:" + e.Message); } } @@ -226,7 +236,7 @@ { if (ProMemory.isSyning) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "数据更新过程中,暂停取流"); return; } //ProMemory.jobRuning = true; @@ -241,7 +251,9 @@ { nRet = m_pOperator.StopGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "停止取流失败;"; + } else { msg += "停止取流成功;"; @@ -251,7 +263,9 @@ nRet = m_pOperator.StartGrabbing(); if (MyCamera.MV_OK != nRet) + { msg += "开始取流失败;"; + } else { msg += "开始取流成功;"; @@ -260,32 +274,48 @@ } } + // 视频画面显示在界面上 int playRet = 0; - if (ProMemory.formType == "1") m_pOperator.Display(Form1.GetInstance().picLive.Handle); - else if (ProMemory.formType == "2") m_pOperator.Display(Form2.GetInstance().picLive.Handle); + if (ProMemory.formType == "1") + { + m_pOperator.Display(Form1.GetInstance().picLive.Handle); + } + else if (ProMemory.formType == "2") + { + m_pOperator.Display(Form2.GetInstance().picLive.Handle); + } if (MyCamera.MV_OK != playRet) - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "DISPLAY:" + "FAIEL"); + } - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 ProMemory.findingEyes = true; + ProMemory.identifyConfig.FlagWorking = true; } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "StartGrabbingError"+ex.Message); } finally { } } - private void stopGrabbing() + private void StopGrabbing() { - int nRet = m_pOperator.StopGrabbing(); - if (ProMemory.formType == "1") Form1.GetInstance().picLive.Image = null; - else if (ProMemory.formType == "2") Form2.GetInstance().picLive.Image = null; + m_pOperator.StopGrabbing(); + if (ProMemory.formType == "1") + { + Form1.GetInstance().picLive.Image = null; + } + else if (ProMemory.formType == "2") + { + Form2.GetInstance().picLive.Image = null; + } ProMemory.m_bGrabbing = false; } diff --git a/irisRefactor/IrisThread/FindEyesTh.cs b/irisRefactor/IrisThread/FindEyesTh.cs index baa4137..aaee4b3 100644 --- a/irisRefactor/IrisThread/FindEyesTh.cs +++ b/irisRefactor/IrisThread/FindEyesTh.cs @@ -35,13 +35,13 @@ while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning) { //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs new file mode 100644 index 0000000..32e9240 --- /dev/null +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -0,0 +1,104 @@ +using irisHelper; +using irisRefactor.FrmService; +using System; +using System.Diagnostics; +using System.Reflection; +using System.Threading; + +namespace irisRefactor.IrisThread +{ + public class IdentifyTh + { + private static readonly IdentifyTh identiyfTh = new IdentifyTh(); + private IdentifyTh() { } + public static IdentifyTh GetInstance + { + get => identiyfTh; + } + + public void Identify() + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); + ProMemory.irisConfig.IdentifyAccess = true; + + // 用于计算操作耗时 + Stopwatch sw = new Stopwatch(); + + try + { + int iMatchNumber = 0; + float iHammingDistance = 1; + int iLeftRight = 0; + + while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && + ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + { + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); + if (ProMemory.irisConfig.Q4.Count > 0) + { + lock (ProMemory.irisConfig.Q4) + { + if (ProMemory.irisConfig.Q4.Count > 0) + { + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + } + } + if (ProMemory.irisConfig.QualifiedIrisBuffer != null) + { + //加载匹配列表 + sw.Restart(); + iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "识别[" + iMatchNumber + "]:" + sw.ElapsedMilliseconds); + } + } + } + + // ProMemory.timer2.Dispose();//停止计时器 + + + //跳出循环,条件是时间到、匹配成功或者正在关闭程序 + ProMemory.irisConfig.AssessThreadRun = false; + ProMemory.irisConfig.EyeFinderThreadRun = false; + + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + //匹配成功 + if (iMatchNumber > 0) + { + string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId + if (ProMemory.formType == "1") + Form1.GetInstance().Success(personId); + else if (ProMemory.formType == "2") + Form2.GetInstance().Success(personId); + //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); + Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); + } + //匹配失败 + else + { + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().failure(); + //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + } + + + ProMemory.jobRuning = false; + ProMemory.cameraController.ContinuousShot_TriggerOff(); + + } + catch (Exception ex) + { + LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); + } + } + + + } +} \ No newline at end of file diff --git a/irisRefactor/IrisThread/IdentiyfTh.cs b/irisRefactor/IrisThread/IdentiyfTh.cs deleted file mode 100644 index 99878de..0000000 --- a/irisRefactor/IrisThread/IdentiyfTh.cs +++ /dev/null @@ -1,100 +0,0 @@ -using irisHelper; -using irisRefactor.FrmService; -using System; -using System.Reflection; -using System.Threading; - -namespace irisRefactor.IrisThread -{ - public class IdentiyfTh - { - private static IdentiyfTh _identiyfTh = null; - private IdentiyfTh() { - } - public static IdentiyfTh GetInstance() - { - if (_identiyfTh == null) - _identiyfTh = new IdentiyfTh(); - - return _identiyfTh; - - } - - public void Identify() - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify"); - ProMemory.irisConfig.IdentifyAccess = true; - - try - { - int iMatchNumber = 0; - float iHammingDistance = 1; - int iLeftRight = 0; - - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) - { - lock (ProMemory.irisConfig.Q4) - { - if (ProMemory.irisConfig.Q4.Count > 0) - { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); - } - } - if (ProMemory.irisConfig.QualifiedIrisBuffer != null) - { - //加载匹配列表 - iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight); - } - } - } - - // ProMemory.timer2.Dispose();//停止计时器 - - //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; - - if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) - ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); - - //匹配成功 - if (iMatchNumber > 0) - { - string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId - if (ProMemory.formType == "1") - Form1.GetInstance().Success(personId); - else if (ProMemory.formType == "2") - Form2.GetInstance().Success(personId); - //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess")); - Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); - } - //匹配失败 - else - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); - - if (ProMemory.formType == "1") - Form1.GetInstance().failure(); - else if (ProMemory.formType == "2") - Form2.GetInstance().failure(); - //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure")); - Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); - } - - ProMemory.jobRuning = false; - ProMemory.cameraController.ContinuousShot_TriggerOff(); - - } - catch (Exception ex) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex); - } - } - - - } -} \ No newline at end of file diff --git a/irisRefactor/IrisThread/ImageQualityAssessTh.cs b/irisRefactor/IrisThread/ImageQualityAssessTh.cs index b21ca9d..0650491 100644 --- a/irisRefactor/IrisThread/ImageQualityAssessTh.cs +++ b/irisRefactor/IrisThread/ImageQualityAssessTh.cs @@ -105,7 +105,7 @@ ProMemory.irisConfig.Key_Identify = 1; ProMemory.irisConfig.IdentifyThreadRun = true; - Thread m_IdentifyThread = new Thread(IdentiyfTh.GetInstance().Identify); + Thread m_IdentifyThread = new Thread(IdentifyTh.GetInstance.Identify); m_IdentifyThread.Name = "Identify"; m_IdentifyThread.Start(); } @@ -136,7 +136,7 @@ if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) { Form1.GetInstance().obtainTemp(); - Form1.GetInstance().failure(); + Form1.GetInstance().Failure(); } else { Form2.GetInstance().failure(); diff --git a/irisRefactor/IrisThread/PreIdentifyTh.cs b/irisRefactor/IrisThread/PreIdentifyTh.cs index 90d4848..1ed042a 100644 --- a/irisRefactor/IrisThread/PreIdentifyTh.cs +++ b/irisRefactor/IrisThread/PreIdentifyTh.cs @@ -1,5 +1,4 @@ using irisHelper; -using irisRefactor.FrmService; using System; using System.Diagnostics; using System.Reflection; @@ -15,41 +14,39 @@ */ class PreIdentifyTh { - private PreIdentifyTh() - { + private PreIdentifyTh() { } - } - - private static readonly PreIdentifyTh _preIdentifyTh = new PreIdentifyTh(); + private static readonly PreIdentifyTh preIdentifyTh = new PreIdentifyTh(); - public static PreIdentifyTh GetInstance { get => _preIdentifyTh; } + public static PreIdentifyTh GetInstance { get => preIdentifyTh; } public void FindEyes() { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify -- FindEyes"); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify Thread Started"); - ProMemory.Tag_SleepTimer = 0; + //ProMemory.Tag_SleepTimer = 0; + //ProMemory.irisConfig.EyeFinderThreadRun = true; // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); - try + // 没有在休眠中;没有数据同步中 + while (ProMemory.isWait == false && ProMemory.isSyning == false) { - // 条件:找眼线程在运行中;休眠线程标志为0;不在数据同步;连续未找到眼睛数小于100 - while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning && ProMemory.identifyConfig.Count_NoEyeLast <= 100) + // 没有正在执行的找眼、识别线程 + if (ProMemory.identifyConfig.FlagFindingEye == false) { - //M++; - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count > 0) + if (ProMemory.irisConfig.QueueFace.Count > 0) { - ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.Q1.Pop(); + ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); } } - if (ProMemory.irisConfig.FaceBuffer != null) + try { unsafe { @@ -69,20 +66,35 @@ sw.Restart(); mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 sw.Stop(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "找眼[" + mark + "]:" + sw.ElapsedMilliseconds); int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; - // 找到1个或者2个眼睛 if (mark == 1 || mark == 2) { // 1.持续没有找到眼的计数器清零 - ProMemory.identifyConfig.Count_NoEyeLast = 0; + ProMemory.identifyConfig.CountNoEyeLast = 0; - // 2.黄灯闪烁 - //ProMemory.IoControllService.setYellowFlash(true); - //Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); - //flashThrd.Start(); + ProMemory.identifyConfig.FlagFoundEye = true; + + // 一次识别过程中首次找到眼,标记开始一次新的识别 + if (ProMemory.identifyConfig.IdentifyTaskId == "") + { + ProMemory.identifyConfig.IdentifyTaskId = DateTime.Now.ToString("yyyyMMddHHmmss"); + + // 2.黄灯闪烁 + ProMemory.IoControllService.setYellowFlash(true); + Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + flashThrd.Start(); + + // 开启识别线程 + ProMemory.irisConfig.Key_Identify = 1; + ProMemory.irisConfig.IdentifyThreadRun = true; + + // 初始化识别线程 + Thread thIdentify = new Thread(IdentifyTh.GetInstance.Identify); + thIdentify.Start(); + } // 3.质量评估 int score = 0; @@ -104,7 +116,7 @@ sw.Restart(); score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 sw.Stop(); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次质量评估操作[" + score + "]:" + sw.ElapsedMilliseconds); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "质量评估[" + score + "]:" + sw.ElapsedMilliseconds); } } } @@ -128,74 +140,200 @@ } } - - if (ProMemory.irisConfig.Key_Identify == 0) - { - ProMemory.irisConfig.Key_Identify = 1; - ProMemory.irisConfig.IdentifyThreadRun = true; - Thread m_IdentifyThread = new Thread(IdentiyfTh.GetInstance().Identify); - m_IdentifyThread.Name = "Identify"; - m_IdentifyThread.Start(); - } - + //if (ProMemory.irisConfig.Key_Identify == 0) + //{ + // ProMemory.irisConfig.Key_Identify = 1; + + // ProMemory.irisConfig.IdentifyThreadRun = true; + + // // 初始化识别线程 + // Thread thIdentify = new Thread(IdentifyTh.GetInstance.Identify); + // thIdentify.Start(); + //} + } Marshal.FreeHGlobal(ptrIrisFace); } else { - ProMemory.identifyConfig.Count_NoEyeLast++; + ProMemory.identifyConfig.CountNoEyeLast++; } } - - Marshal.FreeHGlobal(ptrFace); } - } - - lock (ProMemory.irisConfig.Q2) + } + catch (Exception ex) { - if (ProMemory.irisConfig.Q2.Count >= 30) - { - ProMemory.irisConfig.Q2.Clear(); //手动控制堆栈容量 - } - } - - lock (ProMemory.irisConfig.Q3) - { - if (ProMemory.irisConfig.Q3.Count >= 30) - { - ProMemory.irisConfig.Q3.Clear(); //手动控制堆栈容量 - } - } - } - } - - //if (ProMemory.Tag_SleepTimer == 1) //待机时间到,仍未找到眼睛 - if (ProMemory.identifyConfig.Count_NoEyeLast > 100) - { - if (ProMemory.m_bGrabbing) - { - if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 - { - if (ProMemory.formType == "1") - Form1.GetInstance().ReInitializeToSleep(); - else if (ProMemory.formType == "2") - Form2.GetInstance().ReInitializeToSleep(); - Thread.Sleep(200); - ProMemory.cameraController.ContinuousShot_TriggerOn(); - } - else //已再次触发,继续下一轮识别 - { - ProMemory.cameraController.ContinuousShot_TriggerOff(); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); } } } } - catch (Exception ex) - { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); - } + + //try + //{ + // // 条件:找眼线程在运行中;休眠线程标志为0;不在数据同步;连续未找到眼睛数小于100 + // while (ProMemory.irisConfig.EyeFinderThreadRun && ProMemory.Tag_SleepTimer == 0 && !ProMemory.isSyning && ProMemory.identifyConfig.CountNoEyeLast <= 100) + // { + // //M++; + // if (ProMemory.irisConfig.QueueFace.Count > 0) + // { + // lock (ProMemory.irisConfig.QueueFace) + // { + // if (ProMemory.irisConfig.QueueFace.Count > 0) + // { + // ProMemory.irisConfig.FaceBuffer = ProMemory.irisConfig.QueueFace.Pop(); + // } + // } + + // if (ProMemory.irisConfig.FaceBuffer != null) + // { + // unsafe + // { + // // 申请内存,复制内存 + // IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); + // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); + + // // mark = 找到的眼睛数量 + // int mark; + // // 左右眼睛的定位参数:x,y,r + // int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; + + // fixed (int* pos = &posvec[0]) + // { + // int* ptrPos = pos; + + // sw.Restart(); + // mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 + // sw.Stop(); + // LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + + // int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; + + // // 找到1个或者2个眼睛 + // if (mark == 1 || mark == 2) + // { + // // 1.持续没有找到眼的计数器清零 + // ProMemory.identifyConfig.CountNoEyeLast = 0; + + // // 2.黄灯闪烁 + // //ProMemory.IoControllService.setYellowFlash(true); + // //Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + // //flashThrd.Start(); + + // // 3.质量评估 + // int score = 0; + // Byte[] irisBytesL = new byte[640 * 480]; + // Byte[] irisBytesR = new byte[640 * 480]; + + // IntPtr ptrIrisFace = Marshal.AllocHGlobal(1280 * 960); + // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrIrisFace, 1280 * 960); + + // unsafe + // { + // fixed (byte* irisL = &irisBytesL[0]) + // { + // fixed (byte* irisR = &irisBytesR[0]) + // { + // byte* ptrIrisL = irisL; + // byte* ptrIrisR = irisR; + + // sw.Restart(); + // score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 + // sw.Stop(); + // LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次质量评估操作[" + score + "]:" + sw.ElapsedMilliseconds); + // } + // } + // } + + + // if (score > 0) + // { + // if (score == 1) + // { + // lock (ProMemory.irisConfig.Q4) + // { + // ProMemory.irisConfig.Q4.Push(irisBytesL); + // } + // } + // else if (score == 2) + // { + // lock (ProMemory.irisConfig.Q4) + // { + // ProMemory.irisConfig.Q4.Push(irisBytesL); + // ProMemory.irisConfig.Q4.Push(irisBytesR); + // } + // } + + + // if (ProMemory.irisConfig.Key_Identify == 0) + // { + // ProMemory.irisConfig.Key_Identify = 1; + + // ProMemory.irisConfig.IdentifyThreadRun = true; + // //Thread m_IdentifyThread = new Thread(IdentifyTh.GetInstance().Identify); + // //m_IdentifyThread.Name = "Identify"; + // //m_IdentifyThread.Start(); + // } + + // } + + // Marshal.FreeHGlobal(ptrIrisFace); + // } + // else + // { + // ProMemory.identifyConfig.CountNoEyeLast++; + // } + // } + + // Marshal.FreeHGlobal(ptrFace); + // } + // } + + // lock (ProMemory.irisConfig.Q2) + // { + // if (ProMemory.irisConfig.Q2.Count >= 30) + // { + // ProMemory.irisConfig.Q2.Clear(); //手动控制堆栈容量 + // } + // } + + // lock (ProMemory.irisConfig.Q3) + // { + // if (ProMemory.irisConfig.Q3.Count >= 30) + // { + // ProMemory.irisConfig.Q3.Clear(); //手动控制堆栈容量 + // } + // } + // } + // } + + // //if (ProMemory.Tag_SleepTimer == 1) //待机时间到,仍未找到眼睛 + // if (ProMemory.identifyConfig.CountNoEyeLast > 100) + // { + // if (ProMemory.m_bGrabbing) + // { + // if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 + // { + // if (ProMemory.formType == "1") + // Form1.GetInstance().ReInitializeToSleep(); + // else if (ProMemory.formType == "2") + // Form2.GetInstance().ReInitializeToSleep(); + // Thread.Sleep(200); + // ProMemory.cameraController.ContinuousShot_TriggerOn(); + // } + // else //已再次触发,继续下一轮识别 + // { + // ProMemory.cameraController.ContinuousShot_TriggerOff(); + // } + // } + // } + //} + //catch (Exception ex) + //{ + // LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); + //} } } } diff --git a/irisRefactor/IrisThread/SaveImageTh.cs b/irisRefactor/IrisThread/SaveImageTh.cs index ab978b4..f0ec820 100644 --- a/irisRefactor/IrisThread/SaveImageTh.cs +++ b/irisRefactor/IrisThread/SaveImageTh.cs @@ -13,14 +13,12 @@ public class SaveImageTh { - private static SaveImageTh _saveImageTh = null; + private static readonly SaveImageTh saveImageTh = new SaveImageTh(); private SaveImageTh() { } - public static SaveImageTh GetInstance() + public static SaveImageTh GetInstance { - if (_saveImageTh == null) - _saveImageTh = new SaveImageTh(); + get => saveImageTh; - return _saveImageTh; } //图象采集回调函数 //pData [out] 保存图像数据的缓存地址 @@ -30,7 +28,7 @@ { try { - //1.取出采集到的图像 + // 1.取出采集到的图像 int ylength = pFrameInfo.nWidth * pFrameInfo.nHeight; byte[] imgBytes = new byte[ylength]; Marshal.Copy(pData, imgBytes, 0, ylength); @@ -38,47 +36,26 @@ if (image == null) return; - //2.对图像进行人眼搜索处理 - // 条件:未处在待机状态;正在取流过程;没有进行数据同步 - if (ProMemory.isWait == false && ProMemory.findingEyes && !ProMemory.isSyning) + //2.将图像存入堆栈中 + // 条件:未在待机状态 + if (ProMemory.isWait == false) { + // 开启工作线程 + ProMemory.identifyConfig.FlagWorking = true; + try { - //将图片放入堆栈1 - lock (ProMemory.irisConfig.Q1) + // 将图片放入堆栈1 + lock (ProMemory.irisConfig.QueueFace) { - ProMemory.irisConfig.Q1.Push(imgBytes); - // LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "Q1.Push:" + ProMemory.irisConfig.Q1.Count); + ProMemory.irisConfig.QueueFace.Push(imgBytes); + // LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q1.Push:" + ProMemory.irisConfig.QueueFace.Count); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程push q1 :" + ee); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程push q1 :" + ee); } - - // 条件:找眼线程未开启;未处于待机状态 - if (ProMemory.irisConfig.Key_FindEyes == 0 && !ProMemory.isWait) - { - // 标记进入找眼线程 - /* - ProMemory.irisConfig.Key_FindEyes = 1; - ProMemory.irisConfig.EyeFinderThreadRun = true; - - // 新建线程进行找眼 - Thread m_EyeFinderThread = new Thread(FindEyesTh.GetInstance().FindEyes); - m_EyeFinderThread.Name = "FindEyes"; - m_EyeFinderThread.Start(); - */ - - // 开启工作线程 - ProMemory.identifyConfig.Flag_Working = 1; - ProMemory.irisConfig.Key_FindEyes = 1; - ProMemory.irisConfig.EyeFinderThreadRun = true; - Thread th_PreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes); - th_PreIdentify.Name = "FindEyes"; - th_PreIdentify.Start(); - } - } //释放内存 @@ -86,22 +63,22 @@ //image = null; try { - lock (ProMemory.irisConfig.Q1) + lock (ProMemory.irisConfig.QueueFace) { - if (ProMemory.irisConfig.Q1.Count >= 30) + if (ProMemory.irisConfig.QueueFace.Count >= 30) { - ProMemory.irisConfig.Q1.Clear(); //手动控制堆栈容量 + ProMemory.irisConfig.QueueFace.Clear(); //手动控制堆栈容量 } } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程clear q1 :" + ee); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : 采集线程clear q1 :" + ee); } } catch (Exception ex) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "图像采集线程CatchError:" + ex); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "图像采集线程CatchError:" + ex); } } diff --git a/irisRefactor/ProMemory.cs b/irisRefactor/ProMemory.cs index 07d8bfa..1063f21 100644 --- a/irisRefactor/ProMemory.cs +++ b/irisRefactor/ProMemory.cs @@ -7,6 +7,7 @@ using irisMemory; using irisRefactor.IrisCamera; using irisRefactor.IrisScoket; +using irisRefactor.IrisThread; using MvCamCtrl.NET; using System; using System.Net; @@ -86,6 +87,7 @@ irisConfig = IrisConfig.GetInstance(); identifyConfig = IdentifyConfig.GetInstance; + // 相机控制 cameraController = CameraController.GetInstance(); //GetHostIPv4(); @@ -96,7 +98,7 @@ //检测并连接相机 proConfig.PDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST(); timerCamera = new System.Windows.Forms.Timer(); - timerCamera.Tick += new EventHandler(cameraController.timerCamera_Tick); + timerCamera.Tick += new EventHandler(cameraController.TimerCamera_Tick); timerCamera.Interval = 3000; timerCamera.Start(); @@ -106,6 +108,13 @@ //数据库链接 Thread connectServerThread = new Thread(connectDatabase); connectServerThread.Start(); + + // 初始化找眼预处理线程 + Thread thPreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes) + { + Name = "PreIdentifyThread" + }; + thPreIdentify.Start(); } catch (Exception ex) { LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ex.Message); diff --git a/irisRefactor/irisRefactor.csproj b/irisRefactor/irisRefactor.csproj index f0c6cf1..ac8dd87 100644 --- a/irisRefactor/irisRefactor.csproj +++ b/irisRefactor/irisRefactor.csproj @@ -159,7 +159,7 @@ - +