diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 7248348..111d6ce 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -39,6 +39,11 @@ + + + + + diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 7248348..111d6ce 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -39,6 +39,11 @@ + + + + + diff --git a/irisRefactor/FrmService/Form1.Designer.cs b/irisRefactor/FrmService/Form1.Designer.cs index 10555a6..dc76efe 100644 --- a/irisRefactor/FrmService/Form1.Designer.cs +++ b/irisRefactor/FrmService/Form1.Designer.cs @@ -451,6 +451,7 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Shown += new System.EventHandler(this.Form1_Shown); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 7248348..111d6ce 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -39,6 +39,11 @@ + + + + + diff --git a/irisRefactor/FrmService/Form1.Designer.cs b/irisRefactor/FrmService/Form1.Designer.cs index 10555a6..dc76efe 100644 --- a/irisRefactor/FrmService/Form1.Designer.cs +++ b/irisRefactor/FrmService/Form1.Designer.cs @@ -451,6 +451,7 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Shown += new System.EventHandler(this.Form1_Shown); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index adbd758..77e5276 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -76,7 +76,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } @@ -150,9 +150,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -215,9 +215,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -749,5 +749,15 @@ return meanValue; } #endregion + + private void Form1_KeyUp(object sender, KeyEventArgs e) + { + if (Keys.Escape == e.KeyCode) + { + // 按键ESC,则退出程序 + LogHelper.WriteWarnLog(MethodBase.GetCurrentMethod().DeclaringType, "按下ESC键,退出"); + System.Environment.Exit(0); + } + } } } \ No newline at end of file diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 7248348..111d6ce 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -39,6 +39,11 @@ + + + + + diff --git a/irisRefactor/FrmService/Form1.Designer.cs b/irisRefactor/FrmService/Form1.Designer.cs index 10555a6..dc76efe 100644 --- a/irisRefactor/FrmService/Form1.Designer.cs +++ b/irisRefactor/FrmService/Form1.Designer.cs @@ -451,6 +451,7 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Shown += new System.EventHandler(this.Form1_Shown); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index adbd758..77e5276 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -76,7 +76,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } @@ -150,9 +150,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -215,9 +215,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -749,5 +749,15 @@ return meanValue; } #endregion + + private void Form1_KeyUp(object sender, KeyEventArgs e) + { + if (Keys.Escape == e.KeyCode) + { + // 按键ESC,则退出程序 + LogHelper.WriteWarnLog(MethodBase.GetCurrentMethod().DeclaringType, "按下ESC键,退出"); + System.Environment.Exit(0); + } + } } } \ No newline at end of file diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index c5571c7..518d627 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -62,7 +62,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } catch (Exception ex) @@ -123,14 +123,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } ProMemory.irisConfig.IdentifyAccess = false; @@ -146,7 +146,7 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } @@ -185,14 +185,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } @@ -208,12 +208,12 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } - public void failure() + public void Failure() { if (ProMemory.isSyning) return; @@ -273,7 +273,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; @@ -338,21 +338,21 @@ bool hasPermisson = ProMemory.irisPermisionService.GetOpenDoorPermision(ProMemory.appConfig.AuthConfig, personId, devCode, out doorCode, out inoutType); - doorSound(hasPermisson); + DoorSound(hasPermisson); } else - noDoorSound(); + NoDoorSound(); //考勤 ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, "", devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { @@ -364,7 +364,7 @@ } - private void doorSound(bool hasPermisson) + private void DoorSound(bool hasPermisson) { //有权限 if (hasPermisson) @@ -382,7 +382,7 @@ } } - private void noDoorSound() + private void NoDoorSound() { //识别成功 PlaySound.recSuccess(); diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 7248348..111d6ce 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -39,6 +39,11 @@ + + + + + diff --git a/irisRefactor/FrmService/Form1.Designer.cs b/irisRefactor/FrmService/Form1.Designer.cs index 10555a6..dc76efe 100644 --- a/irisRefactor/FrmService/Form1.Designer.cs +++ b/irisRefactor/FrmService/Form1.Designer.cs @@ -451,6 +451,7 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Shown += new System.EventHandler(this.Form1_Shown); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index adbd758..77e5276 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -76,7 +76,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } @@ -150,9 +150,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -215,9 +215,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -749,5 +749,15 @@ return meanValue; } #endregion + + private void Form1_KeyUp(object sender, KeyEventArgs e) + { + if (Keys.Escape == e.KeyCode) + { + // 按键ESC,则退出程序 + LogHelper.WriteWarnLog(MethodBase.GetCurrentMethod().DeclaringType, "按下ESC键,退出"); + System.Environment.Exit(0); + } + } } } \ No newline at end of file diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index c5571c7..518d627 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -62,7 +62,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } catch (Exception ex) @@ -123,14 +123,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } ProMemory.irisConfig.IdentifyAccess = false; @@ -146,7 +146,7 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } @@ -185,14 +185,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } @@ -208,12 +208,12 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } - public void failure() + public void Failure() { if (ProMemory.isSyning) return; @@ -273,7 +273,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; @@ -338,21 +338,21 @@ bool hasPermisson = ProMemory.irisPermisionService.GetOpenDoorPermision(ProMemory.appConfig.AuthConfig, personId, devCode, out doorCode, out inoutType); - doorSound(hasPermisson); + DoorSound(hasPermisson); } else - noDoorSound(); + NoDoorSound(); //考勤 ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, "", devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { @@ -364,7 +364,7 @@ } - private void doorSound(bool hasPermisson) + private void DoorSound(bool hasPermisson) { //有权限 if (hasPermisson) @@ -382,7 +382,7 @@ } } - private void noDoorSound() + private void NoDoorSound() { //识别成功 PlaySound.recSuccess(); diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index ab18cb6..8638037 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -130,6 +130,13 @@ LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); + + // 初始化找眼预处理线程 + Thread thPreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes) + { + Name = "PreIdentifyThread" + DateTime.Now.ToString("[yyyyMMddHHmmss]") + }; + thPreIdentify.Start(); } catch (Exception e) { @@ -293,8 +300,7 @@ LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 - ProMemory.findingEyes = true; - ProMemory.identifyConfig.FlagWorking = true; + ProMemory.identifyConfig.FlagFindingEye = true; } catch (Exception ex) { diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 7248348..111d6ce 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -39,6 +39,11 @@ + + + + + diff --git a/irisRefactor/FrmService/Form1.Designer.cs b/irisRefactor/FrmService/Form1.Designer.cs index 10555a6..dc76efe 100644 --- a/irisRefactor/FrmService/Form1.Designer.cs +++ b/irisRefactor/FrmService/Form1.Designer.cs @@ -451,6 +451,7 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Shown += new System.EventHandler(this.Form1_Shown); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index adbd758..77e5276 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -76,7 +76,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } @@ -150,9 +150,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -215,9 +215,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -749,5 +749,15 @@ return meanValue; } #endregion + + private void Form1_KeyUp(object sender, KeyEventArgs e) + { + if (Keys.Escape == e.KeyCode) + { + // 按键ESC,则退出程序 + LogHelper.WriteWarnLog(MethodBase.GetCurrentMethod().DeclaringType, "按下ESC键,退出"); + System.Environment.Exit(0); + } + } } } \ No newline at end of file diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index c5571c7..518d627 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -62,7 +62,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } catch (Exception ex) @@ -123,14 +123,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } ProMemory.irisConfig.IdentifyAccess = false; @@ -146,7 +146,7 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } @@ -185,14 +185,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } @@ -208,12 +208,12 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } - public void failure() + public void Failure() { if (ProMemory.isSyning) return; @@ -273,7 +273,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; @@ -338,21 +338,21 @@ bool hasPermisson = ProMemory.irisPermisionService.GetOpenDoorPermision(ProMemory.appConfig.AuthConfig, personId, devCode, out doorCode, out inoutType); - doorSound(hasPermisson); + DoorSound(hasPermisson); } else - noDoorSound(); + NoDoorSound(); //考勤 ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, "", devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { @@ -364,7 +364,7 @@ } - private void doorSound(bool hasPermisson) + private void DoorSound(bool hasPermisson) { //有权限 if (hasPermisson) @@ -382,7 +382,7 @@ } } - private void noDoorSound() + private void NoDoorSound() { //识别成功 PlaySound.recSuccess(); diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index ab18cb6..8638037 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -130,6 +130,13 @@ LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); + + // 初始化找眼预处理线程 + Thread thPreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes) + { + Name = "PreIdentifyThread" + DateTime.Now.ToString("[yyyyMMddHHmmss]") + }; + thPreIdentify.Start(); } catch (Exception e) { @@ -293,8 +300,7 @@ LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 - ProMemory.findingEyes = true; - ProMemory.identifyConfig.FlagWorking = true; + ProMemory.identifyConfig.FlagFindingEye = true; } catch (Exception ex) { diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs index 32e9240..9b1f4e0 100644 --- a/irisRefactor/IrisThread/IdentifyTh.cs +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -20,6 +20,7 @@ { LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); ProMemory.irisConfig.IdentifyAccess = true; + ProMemory.irisConfig.IdentifyThreadRun = true; // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); @@ -30,17 +31,17 @@ float iHammingDistance = 1; int iLeftRight = 0; - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + while (ProMemory.identifyConfig.IdentifyTaskId != "" && iMatchNumber == 0 && + !ProMemory.goingToCloseForm && !ProMemory.isSyning) { - LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) + if (ProMemory.irisConfig.QueueIdentify.Count > 0) { - lock (ProMemory.irisConfig.Q4) + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "QueueIdentify:" + ProMemory.irisConfig.QueueIdentify.Count); + lock (ProMemory.irisConfig.QueueIdentify) { - if (ProMemory.irisConfig.Q4.Count > 0) + if (ProMemory.irisConfig.QueueIdentify.Count > 0) { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.QueueIdentify.Pop(); } } if (ProMemory.irisConfig.QualifiedIrisBuffer != null) @@ -58,8 +59,10 @@ //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; + // ProMemory.irisConfig.AssessThreadRun = false; + // ProMemory.irisConfig.EyeFinderThreadRun = false; + + ProMemory.identifyConfig.FlagFindingEye = false; if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); @@ -76,19 +79,19 @@ Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); } //匹配失败 - else - { - LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + //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); - } - + // 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.identifyConfig.InitConfig(); ProMemory.jobRuning = false; ProMemory.cameraController.ContinuousShot_TriggerOff(); diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 7248348..111d6ce 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -39,6 +39,11 @@ + + + + + diff --git a/irisRefactor/FrmService/Form1.Designer.cs b/irisRefactor/FrmService/Form1.Designer.cs index 10555a6..dc76efe 100644 --- a/irisRefactor/FrmService/Form1.Designer.cs +++ b/irisRefactor/FrmService/Form1.Designer.cs @@ -451,6 +451,7 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Shown += new System.EventHandler(this.Form1_Shown); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index adbd758..77e5276 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -76,7 +76,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } @@ -150,9 +150,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -215,9 +215,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -749,5 +749,15 @@ return meanValue; } #endregion + + private void Form1_KeyUp(object sender, KeyEventArgs e) + { + if (Keys.Escape == e.KeyCode) + { + // 按键ESC,则退出程序 + LogHelper.WriteWarnLog(MethodBase.GetCurrentMethod().DeclaringType, "按下ESC键,退出"); + System.Environment.Exit(0); + } + } } } \ No newline at end of file diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index c5571c7..518d627 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -62,7 +62,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } catch (Exception ex) @@ -123,14 +123,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } ProMemory.irisConfig.IdentifyAccess = false; @@ -146,7 +146,7 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } @@ -185,14 +185,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } @@ -208,12 +208,12 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } - public void failure() + public void Failure() { if (ProMemory.isSyning) return; @@ -273,7 +273,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; @@ -338,21 +338,21 @@ bool hasPermisson = ProMemory.irisPermisionService.GetOpenDoorPermision(ProMemory.appConfig.AuthConfig, personId, devCode, out doorCode, out inoutType); - doorSound(hasPermisson); + DoorSound(hasPermisson); } else - noDoorSound(); + NoDoorSound(); //考勤 ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, "", devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { @@ -364,7 +364,7 @@ } - private void doorSound(bool hasPermisson) + private void DoorSound(bool hasPermisson) { //有权限 if (hasPermisson) @@ -382,7 +382,7 @@ } } - private void noDoorSound() + private void NoDoorSound() { //识别成功 PlaySound.recSuccess(); diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index ab18cb6..8638037 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -130,6 +130,13 @@ LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); + + // 初始化找眼预处理线程 + Thread thPreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes) + { + Name = "PreIdentifyThread" + DateTime.Now.ToString("[yyyyMMddHHmmss]") + }; + thPreIdentify.Start(); } catch (Exception e) { @@ -293,8 +300,7 @@ LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 - ProMemory.findingEyes = true; - ProMemory.identifyConfig.FlagWorking = true; + ProMemory.identifyConfig.FlagFindingEye = true; } catch (Exception ex) { diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs index 32e9240..9b1f4e0 100644 --- a/irisRefactor/IrisThread/IdentifyTh.cs +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -20,6 +20,7 @@ { LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); ProMemory.irisConfig.IdentifyAccess = true; + ProMemory.irisConfig.IdentifyThreadRun = true; // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); @@ -30,17 +31,17 @@ float iHammingDistance = 1; int iLeftRight = 0; - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + while (ProMemory.identifyConfig.IdentifyTaskId != "" && iMatchNumber == 0 && + !ProMemory.goingToCloseForm && !ProMemory.isSyning) { - LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) + if (ProMemory.irisConfig.QueueIdentify.Count > 0) { - lock (ProMemory.irisConfig.Q4) + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "QueueIdentify:" + ProMemory.irisConfig.QueueIdentify.Count); + lock (ProMemory.irisConfig.QueueIdentify) { - if (ProMemory.irisConfig.Q4.Count > 0) + if (ProMemory.irisConfig.QueueIdentify.Count > 0) { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.QueueIdentify.Pop(); } } if (ProMemory.irisConfig.QualifiedIrisBuffer != null) @@ -58,8 +59,10 @@ //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; + // ProMemory.irisConfig.AssessThreadRun = false; + // ProMemory.irisConfig.EyeFinderThreadRun = false; + + ProMemory.identifyConfig.FlagFindingEye = false; if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); @@ -76,19 +79,19 @@ Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); } //匹配失败 - else - { - LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + //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); - } - + // 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.identifyConfig.InitConfig(); ProMemory.jobRuning = false; ProMemory.cameraController.ContinuousShot_TriggerOff(); diff --git a/irisRefactor/IrisThread/ImageQualityAssessTh.cs b/irisRefactor/IrisThread/ImageQualityAssessTh.cs index 0650491..f6d58e4 100644 --- a/irisRefactor/IrisThread/ImageQualityAssessTh.cs +++ b/irisRefactor/IrisThread/ImageQualityAssessTh.cs @@ -86,17 +86,17 @@ { if (score == 1) { - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); } } else if (score == 2) { - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Push(irisBytesL); - ProMemory.irisConfig.Q4.Push(irisBytesR); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesR); } } @@ -116,11 +116,11 @@ } } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - if (ProMemory.irisConfig.Q4.Count >= 30) + if (ProMemory.irisConfig.QueueIdentify.Count >= 30) { - ProMemory.irisConfig.Q4.Clear(); //手动控制堆栈容量 + ProMemory.irisConfig.QueueIdentify.Clear(); //手动控制堆栈容量 } } @@ -139,7 +139,7 @@ Form1.GetInstance().Failure(); } else { - Form2.GetInstance().failure(); + Form2.GetInstance().Failure(); } int time2 = ProMemory.appConfig.ShowTimeFailure; diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 7248348..111d6ce 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -39,6 +39,11 @@ + + + + + diff --git a/irisRefactor/FrmService/Form1.Designer.cs b/irisRefactor/FrmService/Form1.Designer.cs index 10555a6..dc76efe 100644 --- a/irisRefactor/FrmService/Form1.Designer.cs +++ b/irisRefactor/FrmService/Form1.Designer.cs @@ -451,6 +451,7 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Shown += new System.EventHandler(this.Form1_Shown); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index adbd758..77e5276 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -76,7 +76,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } @@ -150,9 +150,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -215,9 +215,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -749,5 +749,15 @@ return meanValue; } #endregion + + private void Form1_KeyUp(object sender, KeyEventArgs e) + { + if (Keys.Escape == e.KeyCode) + { + // 按键ESC,则退出程序 + LogHelper.WriteWarnLog(MethodBase.GetCurrentMethod().DeclaringType, "按下ESC键,退出"); + System.Environment.Exit(0); + } + } } } \ No newline at end of file diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index c5571c7..518d627 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -62,7 +62,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } catch (Exception ex) @@ -123,14 +123,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } ProMemory.irisConfig.IdentifyAccess = false; @@ -146,7 +146,7 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } @@ -185,14 +185,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } @@ -208,12 +208,12 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } - public void failure() + public void Failure() { if (ProMemory.isSyning) return; @@ -273,7 +273,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; @@ -338,21 +338,21 @@ bool hasPermisson = ProMemory.irisPermisionService.GetOpenDoorPermision(ProMemory.appConfig.AuthConfig, personId, devCode, out doorCode, out inoutType); - doorSound(hasPermisson); + DoorSound(hasPermisson); } else - noDoorSound(); + NoDoorSound(); //考勤 ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, "", devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { @@ -364,7 +364,7 @@ } - private void doorSound(bool hasPermisson) + private void DoorSound(bool hasPermisson) { //有权限 if (hasPermisson) @@ -382,7 +382,7 @@ } } - private void noDoorSound() + private void NoDoorSound() { //识别成功 PlaySound.recSuccess(); diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index ab18cb6..8638037 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -130,6 +130,13 @@ LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); + + // 初始化找眼预处理线程 + Thread thPreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes) + { + Name = "PreIdentifyThread" + DateTime.Now.ToString("[yyyyMMddHHmmss]") + }; + thPreIdentify.Start(); } catch (Exception e) { @@ -293,8 +300,7 @@ LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 - ProMemory.findingEyes = true; - ProMemory.identifyConfig.FlagWorking = true; + ProMemory.identifyConfig.FlagFindingEye = true; } catch (Exception ex) { diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs index 32e9240..9b1f4e0 100644 --- a/irisRefactor/IrisThread/IdentifyTh.cs +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -20,6 +20,7 @@ { LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); ProMemory.irisConfig.IdentifyAccess = true; + ProMemory.irisConfig.IdentifyThreadRun = true; // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); @@ -30,17 +31,17 @@ float iHammingDistance = 1; int iLeftRight = 0; - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + while (ProMemory.identifyConfig.IdentifyTaskId != "" && iMatchNumber == 0 && + !ProMemory.goingToCloseForm && !ProMemory.isSyning) { - LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) + if (ProMemory.irisConfig.QueueIdentify.Count > 0) { - lock (ProMemory.irisConfig.Q4) + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "QueueIdentify:" + ProMemory.irisConfig.QueueIdentify.Count); + lock (ProMemory.irisConfig.QueueIdentify) { - if (ProMemory.irisConfig.Q4.Count > 0) + if (ProMemory.irisConfig.QueueIdentify.Count > 0) { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.QueueIdentify.Pop(); } } if (ProMemory.irisConfig.QualifiedIrisBuffer != null) @@ -58,8 +59,10 @@ //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; + // ProMemory.irisConfig.AssessThreadRun = false; + // ProMemory.irisConfig.EyeFinderThreadRun = false; + + ProMemory.identifyConfig.FlagFindingEye = false; if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); @@ -76,19 +79,19 @@ Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); } //匹配失败 - else - { - LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + //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); - } - + // 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.identifyConfig.InitConfig(); ProMemory.jobRuning = false; ProMemory.cameraController.ContinuousShot_TriggerOff(); diff --git a/irisRefactor/IrisThread/ImageQualityAssessTh.cs b/irisRefactor/IrisThread/ImageQualityAssessTh.cs index 0650491..f6d58e4 100644 --- a/irisRefactor/IrisThread/ImageQualityAssessTh.cs +++ b/irisRefactor/IrisThread/ImageQualityAssessTh.cs @@ -86,17 +86,17 @@ { if (score == 1) { - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); } } else if (score == 2) { - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Push(irisBytesL); - ProMemory.irisConfig.Q4.Push(irisBytesR); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesR); } } @@ -116,11 +116,11 @@ } } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - if (ProMemory.irisConfig.Q4.Count >= 30) + if (ProMemory.irisConfig.QueueIdentify.Count >= 30) { - ProMemory.irisConfig.Q4.Clear(); //手动控制堆栈容量 + ProMemory.irisConfig.QueueIdentify.Clear(); //手动控制堆栈容量 } } @@ -139,7 +139,7 @@ Form1.GetInstance().Failure(); } else { - Form2.GetInstance().failure(); + Form2.GetInstance().Failure(); } int time2 = ProMemory.appConfig.ShowTimeFailure; diff --git a/irisRefactor/IrisThread/PreIdentifyTh.cs b/irisRefactor/IrisThread/PreIdentifyTh.cs index 1ed042a..3ced240 100644 --- a/irisRefactor/IrisThread/PreIdentifyTh.cs +++ b/irisRefactor/IrisThread/PreIdentifyTh.cs @@ -1,4 +1,5 @@ using irisHelper; +using irisRefactor.FrmService; using System; using System.Diagnostics; using System.Reflection; @@ -24,18 +25,17 @@ { LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify Thread Started"); - //ProMemory.Tag_SleepTimer = 0; - //ProMemory.irisConfig.EyeFinderThreadRun = true; - // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); - // 没有在休眠中;没有数据同步中 - while (ProMemory.isWait == false && ProMemory.isSyning == false) + // 线程启动后,一直在运行中 + while (true) { - // 没有正在执行的找眼、识别线程 - if (ProMemory.identifyConfig.FlagFindingEye == false) + // 没有在休眠中;没有数据同步中 + if (ProMemory.isWait == false && ProMemory.isSyning == false && + ProMemory.identifyConfig.FlagFindingEye == true) { + // 取出来图像 if (ProMemory.irisConfig.QueueFace.Count > 0) { lock (ProMemory.irisConfig.QueueFace) @@ -46,294 +46,202 @@ } } - try + int eyeCount = 0; + int[] irisPos = new int[6]; + if (ProMemory.irisConfig.FaceBuffer != null) { - unsafe + // 执行找眼 + sw.Restart(); + eyeCount = this.ExeCaptureEye(ref irisPos); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "找眼[" + eyeCount + "个][耗时" + sw.ElapsedMilliseconds + "ms]"); + } + + if (eyeCount > 0) // 找到一个或者两个眼睛 + { + if (ProMemory.identifyConfig.IdentifyTaskId == "") // 不在识别过程中 { - // 申请内存,复制内存 - IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); - Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); + // 启动一次识别过程 + // 1.设置id + ProMemory.identifyConfig.StartIdentify(DateTime.Now.ToString("yyyyMMddHHmmss")); - // mark = 找到的眼睛数量 - int mark; - // 左右眼睛的定位参数:x,y,r - int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; - - fixed (int* pos = &posvec[0]) + // 启动识别线程 + // ProMemory.irisConfig.IdentifyThreadRun = true; + Thread identifyThread = new Thread(IdentifyTh.GetInstance.Identify) { - int* ptrPos = pos; + Name = "Identify Thread" + DateTime.Now.ToString("[yyyyMMddHHmmss]") + }; + identifyThread.Start(); - sw.Restart(); - mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 - sw.Stop(); - LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "找眼[" + mark + "]:" + sw.ElapsedMilliseconds); + //黄灯闪烁 + ProMemory.IoControllService.setYellowFlash(true); + Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + flashThrd.Start(); - int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; + } + else // 在识别过程中,继续评估,并将合格图像存入堆栈 + { + ProMemory.identifyConfig.CountTryIdentify++; // ★尝试识别计数器+1 - if (mark == 1 || mark == 2) + if (ProMemory.identifyConfig.CountTryIdentify > Convert.ToInt32(ConfigHelper.GetAppConfig("maxTryIdentify"))) // ★连续20次尝试未识别成功则识别失败 + { + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().Failure(); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + + // 将变量清零 + ProMemory.identifyConfig.InitConfig(); + } + } + + // 调用质量评估方法 + Byte[] irisBytesL = new byte[640 * 480]; + Byte[] irisBytesR = new byte[640 * 480]; + + sw.Restart(); + int score = this.ExeAssessFocus(irisPos, ref irisBytesL, ref irisBytesR); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "质量评估[" + score + "个][耗时" + sw.ElapsedMilliseconds + "ms]"); + + if (score == 1) + { + lock (ProMemory.irisConfig.QueueIdentify) + { + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); + } + } + else if (score == 2) + { + lock (ProMemory.irisConfig.QueueIdentify) + { + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesR); + } + } + } + else // 没找到眼 + { + if (ProMemory.identifyConfig.IdentifyTaskId == "") // 不在识别过程中 + { + ProMemory.identifyConfig.CountNoEyeLast++; // ★持续未找到眼计数器+1 + + if (ProMemory.identifyConfig.CountNoEyeLast > Convert.ToInt32(ConfigHelper.GetAppConfig("maxCountNoEyeLast"))) // ★连续200张图片未找到眼则待机 + { + ProMemory.identifyConfig.CountNoEyeLast = 0; // ★将持续未找到眼的控制变量清零 + if (ProMemory.m_bGrabbing) { - // 1.持续没有找到眼的计数器清零 - ProMemory.identifyConfig.CountNoEyeLast = 0; - - ProMemory.identifyConfig.FlagFoundEye = true; - - // 一次识别过程中首次找到眼,标记开始一次新的识别 - if (ProMemory.identifyConfig.IdentifyTaskId == "") + if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 { - 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(); + if (ProMemory.formType == "1") + Form1.GetInstance().ReInitializeToSleep(); + else if (ProMemory.formType == "2") + Form2.GetInstance().ReInitializeToSleep(); + Thread.Sleep(200); + ProMemory.cameraController.ContinuousShot_TriggerOn(); } - - // 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 + else //已再次触发,继续下一轮识别 { - 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.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "质量评估[" + score + "]:" + sw.ElapsedMilliseconds); - } - } + ProMemory.cameraController.ContinuousShot_TriggerOff(); } - - - 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 thIdentify = new Thread(IdentifyTh.GetInstance.Identify); - // thIdentify.Start(); - //} - - } - - Marshal.FreeHGlobal(ptrIrisFace); - } - else - { - ProMemory.identifyConfig.CountNoEyeLast++; } } } - } - catch (Exception ex) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); + else // 在某次识别过程中, + { + ProMemory.identifyConfig.CountTryIdentify++; // ★尝试识别计数器+1 + + if (ProMemory.identifyConfig.CountTryIdentify > Convert.ToInt32(ConfigHelper.GetAppConfig("maxTryIdentify"))) // ★连续20次尝试未识别成功则识别失败 + { + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().Failure(); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + + // 将变量清零 + ProMemory.identifyConfig.InitConfig(); + } + } } } + else + { + // 堆栈中没有图像则跳过 + continue; + } } } + } - //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(); - // } - // } + /** + * 调用找眼方法 + * 返回找到的眼睛数 + */ + private int ExeCaptureEye(ref int[] irisPos) + { + unsafe + { + IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); + Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); - // if (ProMemory.irisConfig.FaceBuffer != null) - // { - // unsafe - // { - // // 申请内存,复制内存 - // IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); - // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); + int mark = 0; + int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; - // // mark = 找到的眼睛数量 - // int mark; - // // 左右眼睛的定位参数:x,y,r - // int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; + fixed (int* pos = &posvec[0]) + { + int* ptrPos = pos; + mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); + for (int i = 0; i < irisPos.Length; i++) + { + irisPos[i] = ptrPos[i]; + } + } - // fixed (int* pos = &posvec[0]) - // { - // int* ptrPos = pos; + Marshal.FreeHGlobal(ptrFace); - // sw.Restart(); - // mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 - // sw.Stop(); - // LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + // 返回找到的眼睛数 + return mark; + } + } - // int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; + private int ExeAssessFocus(int[] irisPos, ref byte[] irisBytesL, ref byte[] irisBytesR) + { + int score = 0; - // // 找到1个或者2个眼睛 - // if (mark == 1 || mark == 2) - // { - // // 1.持续没有找到眼的计数器清零 - // ProMemory.identifyConfig.CountNoEyeLast = 0; + if (ProMemory.irisConfig.FaceBuffer != null) + { + 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; + score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 + } + } + } - // // 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); - // } - // } - // } + Marshal.FreeHGlobal(ptrIrisFace); + } - // 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); - //} + return score; } } } diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 7248348..111d6ce 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -39,6 +39,11 @@ + + + + + diff --git a/irisRefactor/FrmService/Form1.Designer.cs b/irisRefactor/FrmService/Form1.Designer.cs index 10555a6..dc76efe 100644 --- a/irisRefactor/FrmService/Form1.Designer.cs +++ b/irisRefactor/FrmService/Form1.Designer.cs @@ -451,6 +451,7 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Shown += new System.EventHandler(this.Form1_Shown); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index adbd758..77e5276 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -76,7 +76,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } @@ -150,9 +150,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -215,9 +215,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -749,5 +749,15 @@ return meanValue; } #endregion + + private void Form1_KeyUp(object sender, KeyEventArgs e) + { + if (Keys.Escape == e.KeyCode) + { + // 按键ESC,则退出程序 + LogHelper.WriteWarnLog(MethodBase.GetCurrentMethod().DeclaringType, "按下ESC键,退出"); + System.Environment.Exit(0); + } + } } } \ No newline at end of file diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index c5571c7..518d627 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -62,7 +62,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } catch (Exception ex) @@ -123,14 +123,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } ProMemory.irisConfig.IdentifyAccess = false; @@ -146,7 +146,7 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } @@ -185,14 +185,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } @@ -208,12 +208,12 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } - public void failure() + public void Failure() { if (ProMemory.isSyning) return; @@ -273,7 +273,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; @@ -338,21 +338,21 @@ bool hasPermisson = ProMemory.irisPermisionService.GetOpenDoorPermision(ProMemory.appConfig.AuthConfig, personId, devCode, out doorCode, out inoutType); - doorSound(hasPermisson); + DoorSound(hasPermisson); } else - noDoorSound(); + NoDoorSound(); //考勤 ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, "", devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { @@ -364,7 +364,7 @@ } - private void doorSound(bool hasPermisson) + private void DoorSound(bool hasPermisson) { //有权限 if (hasPermisson) @@ -382,7 +382,7 @@ } } - private void noDoorSound() + private void NoDoorSound() { //识别成功 PlaySound.recSuccess(); diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index ab18cb6..8638037 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -130,6 +130,13 @@ LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); + + // 初始化找眼预处理线程 + Thread thPreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes) + { + Name = "PreIdentifyThread" + DateTime.Now.ToString("[yyyyMMddHHmmss]") + }; + thPreIdentify.Start(); } catch (Exception e) { @@ -293,8 +300,7 @@ LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 - ProMemory.findingEyes = true; - ProMemory.identifyConfig.FlagWorking = true; + ProMemory.identifyConfig.FlagFindingEye = true; } catch (Exception ex) { diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs index 32e9240..9b1f4e0 100644 --- a/irisRefactor/IrisThread/IdentifyTh.cs +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -20,6 +20,7 @@ { LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); ProMemory.irisConfig.IdentifyAccess = true; + ProMemory.irisConfig.IdentifyThreadRun = true; // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); @@ -30,17 +31,17 @@ float iHammingDistance = 1; int iLeftRight = 0; - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + while (ProMemory.identifyConfig.IdentifyTaskId != "" && iMatchNumber == 0 && + !ProMemory.goingToCloseForm && !ProMemory.isSyning) { - LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) + if (ProMemory.irisConfig.QueueIdentify.Count > 0) { - lock (ProMemory.irisConfig.Q4) + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "QueueIdentify:" + ProMemory.irisConfig.QueueIdentify.Count); + lock (ProMemory.irisConfig.QueueIdentify) { - if (ProMemory.irisConfig.Q4.Count > 0) + if (ProMemory.irisConfig.QueueIdentify.Count > 0) { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.QueueIdentify.Pop(); } } if (ProMemory.irisConfig.QualifiedIrisBuffer != null) @@ -58,8 +59,10 @@ //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; + // ProMemory.irisConfig.AssessThreadRun = false; + // ProMemory.irisConfig.EyeFinderThreadRun = false; + + ProMemory.identifyConfig.FlagFindingEye = false; if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); @@ -76,19 +79,19 @@ Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); } //匹配失败 - else - { - LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + //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); - } - + // 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.identifyConfig.InitConfig(); ProMemory.jobRuning = false; ProMemory.cameraController.ContinuousShot_TriggerOff(); diff --git a/irisRefactor/IrisThread/ImageQualityAssessTh.cs b/irisRefactor/IrisThread/ImageQualityAssessTh.cs index 0650491..f6d58e4 100644 --- a/irisRefactor/IrisThread/ImageQualityAssessTh.cs +++ b/irisRefactor/IrisThread/ImageQualityAssessTh.cs @@ -86,17 +86,17 @@ { if (score == 1) { - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); } } else if (score == 2) { - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Push(irisBytesL); - ProMemory.irisConfig.Q4.Push(irisBytesR); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesR); } } @@ -116,11 +116,11 @@ } } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - if (ProMemory.irisConfig.Q4.Count >= 30) + if (ProMemory.irisConfig.QueueIdentify.Count >= 30) { - ProMemory.irisConfig.Q4.Clear(); //手动控制堆栈容量 + ProMemory.irisConfig.QueueIdentify.Clear(); //手动控制堆栈容量 } } @@ -139,7 +139,7 @@ Form1.GetInstance().Failure(); } else { - Form2.GetInstance().failure(); + Form2.GetInstance().Failure(); } int time2 = ProMemory.appConfig.ShowTimeFailure; diff --git a/irisRefactor/IrisThread/PreIdentifyTh.cs b/irisRefactor/IrisThread/PreIdentifyTh.cs index 1ed042a..3ced240 100644 --- a/irisRefactor/IrisThread/PreIdentifyTh.cs +++ b/irisRefactor/IrisThread/PreIdentifyTh.cs @@ -1,4 +1,5 @@ using irisHelper; +using irisRefactor.FrmService; using System; using System.Diagnostics; using System.Reflection; @@ -24,18 +25,17 @@ { LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify Thread Started"); - //ProMemory.Tag_SleepTimer = 0; - //ProMemory.irisConfig.EyeFinderThreadRun = true; - // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); - // 没有在休眠中;没有数据同步中 - while (ProMemory.isWait == false && ProMemory.isSyning == false) + // 线程启动后,一直在运行中 + while (true) { - // 没有正在执行的找眼、识别线程 - if (ProMemory.identifyConfig.FlagFindingEye == false) + // 没有在休眠中;没有数据同步中 + if (ProMemory.isWait == false && ProMemory.isSyning == false && + ProMemory.identifyConfig.FlagFindingEye == true) { + // 取出来图像 if (ProMemory.irisConfig.QueueFace.Count > 0) { lock (ProMemory.irisConfig.QueueFace) @@ -46,294 +46,202 @@ } } - try + int eyeCount = 0; + int[] irisPos = new int[6]; + if (ProMemory.irisConfig.FaceBuffer != null) { - unsafe + // 执行找眼 + sw.Restart(); + eyeCount = this.ExeCaptureEye(ref irisPos); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "找眼[" + eyeCount + "个][耗时" + sw.ElapsedMilliseconds + "ms]"); + } + + if (eyeCount > 0) // 找到一个或者两个眼睛 + { + if (ProMemory.identifyConfig.IdentifyTaskId == "") // 不在识别过程中 { - // 申请内存,复制内存 - IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); - Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); + // 启动一次识别过程 + // 1.设置id + ProMemory.identifyConfig.StartIdentify(DateTime.Now.ToString("yyyyMMddHHmmss")); - // mark = 找到的眼睛数量 - int mark; - // 左右眼睛的定位参数:x,y,r - int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; - - fixed (int* pos = &posvec[0]) + // 启动识别线程 + // ProMemory.irisConfig.IdentifyThreadRun = true; + Thread identifyThread = new Thread(IdentifyTh.GetInstance.Identify) { - int* ptrPos = pos; + Name = "Identify Thread" + DateTime.Now.ToString("[yyyyMMddHHmmss]") + }; + identifyThread.Start(); - sw.Restart(); - mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 - sw.Stop(); - LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "找眼[" + mark + "]:" + sw.ElapsedMilliseconds); + //黄灯闪烁 + ProMemory.IoControllService.setYellowFlash(true); + Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + flashThrd.Start(); - int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; + } + else // 在识别过程中,继续评估,并将合格图像存入堆栈 + { + ProMemory.identifyConfig.CountTryIdentify++; // ★尝试识别计数器+1 - if (mark == 1 || mark == 2) + if (ProMemory.identifyConfig.CountTryIdentify > Convert.ToInt32(ConfigHelper.GetAppConfig("maxTryIdentify"))) // ★连续20次尝试未识别成功则识别失败 + { + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().Failure(); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + + // 将变量清零 + ProMemory.identifyConfig.InitConfig(); + } + } + + // 调用质量评估方法 + Byte[] irisBytesL = new byte[640 * 480]; + Byte[] irisBytesR = new byte[640 * 480]; + + sw.Restart(); + int score = this.ExeAssessFocus(irisPos, ref irisBytesL, ref irisBytesR); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "质量评估[" + score + "个][耗时" + sw.ElapsedMilliseconds + "ms]"); + + if (score == 1) + { + lock (ProMemory.irisConfig.QueueIdentify) + { + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); + } + } + else if (score == 2) + { + lock (ProMemory.irisConfig.QueueIdentify) + { + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesR); + } + } + } + else // 没找到眼 + { + if (ProMemory.identifyConfig.IdentifyTaskId == "") // 不在识别过程中 + { + ProMemory.identifyConfig.CountNoEyeLast++; // ★持续未找到眼计数器+1 + + if (ProMemory.identifyConfig.CountNoEyeLast > Convert.ToInt32(ConfigHelper.GetAppConfig("maxCountNoEyeLast"))) // ★连续200张图片未找到眼则待机 + { + ProMemory.identifyConfig.CountNoEyeLast = 0; // ★将持续未找到眼的控制变量清零 + if (ProMemory.m_bGrabbing) { - // 1.持续没有找到眼的计数器清零 - ProMemory.identifyConfig.CountNoEyeLast = 0; - - ProMemory.identifyConfig.FlagFoundEye = true; - - // 一次识别过程中首次找到眼,标记开始一次新的识别 - if (ProMemory.identifyConfig.IdentifyTaskId == "") + if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 { - 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(); + if (ProMemory.formType == "1") + Form1.GetInstance().ReInitializeToSleep(); + else if (ProMemory.formType == "2") + Form2.GetInstance().ReInitializeToSleep(); + Thread.Sleep(200); + ProMemory.cameraController.ContinuousShot_TriggerOn(); } - - // 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 + else //已再次触发,继续下一轮识别 { - 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.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "质量评估[" + score + "]:" + sw.ElapsedMilliseconds); - } - } + ProMemory.cameraController.ContinuousShot_TriggerOff(); } - - - 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 thIdentify = new Thread(IdentifyTh.GetInstance.Identify); - // thIdentify.Start(); - //} - - } - - Marshal.FreeHGlobal(ptrIrisFace); - } - else - { - ProMemory.identifyConfig.CountNoEyeLast++; } } } - } - catch (Exception ex) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); + else // 在某次识别过程中, + { + ProMemory.identifyConfig.CountTryIdentify++; // ★尝试识别计数器+1 + + if (ProMemory.identifyConfig.CountTryIdentify > Convert.ToInt32(ConfigHelper.GetAppConfig("maxTryIdentify"))) // ★连续20次尝试未识别成功则识别失败 + { + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().Failure(); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + + // 将变量清零 + ProMemory.identifyConfig.InitConfig(); + } + } } } + else + { + // 堆栈中没有图像则跳过 + continue; + } } } + } - //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(); - // } - // } + /** + * 调用找眼方法 + * 返回找到的眼睛数 + */ + private int ExeCaptureEye(ref int[] irisPos) + { + unsafe + { + IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); + Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); - // if (ProMemory.irisConfig.FaceBuffer != null) - // { - // unsafe - // { - // // 申请内存,复制内存 - // IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); - // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); + int mark = 0; + int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; - // // mark = 找到的眼睛数量 - // int mark; - // // 左右眼睛的定位参数:x,y,r - // int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; + fixed (int* pos = &posvec[0]) + { + int* ptrPos = pos; + mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); + for (int i = 0; i < irisPos.Length; i++) + { + irisPos[i] = ptrPos[i]; + } + } - // fixed (int* pos = &posvec[0]) - // { - // int* ptrPos = pos; + Marshal.FreeHGlobal(ptrFace); - // sw.Restart(); - // mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 - // sw.Stop(); - // LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + // 返回找到的眼睛数 + return mark; + } + } - // int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; + private int ExeAssessFocus(int[] irisPos, ref byte[] irisBytesL, ref byte[] irisBytesR) + { + int score = 0; - // // 找到1个或者2个眼睛 - // if (mark == 1 || mark == 2) - // { - // // 1.持续没有找到眼的计数器清零 - // ProMemory.identifyConfig.CountNoEyeLast = 0; + if (ProMemory.irisConfig.FaceBuffer != null) + { + 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; + score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 + } + } + } - // // 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); - // } - // } - // } + Marshal.FreeHGlobal(ptrIrisFace); + } - // 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); - //} + return score; } } } diff --git a/irisRefactor/IrisThread/SaveImageTh.cs b/irisRefactor/IrisThread/SaveImageTh.cs index f0ec820..e58e150 100644 --- a/irisRefactor/IrisThread/SaveImageTh.cs +++ b/irisRefactor/IrisThread/SaveImageTh.cs @@ -40,9 +40,6 @@ // 条件:未在待机状态 if (ProMemory.isWait == false) { - // 开启工作线程 - ProMemory.identifyConfig.FlagWorking = true; - try { // 将图片放入堆栈1 diff --git a/irisMemory/IdentifyConfig.cs b/irisMemory/IdentifyConfig.cs index c025b36..0453007 100644 --- a/irisMemory/IdentifyConfig.cs +++ b/irisMemory/IdentifyConfig.cs @@ -1,20 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - + namespace irisMemory { public class IdentifyConfig { - // =1时表示在工作,拍图; - // =0时表示终端待机 - private volatile bool flagWorking; // 是否在拍图,是否在工作标志位 - private volatile bool flagFindingEye; // 是否正在找眼标志位 + /** + * ★是否允许找眼标志位 + * =1表示允许;=0表示退出 + */ + private volatile bool flagFindingEye; private volatile bool flagFoundEye; // 是否找到合格眼睛标志位,用于表示是否进入识别过程 - private int countNoEyeLast; // 进入识别过程前,连续没找到眼的次数 + /** + * ★进入识别过程前,连续没找到眼的次数 + */ + private volatile int countNoEyeLast; + /** + * ★进入识别后,尝试找眼及识别次数 + */ + private volatile int countTryIdentify; + + /** + * ★识别过程id + * ="" 表示不在识别过程中;不为空表示在识别过程中,值为找到眼的时刻值 + */ private string identifyTaskId; // 一次识别过程的id private IdentifyConfig() @@ -27,24 +36,36 @@ */ public void InitConfig() { - this.FlagWorking = false; this.FlagFindingEye = false; this.FlagFoundEye = false; this.CountNoEyeLast = 0; + this.CountTryIdentify = 0; this.IdentifyTaskId = ""; } + /** + * 开始一次识别过程 + */ + public void StartIdentify(string taskId) + { + this.CountNoEyeLast = 0; + this.countTryIdentify = 0; + + this.IdentifyTaskId = taskId; + } + private static readonly IdentifyConfig identifyConfig = new IdentifyConfig(); 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 int CountTryIdentify { get => countTryIdentify; set => countTryIdentify = value; } public string IdentifyTaskId { get => identifyTaskId; set => identifyTaskId = value; } + } } diff --git a/irisMemory/IrisConfig.cs b/irisMemory/IrisConfig.cs index d4188d5..453e9b1 100644 --- a/irisMemory/IrisConfig.cs +++ b/irisMemory/IrisConfig.cs @@ -10,7 +10,7 @@ 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,供虹膜识别 */ + private static Stack queueIdentify; /* 队列4:用于存放质量合格的眼部图像640*480,供虹膜识别 */ private byte[] faceBuffer; /* 用于保存相机采集的面部图像,从q1中取得 */ private byte[] irisFaceBuffer; /* 用于保存搜到眼睛的面部图像,从q2中取得 */ @@ -70,16 +70,16 @@ } } - public Stack Q4 + public Stack QueueIdentify { get { - return q4; + return queueIdentify; } set { - q4 = value; + queueIdentify = value; } } @@ -231,7 +231,7 @@ QueueFace = new Stack(); Q2 = new Stack(); Q3 = new Stack(); - Q4 = new Stack(); + QueueIdentify = new Stack(); FaceBuffer = new byte[1280 * 960]; IrisFaceBuffer = new byte[1280 * 960]; IrisPosBuffer = new int[3]; diff --git a/irisRefactor/App.config b/irisRefactor/App.config index 7248348..111d6ce 100644 --- a/irisRefactor/App.config +++ b/irisRefactor/App.config @@ -39,6 +39,11 @@ + + + + + diff --git a/irisRefactor/FrmService/Form1.Designer.cs b/irisRefactor/FrmService/Form1.Designer.cs index 10555a6..dc76efe 100644 --- a/irisRefactor/FrmService/Form1.Designer.cs +++ b/irisRefactor/FrmService/Form1.Designer.cs @@ -451,6 +451,7 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Shown += new System.EventHandler(this.Form1_Shown); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); diff --git a/irisRefactor/FrmService/Form1.cs b/irisRefactor/FrmService/Form1.cs index adbd758..77e5276 100644 --- a/irisRefactor/FrmService/Form1.cs +++ b/irisRefactor/FrmService/Form1.cs @@ -76,7 +76,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } @@ -150,9 +150,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -215,9 +215,9 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) @@ -749,5 +749,15 @@ return meanValue; } #endregion + + private void Form1_KeyUp(object sender, KeyEventArgs e) + { + if (Keys.Escape == e.KeyCode) + { + // 按键ESC,则退出程序 + LogHelper.WriteWarnLog(MethodBase.GetCurrentMethod().DeclaringType, "按下ESC键,退出"); + System.Environment.Exit(0); + } + } } } \ No newline at end of file diff --git a/irisRefactor/FrmService/Form2.cs b/irisRefactor/FrmService/Form2.cs index c5571c7..518d627 100644 --- a/irisRefactor/FrmService/Form2.cs +++ b/irisRefactor/FrmService/Form2.cs @@ -62,7 +62,7 @@ { try { - ProMemory.close(); + ProMemory.Close(); Environment.Exit(0); } catch (Exception ex) @@ -123,14 +123,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } ProMemory.irisConfig.IdentifyAccess = false; @@ -146,7 +146,7 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } @@ -185,14 +185,14 @@ { ProMemory.irisConfig.Q3.Clear(); } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Clear(); + ProMemory.irisConfig.QueueIdentify.Clear(); } } catch (Exception ee) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "errorerrorerror : clear q1/q2/q3/q4 :" + ee.Message); } @@ -208,12 +208,12 @@ catch (Exception ex) { string msg = "初始化失败!" + ex.Message; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } } - public void failure() + public void Failure() { if (ProMemory.isSyning) return; @@ -273,7 +273,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; @@ -338,21 +338,21 @@ bool hasPermisson = ProMemory.irisPermisionService.GetOpenDoorPermision(ProMemory.appConfig.AuthConfig, personId, devCode, out doorCode, out inoutType); - doorSound(hasPermisson); + DoorSound(hasPermisson); } else - noDoorSound(); + NoDoorSound(); //考勤 ProMemory.irisRecordsService.insertRecordsLocal(personId, dtNow, "", devCode, doorCode, inoutType); - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, ProMemory.stringBuilder.ToString()); } catch (Exception e) { - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "success:" + e.Message); } finally { @@ -364,7 +364,7 @@ } - private void doorSound(bool hasPermisson) + private void DoorSound(bool hasPermisson) { //有权限 if (hasPermisson) @@ -382,7 +382,7 @@ } } - private void noDoorSound() + private void NoDoorSound() { //识别成功 PlaySound.recSuccess(); diff --git a/irisRefactor/IrisCamera/CameraController.cs b/irisRefactor/IrisCamera/CameraController.cs index ab18cb6..8638037 100644 --- a/irisRefactor/IrisCamera/CameraController.cs +++ b/irisRefactor/IrisCamera/CameraController.cs @@ -130,6 +130,13 @@ LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "CAMERA,START"); ContinuousShot_TriggerOff(); + + // 初始化找眼预处理线程 + Thread thPreIdentify = new Thread(PreIdentifyTh.GetInstance.FindEyes) + { + Name = "PreIdentifyThread" + DateTime.Now.ToString("[yyyyMMddHHmmss]") + }; + thPreIdentify.Start(); } catch (Exception e) { @@ -293,8 +300,7 @@ LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); // 最重要的操作,将findingEyes的变量设置为true,表示可以开始找眼 - ProMemory.findingEyes = true; - ProMemory.identifyConfig.FlagWorking = true; + ProMemory.identifyConfig.FlagFindingEye = true; } catch (Exception ex) { diff --git a/irisRefactor/IrisThread/IdentifyTh.cs b/irisRefactor/IrisThread/IdentifyTh.cs index 32e9240..9b1f4e0 100644 --- a/irisRefactor/IrisThread/IdentifyTh.cs +++ b/irisRefactor/IrisThread/IdentifyTh.cs @@ -20,6 +20,7 @@ { LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started"); ProMemory.irisConfig.IdentifyAccess = true; + ProMemory.irisConfig.IdentifyThreadRun = true; // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); @@ -30,17 +31,17 @@ float iHammingDistance = 1; int iLeftRight = 0; - while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 && - ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning) + while (ProMemory.identifyConfig.IdentifyTaskId != "" && iMatchNumber == 0 && + !ProMemory.goingToCloseForm && !ProMemory.isSyning) { - LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count); - if (ProMemory.irisConfig.Q4.Count > 0) + if (ProMemory.irisConfig.QueueIdentify.Count > 0) { - lock (ProMemory.irisConfig.Q4) + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "QueueIdentify:" + ProMemory.irisConfig.QueueIdentify.Count); + lock (ProMemory.irisConfig.QueueIdentify) { - if (ProMemory.irisConfig.Q4.Count > 0) + if (ProMemory.irisConfig.QueueIdentify.Count > 0) { - ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop(); + ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.QueueIdentify.Pop(); } } if (ProMemory.irisConfig.QualifiedIrisBuffer != null) @@ -58,8 +59,10 @@ //跳出循环,条件是时间到、匹配成功或者正在关闭程序 - ProMemory.irisConfig.AssessThreadRun = false; - ProMemory.irisConfig.EyeFinderThreadRun = false; + // ProMemory.irisConfig.AssessThreadRun = false; + // ProMemory.irisConfig.EyeFinderThreadRun = false; + + ProMemory.identifyConfig.FlagFindingEye = false; if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); @@ -76,19 +79,19 @@ Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess); } //匹配失败 - else - { - LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + //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); - } - + // 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.identifyConfig.InitConfig(); ProMemory.jobRuning = false; ProMemory.cameraController.ContinuousShot_TriggerOff(); diff --git a/irisRefactor/IrisThread/ImageQualityAssessTh.cs b/irisRefactor/IrisThread/ImageQualityAssessTh.cs index 0650491..f6d58e4 100644 --- a/irisRefactor/IrisThread/ImageQualityAssessTh.cs +++ b/irisRefactor/IrisThread/ImageQualityAssessTh.cs @@ -86,17 +86,17 @@ { if (score == 1) { - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); } } else if (score == 2) { - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - ProMemory.irisConfig.Q4.Push(irisBytesL); - ProMemory.irisConfig.Q4.Push(irisBytesR); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesR); } } @@ -116,11 +116,11 @@ } } - lock (ProMemory.irisConfig.Q4) + lock (ProMemory.irisConfig.QueueIdentify) { - if (ProMemory.irisConfig.Q4.Count >= 30) + if (ProMemory.irisConfig.QueueIdentify.Count >= 30) { - ProMemory.irisConfig.Q4.Clear(); //手动控制堆栈容量 + ProMemory.irisConfig.QueueIdentify.Clear(); //手动控制堆栈容量 } } @@ -139,7 +139,7 @@ Form1.GetInstance().Failure(); } else { - Form2.GetInstance().failure(); + Form2.GetInstance().Failure(); } int time2 = ProMemory.appConfig.ShowTimeFailure; diff --git a/irisRefactor/IrisThread/PreIdentifyTh.cs b/irisRefactor/IrisThread/PreIdentifyTh.cs index 1ed042a..3ced240 100644 --- a/irisRefactor/IrisThread/PreIdentifyTh.cs +++ b/irisRefactor/IrisThread/PreIdentifyTh.cs @@ -1,4 +1,5 @@ using irisHelper; +using irisRefactor.FrmService; using System; using System.Diagnostics; using System.Reflection; @@ -24,18 +25,17 @@ { LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "PreIdentify Thread Started"); - //ProMemory.Tag_SleepTimer = 0; - //ProMemory.irisConfig.EyeFinderThreadRun = true; - // 用于计算操作耗时 Stopwatch sw = new Stopwatch(); - // 没有在休眠中;没有数据同步中 - while (ProMemory.isWait == false && ProMemory.isSyning == false) + // 线程启动后,一直在运行中 + while (true) { - // 没有正在执行的找眼、识别线程 - if (ProMemory.identifyConfig.FlagFindingEye == false) + // 没有在休眠中;没有数据同步中 + if (ProMemory.isWait == false && ProMemory.isSyning == false && + ProMemory.identifyConfig.FlagFindingEye == true) { + // 取出来图像 if (ProMemory.irisConfig.QueueFace.Count > 0) { lock (ProMemory.irisConfig.QueueFace) @@ -46,294 +46,202 @@ } } - try + int eyeCount = 0; + int[] irisPos = new int[6]; + if (ProMemory.irisConfig.FaceBuffer != null) { - unsafe + // 执行找眼 + sw.Restart(); + eyeCount = this.ExeCaptureEye(ref irisPos); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "找眼[" + eyeCount + "个][耗时" + sw.ElapsedMilliseconds + "ms]"); + } + + if (eyeCount > 0) // 找到一个或者两个眼睛 + { + if (ProMemory.identifyConfig.IdentifyTaskId == "") // 不在识别过程中 { - // 申请内存,复制内存 - IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); - Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); + // 启动一次识别过程 + // 1.设置id + ProMemory.identifyConfig.StartIdentify(DateTime.Now.ToString("yyyyMMddHHmmss")); - // mark = 找到的眼睛数量 - int mark; - // 左右眼睛的定位参数:x,y,r - int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; - - fixed (int* pos = &posvec[0]) + // 启动识别线程 + // ProMemory.irisConfig.IdentifyThreadRun = true; + Thread identifyThread = new Thread(IdentifyTh.GetInstance.Identify) { - int* ptrPos = pos; + Name = "Identify Thread" + DateTime.Now.ToString("[yyyyMMddHHmmss]") + }; + identifyThread.Start(); - sw.Restart(); - mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 - sw.Stop(); - LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "找眼[" + mark + "]:" + sw.ElapsedMilliseconds); + //黄灯闪烁 + ProMemory.IoControllService.setYellowFlash(true); + Thread flashThrd = new Thread(ProMemory.IoControllService.YellowFlash); + flashThrd.Start(); - int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; + } + else // 在识别过程中,继续评估,并将合格图像存入堆栈 + { + ProMemory.identifyConfig.CountTryIdentify++; // ★尝试识别计数器+1 - if (mark == 1 || mark == 2) + if (ProMemory.identifyConfig.CountTryIdentify > Convert.ToInt32(ConfigHelper.GetAppConfig("maxTryIdentify"))) // ★连续20次尝试未识别成功则识别失败 + { + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().Failure(); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + + // 将变量清零 + ProMemory.identifyConfig.InitConfig(); + } + } + + // 调用质量评估方法 + Byte[] irisBytesL = new byte[640 * 480]; + Byte[] irisBytesR = new byte[640 * 480]; + + sw.Restart(); + int score = this.ExeAssessFocus(irisPos, ref irisBytesL, ref irisBytesR); + sw.Stop(); + LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "质量评估[" + score + "个][耗时" + sw.ElapsedMilliseconds + "ms]"); + + if (score == 1) + { + lock (ProMemory.irisConfig.QueueIdentify) + { + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); + } + } + else if (score == 2) + { + lock (ProMemory.irisConfig.QueueIdentify) + { + ProMemory.irisConfig.QueueIdentify.Push(irisBytesL); + ProMemory.irisConfig.QueueIdentify.Push(irisBytesR); + } + } + } + else // 没找到眼 + { + if (ProMemory.identifyConfig.IdentifyTaskId == "") // 不在识别过程中 + { + ProMemory.identifyConfig.CountNoEyeLast++; // ★持续未找到眼计数器+1 + + if (ProMemory.identifyConfig.CountNoEyeLast > Convert.ToInt32(ConfigHelper.GetAppConfig("maxCountNoEyeLast"))) // ★连续200张图片未找到眼则待机 + { + ProMemory.identifyConfig.CountNoEyeLast = 0; // ★将持续未找到眼的控制变量清零 + if (ProMemory.m_bGrabbing) { - // 1.持续没有找到眼的计数器清零 - ProMemory.identifyConfig.CountNoEyeLast = 0; - - ProMemory.identifyConfig.FlagFoundEye = true; - - // 一次识别过程中首次找到眼,标记开始一次新的识别 - if (ProMemory.identifyConfig.IdentifyTaskId == "") + if (ProMemory.IoControllService.getSensorVal() == 0) //未再次触发,待机 { - 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(); + if (ProMemory.formType == "1") + Form1.GetInstance().ReInitializeToSleep(); + else if (ProMemory.formType == "2") + Form2.GetInstance().ReInitializeToSleep(); + Thread.Sleep(200); + ProMemory.cameraController.ContinuousShot_TriggerOn(); } - - // 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 + else //已再次触发,继续下一轮识别 { - 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.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "质量评估[" + score + "]:" + sw.ElapsedMilliseconds); - } - } + ProMemory.cameraController.ContinuousShot_TriggerOff(); } - - - 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 thIdentify = new Thread(IdentifyTh.GetInstance.Identify); - // thIdentify.Start(); - //} - - } - - Marshal.FreeHGlobal(ptrIrisFace); - } - else - { - ProMemory.identifyConfig.CountNoEyeLast++; } } } - } - catch (Exception ex) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "眼睛搜索线程CatchError:" + ex); + else // 在某次识别过程中, + { + ProMemory.identifyConfig.CountTryIdentify++; // ★尝试识别计数器+1 + + if (ProMemory.identifyConfig.CountTryIdentify > Convert.ToInt32(ConfigHelper.GetAppConfig("maxTryIdentify"))) // ★连续20次尝试未识别成功则识别失败 + { + if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority) + ProMemory.tempRegion = Form1.GetInstance().obtainTemp(); + + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString()); + + if (ProMemory.formType == "1") + Form1.GetInstance().Failure(); + else if (ProMemory.formType == "2") + Form2.GetInstance().Failure(); + Thread.Sleep(ProMemory.appConfig.ShowTimeFailure); + + // 将变量清零 + ProMemory.identifyConfig.InitConfig(); + } + } } } + else + { + // 堆栈中没有图像则跳过 + continue; + } } } + } - //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(); - // } - // } + /** + * 调用找眼方法 + * 返回找到的眼睛数 + */ + private int ExeCaptureEye(ref int[] irisPos) + { + unsafe + { + IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); + Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); - // if (ProMemory.irisConfig.FaceBuffer != null) - // { - // unsafe - // { - // // 申请内存,复制内存 - // IntPtr ptrFace = Marshal.AllocHGlobal(1280 * 960); - // Marshal.Copy(ProMemory.irisConfig.FaceBuffer, 0, ptrFace, 1280 * 960); + int mark = 0; + int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; - // // mark = 找到的眼睛数量 - // int mark; - // // 左右眼睛的定位参数:x,y,r - // int[] posvec = new int[] { 0, 0, 0, 0, 0, 0 }; + fixed (int* pos = &posvec[0]) + { + int* ptrPos = pos; + mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); + for (int i = 0; i < irisPos.Length; i++) + { + irisPos[i] = ptrPos[i]; + } + } - // fixed (int* pos = &posvec[0]) - // { - // int* ptrPos = pos; + Marshal.FreeHGlobal(ptrFace); - // sw.Restart(); - // mark = ProMemory.CaptureEye_Rec(ptrFace, ref ptrPos); // 调用找眼算法 - // sw.Stop(); - // LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "执行一次找眼操作[" + mark + "]:" + sw.ElapsedMilliseconds); + // 返回找到的眼睛数 + return mark; + } + } - // int[] irisPos = { ptrPos[0], ptrPos[1], ptrPos[2], ptrPos[3], ptrPos[4], ptrPos[5] }; + private int ExeAssessFocus(int[] irisPos, ref byte[] irisBytesL, ref byte[] irisBytesR) + { + int score = 0; - // // 找到1个或者2个眼睛 - // if (mark == 1 || mark == 2) - // { - // // 1.持续没有找到眼的计数器清零 - // ProMemory.identifyConfig.CountNoEyeLast = 0; + if (ProMemory.irisConfig.FaceBuffer != null) + { + 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; + score = ProMemory.AssessFocus_Rec(ptrIrisFace, irisPos, ref ptrIrisL, ref ptrIrisR); //质量评估 0均不合格 1一幅合格 2均合格 + } + } + } - // // 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); - // } - // } - // } + Marshal.FreeHGlobal(ptrIrisFace); + } - // 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); - //} + return score; } } } diff --git a/irisRefactor/IrisThread/SaveImageTh.cs b/irisRefactor/IrisThread/SaveImageTh.cs index f0ec820..e58e150 100644 --- a/irisRefactor/IrisThread/SaveImageTh.cs +++ b/irisRefactor/IrisThread/SaveImageTh.cs @@ -40,9 +40,6 @@ // 条件:未在待机状态 if (ProMemory.isWait == false) { - // 开启工作线程 - ProMemory.identifyConfig.FlagWorking = true; - try { // 将图片放入堆栈1 diff --git a/irisRefactor/ProMemory.cs b/irisRefactor/ProMemory.cs index 1063f21..49a760f 100644 --- a/irisRefactor/ProMemory.cs +++ b/irisRefactor/ProMemory.cs @@ -7,7 +7,6 @@ using irisMemory; using irisRefactor.IrisCamera; using irisRefactor.IrisScoket; -using irisRefactor.IrisThread; using MvCamCtrl.NET; using System; using System.Net; @@ -99,29 +98,22 @@ proConfig.PDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST(); timerCamera = new System.Windows.Forms.Timer(); timerCamera.Tick += new EventHandler(cameraController.TimerCamera_Tick); - timerCamera.Interval = 3000; + timerCamera.Interval = 3000; // 延时3000ms执行 timerCamera.Start(); //初始化门禁,若有权限链接串口 DoorSystem doorSystem = new DoorSystem(); //数据库链接 - Thread connectServerThread = new Thread(connectDatabase); + 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); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, ex.Message); } } - private static void connectDatabase() + private static void ConnectDatabase() { if (DatabaseLocal.OpenDB(appConfig.DbLocalConfig) == 0) { @@ -142,10 +134,10 @@ socket.start(); string msg = "初始化数据库连接成功"; - LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, msg); + LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, msg); } - public static void close() { + public static void Close() { goingToCloseForm = true; irisConfig.IdentifyThreadRun = false;