Newer
Older
IRIS_REFACTOR / irisRefactor / IrisThread / IdentifyTh.cs
using irisHelper;
using irisRefactor.FrmService;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading;

namespace irisRefactor.IrisThread
{
    public class IdentifyTh
    {
        private static readonly IdentifyTh identiyfTh = new IdentifyTh();
        private IdentifyTh() { }
        public static IdentifyTh GetInstance
        {
            get => identiyfTh;
        }

        public void Identify()
        {
            LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "Identify Thread Started");
            ProMemory.irisConfig.IdentifyAccess = true;

            // 用于计算操作耗时
            Stopwatch sw = new Stopwatch();

            try
            {
                int iMatchNumber = 0;
                float iHammingDistance = 1;
                int iLeftRight = 0;

                while (ProMemory.irisConfig.IdentifyThreadRun == true && iMatchNumber == 0 &&
                    ProMemory.Tag_IdentifyTimer == 0 && !ProMemory.goingToCloseForm && !ProMemory.isSyning)
                {
                    LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "Q4:" + ProMemory.irisConfig.Q4.Count);
                    if (ProMemory.irisConfig.Q4.Count > 0)
                    {
                        lock (ProMemory.irisConfig.Q4)
                        {
                            if (ProMemory.irisConfig.Q4.Count > 0)
                            {
                                ProMemory.irisConfig.QualifiedIrisBuffer = ProMemory.irisConfig.Q4.Pop();
                            }
                        }
                        if (ProMemory.irisConfig.QualifiedIrisBuffer != null)
                        {
                            //加载匹配列表
                            sw.Restart();
                            iMatchNumber = ProMemory.proConfig.CodeListMgr.MatchOneEye(ProMemory.irisConfig.QualifiedIrisBuffer, out iHammingDistance, out iLeftRight);
                            sw.Stop();
                            LogHelper.WriteDebugLog(MethodBase.GetCurrentMethod().DeclaringType, "识别[" + iMatchNumber + "]:" + sw.ElapsedMilliseconds);
                        }
                    }
                }

                // ProMemory.timer2.Dispose();//停止计时器

                
                //跳出循环,条件是时间到、匹配成功或者正在关闭程序      
                ProMemory.irisConfig.AssessThreadRun = false;
                ProMemory.irisConfig.EyeFinderThreadRun = false;

                if (ProMemory.appConfig.AuthConfig.HasTempDtAuthority)
                   ProMemory.tempRegion = Form1.GetInstance().obtainTemp();

                //匹配成功
                if (iMatchNumber > 0)
                {
                    string personId = ProMemory.proConfig.CodeListMgr.GetUserForIndex(iMatchNumber);//personId                  
                    if (ProMemory.formType == "1")
                        Form1.GetInstance().Success(personId);
                    else if (ProMemory.formType == "2")
                        Form2.GetInstance().Success(personId);
                    //int time = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeSuccess"));
                    Thread.Sleep(ProMemory.appConfig.ShowTimeSuccess);
                }
                //匹配失败
                else
                {
                    LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "未知人员温度:" + ProMemory.tempString.ToString());

                    if (ProMemory.formType == "1")
                        Form1.GetInstance().Failure();
                    else if (ProMemory.formType == "2")
                        Form2.GetInstance().failure();
                    //int time2 = Convert.ToInt32(ConfigHelper.GetAppConfig("showTimeFailure"));
                    Thread.Sleep(ProMemory.appConfig.ShowTimeFailure);
                }
                

                ProMemory.jobRuning = false;
                ProMemory.cameraController.ContinuousShot_TriggerOff();

            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, "虹膜匹配线程CatchError:" + ex);
            }
        }


    }
}