Exemple #1
0
        public void SetIdentifyResults(IdentifyResults _IdentifyResults)
        {
            image_capImage.Source = _IdentifyResults.CapImg;
            image_cmpImage.Source = _IdentifyResults.RegImg;
            long     _longtime = _IdentifyResults.Info.Time;
            DateTime s         = new DateTime(1970, 1, 1);

            s = s.AddSeconds(_longtime);
            label_Socre.Text        = label_Socre.Text.ToString().Replace("Socre", _IdentifyResults.Info.Score + "");
            label_TemplateName.Text = label_TemplateName.Text.ToString().Replace("TemplateName", _IdentifyResults.Info.Name);
            label_TemplateType.Text = label_TemplateType.Text.ToString().Replace("TemplateType", _IdentifyResults.TemplateType);
            label_CapTime.Text      = s.ToString("yyyy/MM/dd HH:mm:ss");
            label_CapChannel.Text   = label_CapChannel.Text.ToString().Replace("CapChannel", _IdentifyResults.ChannelName);
            List <byte[]> senceImg = thirft.QuerySenceImg(_IdentifyResults.ID, s.ToString("yyyy/MM/dd HH:mm:ss").Split(' ')[0].Replace("/", "").Replace("/", ""));

            if (senceImg != null && senceImg.Count > 0 && senceImg[0].Length > 0)
            {
                BitmapImage bitImage = new BitmapImage();
                bitImage.BeginInit();
                bitImage.StreamSource = new System.IO.MemoryStream(senceImg[0]);
                bitImage.EndInit();
                image_SenceImg.Source = bitImage;
            }
            else
            {
                MyMessage.showYes("获取抓拍实时帧失败!");
            }
        }
Exemple #2
0
        public override SpeechIdentifier.Result Post()
        {
            if (IsSessionOpen && !IsSessionClosing)
            {
                IdentifyResults.Clear();

                Uri uri = Configuration.Server.BuildEndpoint(URI_PATH_PROCESS);

                Logger?.LogDebug("SpeechIdentifier_HttpClient_Version1.Post(): URI: " + uri.ToString());

                using (var request = BuildRequest(CallMode.Process, uri))
                {
                    try
                    {
                        var responseTask = mHttpClient.SendAsync(request);

                        responseTask.RunSynchronously();

                        var resultTask = HandleResponse(CallMode.Process, request, responseTask.Result);

                        resultTask.RunSynchronously();
                    }
                    catch (HttpRequestException ex)
                    {
                        IdentifyResult = SpeechIdentifier.Result.Timeout;
                        Logger?.LogError(ex);
                    }
                    return(IdentifyResult);
                }
            }
            return(IdentifyResult = SpeechIdentifier.Result.Invalid);
        }
Exemple #3
0
 public void SetIdentifyResults(IdentifyResults _IdentifyResults)
 {
     try
     {
         image_capImage.Source = _IdentifyResults.CapImg;
         image_cmpImage.Source = _IdentifyResults.RegImg;
         long     _longtime = _IdentifyResults.NewRci.Time;
         DateTime s         = new DateTime(1970, 1, 1);
         s = s.AddSeconds(_longtime);
         label_Socre.Text        = label_Socre.Text.ToString().Replace("Socre", _IdentifyResults.NewRci.Score + "");
         label_TemplateName.Text = label_TemplateName.Text.ToString().Replace("TemplateName", _IdentifyResults.NewRci.Name);
         label_TemplateType.Text = label_TemplateType.Text.ToString().Replace("TemplateType", _IdentifyResults.TemplateType);
         label_CapTime.Text      = s.ToString("yyyy/MM/dd HH:mm:ss");
         label_CapChannel.Text   = label_CapChannel.Text.ToString().Replace("CapChannel", _IdentifyResults.ChannelName);
         List <byte[]> senceImg = thirft.QuerySenceImg(_IdentifyResults.ID, s.ToString("yyyy/MM/dd HH:mm:ss").Split(' ')[0].Replace("/", "").Replace("/", ""));
         if (senceImg != null && senceImg.Count > 0 && senceImg[0].Length > 0)
         {
             image_SenceImg.Source = ImageConvert.ToBitmapImage(senceImg[0]);
         }
         else
         {
             MB_MODULES.Views.MyMessage.showYes("获取抓拍实时帧失败!");
         }
     }
     catch (Exception ex)
     {
         MyMessage.Show(ex.Message);
     }
 }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        public void Get(ManualResetEvent snap, ManualResetEvent snapCompare, IdentifyResults result, byte[] snapStream, byte[] compareStream)
        {
            try
            {
                TypeInfo channelMgrType = GlobalCache.ChannelMgrObj.GetType() as TypeInfo;
                //channelMgrType.DeclaredProperties.FirstOrDefault(p=>p.Name ==Zhangxiaowen.i20170111.Sensing.ZhangXiaowen)

                channelMgrCtrl = GlobalCache.ChannelMgrObj as Control;

                foreach (FieldInfo item in channelMgrType.DeclaredFields)
                {
                    switch (item.Name)
                    {
                    case "CapimageByteRealtimeCapInfo":
                        snapField = item;
                        break;

                    case "_MyCapFaceLogWithImg":
                        //snapFaceImgField = snapPersonObj;
                        break;

                    case "ResetServerRealtimeCapInfo":
                        //TypeInfo ti = item.FieldType as TypeInfo;
                        //ConstructorInfo cio = ti.GetConstructors().FirstOrDefault();
                        //object _obj = cio.Invoke(new object[] { false });
                        //resetSnapInfoField = _obj as ManualResetEvent;
                        resetSnapInfoField = snap;
                        break;

                    case "snapStream":
                        snapStreamField = snapStream;
                        break;

                    case "campareStream":
                        //compareStreamField = item;
                        compareStreamField = compareStream;
                        break;

                    case "_IdentifyResults":
                        identifyResult = result;
                        break;

                    case "ResetServerRealtimeCmpInfo":
                        resetCompareInfoField = snapCompare;
                        //TypeInfo tio = item.FieldType as TypeInfo;
                        //ConstructorInfo cio1 = tio.GetConstructors().FirstOrDefault();
                        //object _obj1 = cio1.Invoke(new object[] { false });
                        //resetCompareInfoField = _obj1 as ManualResetEvent;
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger <UIServerInterForWifi> .Log.Error("UIServerInterForWifi.Get()", ex);
            }
        }
Exemple #5
0
        public void SetIdentifyResults(IdentifyResults _IdentifyResults)
        {
            cCViewModel.Image = _IdentifyResults.CapImg;
            long     _longtime = _IdentifyResults.Info.Time;
            DateTime s         = new DateTime(1970, 1, 1);

            s = s.AddSeconds(_longtime);
            cCViewModel.Day = s.ToString("yyyy/MM/dd HH:mm:ss").Split(' ')[0].Replace("/", "").Replace("/", "");
            cCViewModel.Id  = _IdentifyResults.ID;
            GetCmpByCapId();
            List <byte[]> senceImg = thirft.QuerySenceImg(_IdentifyResults.ID, cCViewModel.Day);

            if (senceImg != null && senceImg.Count > 0 && senceImg[0].Length > 0)
            {
                BitmapImage bitImage = new BitmapImage();
                bitImage.BeginInit();
                bitImage.StreamSource = new System.IO.MemoryStream(senceImg[0]);
                bitImage.EndInit();
                image_SenceImg.Source = bitImage;
            }
            else
            {
                MB_MODULES.Views.MyMessage.showYes("获取抓拍实时帧失败!");
            }
        }
Exemple #6
0
        public override async Task <SpeechIdentifier.Result> SummarizeAsync()
        {
            if (IsSessionOpen && !IsSessionClosing)
            {
                IsSessionClosing = true;
                IdentifyResults.Clear();
                Content.Clear();

                Uri uri = Configuration.Server.BuildEndpoint(URI_PATH_SUMMARIZE);

                Logger?.LogDebug("SpeechIdentifier_HttpClient_Version1.SummarizeAsync(): URI: " + uri.ToString());

                using (var request = BuildRequest(CallMode.Summarize, uri))
                {
                    try
                    {
                        await HandleResponse(CallMode.Summarize, request, await mHttpClient.SendAsync(request));
                    }
                    catch (HttpRequestException ex)
                    {
                        IdentifyResult = SpeechIdentifier.Result.Timeout;
                        Logger?.LogError(ex);
                    }
                    return(IdentifyResult);
                }
            }
            return(IdentifyResult = SpeechIdentifier.Result.Invalid);
        }
Exemple #7
0
        public override void Cancel(string reason, SpeechIdentifier.CancelCallback callback)
        {
            if (IsSessionOpen && !IsSessionClosing)
            {
                IsSessionClosing = true;
                IdentifyResults.Clear();
                Content.Clear();

                if (string.IsNullOrEmpty(reason))
                {
                    reason = "Unknown";
                }
                else
                {
                    reason = reason.Replace(' ', '-').Substring(0, System.Math.Min(reason.Length, 64));
                }

                Uri uri = Configuration.Server.BuildEndpoint(URI_PATH_CANCEL, reason);

                Logger?.LogDebug("SpeechIdentifier_HttpClient_Version1.Cancel(callback): URI: " + uri.ToString());

                using (var request = BuildRequest(CallMode.Cancel, uri))
                {
                    var task = mHttpClient.SendAsync(request).ContinueWith((requestTask) => {
                        if (requestTask.IsFaulted)
                        {
                            IdentifyResult = SpeechIdentifier.Result.Timeout;
                            Logger?.LogError(requestTask.Exception);
                            callback?.Invoke();
                            return;
                        }
                        HandleResponse(CallMode.Cancel, request, requestTask.Result).ContinueWith((responseTask) => {
                            if (responseTask.IsFaulted)
                            {
                                IdentifyResult = SpeechIdentifier.Result.Timeout;
                                Logger?.LogError(responseTask.Exception);
                                callback?.Invoke();
                                return;
                            }
                            callback?.Invoke();
                        });
                    });

                    if (task.IsFaulted)
                    {
                        IdentifyResult = SpeechIdentifier.Result.Timeout;
                        Logger?.LogError(task.Exception);
                        callback?.Invoke();
                    }

                    return;
                }
            }
            IdentifyResult = SpeechIdentifier.Result.Invalid;
            callback?.Invoke();
        }
Exemple #8
0
        public override void Summarize(SpeechIdentifier.SummarizeCallback callback)
        {
            if (IsSessionOpen && !IsSessionClosing)
            {
                IsSessionClosing = true;
                IdentifyResults.Clear();
                Content.Clear();

                Uri uri = Configuration.Server.BuildEndpoint(URI_PATH_SUMMARIZE);

                Logger?.LogDebug("SpeechIdentifier_HttpClient_Version1.Summarize(callback): URI: " + uri.ToString());

                using (var request = BuildRequest(CallMode.Summarize, uri))
                {
                    var task = mHttpClient.SendAsync(request).ContinueWith((requestTask) => {
                        if (requestTask.IsFaulted)
                        {
                            IdentifyResult = SpeechIdentifier.Result.Timeout;
                            Logger?.LogError(requestTask.Exception);
                            callback?.Invoke(IdentifyResult);
                            return;
                        }
                        HandleResponse(CallMode.Summarize, request, requestTask.Result).ContinueWith((responseTask) => {
                            if (responseTask.IsFaulted)
                            {
                                IdentifyResult = SpeechIdentifier.Result.Timeout;
                                Logger?.LogError(responseTask.Exception);
                                callback?.Invoke(IdentifyResult);
                                return;
                            }
                            callback?.Invoke(IdentifyResult);
                        });
                    });

                    if (task.IsFaulted)
                    {
                        IdentifyResult = SpeechIdentifier.Result.Timeout;
                        Logger?.LogError(task.Exception);
                        callback?.Invoke(IdentifyResult);
                    }

                    return;
                }
            }
            callback?.Invoke(IdentifyResult = SpeechIdentifier.Result.Invalid);
        }
        /// <summary>
        /// 比对双击 显示比对详细信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listViewContIdentifyResults_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            IdentifyResults _IdentifyResults = listViewContIdentifyResults.SelectedItem as IdentifyResults;

            if (_IdentifyResults == null)
            {
                return;
            }
            //比对窗口
            //ChannelCompare channelCompare = new ChannelCompare();
            //channelCompare.SetIdentifyResults(_IdentifyResults);
            //channelCompare.ShowDialog();
            //实时帧窗口
            CompInfo comInfoWin = new CompInfo();

            comInfoWin.SetIdentifyResults(_IdentifyResults);
            comInfoWin.ShowDialog();
        }
Exemple #10
0
        public override bool Cancel(string reason)
        {
            if (IsSessionOpen && !IsSessionClosing)
            {
                IsSessionClosing = true;
                IdentifyResults.Clear();
                Content.Clear();

                if (string.IsNullOrEmpty(reason))
                {
                    reason = "Unknown";
                }
                else
                {
                    reason = reason.Replace(' ', '-').Substring(0, System.Math.Min(reason.Length, 64));
                }

                Uri uri = Configuration.Server.BuildEndpoint(URI_PATH_CANCEL, reason);

                Logger?.LogDebug("SpeechIdentifier_HttpClient_Version1.Cancel(): URI: " + uri.ToString());

                using (var request = BuildRequest(CallMode.Cancel, uri))
                {
                    try
                    {
                        var responseTask = mHttpClient.SendAsync(request);

                        responseTask.RunSynchronously();

                        var resultTask = HandleResponse(CallMode.Cancel, request, responseTask.Result);

                        resultTask.RunSynchronously();

                        return(resultTask.Result);
                    }
                    catch (HttpRequestException ex)
                    {
                        IdentifyResult = SpeechIdentifier.Result.Timeout;
                        Logger?.LogError(ex);
                    }
                }
            }
            return(false);
        }
Exemple #11
0
        protected void AddResult(uint index, string name, SpeechIdentifier.InstanceResult result)
        {
            SpeechIdentifier.Profile profile = Profiles[index];

            if (result.Result == SpeechIdentifier.Result.Unknown)
            {
                if (result.Score == 0.0)
                {
                    result.Result = SpeechIdentifier.Result.NotScored;
                }
                else if (result.Score >= profile.PassThreshold)
                {
                    result.Result = SpeechIdentifier.Result.Pass;
                }
                else if (result.Score <= profile.FailThreshold)
                {
                    result.Result = SpeechIdentifier.Result.Fail;
                }
                else
                {
                    result.Result = SpeechIdentifier.Result.Ambiguous;
                }
            }

            Logger?.LogDebug("SpeechIdentifierBase.AddResult(): {0} - Index: {1}", name, index);
            Logger?.LogDebug("SpeechIdentifierBase.AddResult(): {0} - Error: {1}", name, result.ErrorCode);
            Logger?.LogDebug("SpeechIdentifierBase.AddResult(): {0} - Score: {1}", name, result.Score);
            Logger?.LogDebug("SpeechIdentifierBase.AddResult(): {0} - SpeechExtracted: {1}", name, result.SpeechExtracted);
            Logger?.LogDebug("SpeechIdentifierBase.AddResult(): {0} - Result: {1}", name, result.Result);

            if (result.IsAuthorized.HasValue)
            {
                IsAuthorized = result.IsAuthorized.Value;
                Logger?.LogDebug("SpeechIdentifierBase.AddResult(): {0} - IsAuthorized: {1}", name, IsAuthorized);
            }

            foreach (var extra in result.Extra)
            {
                Logger?.LogDebug("SpeechIdentifierBase.AddResult(): {0} - {1}: {2}", name, extra.Key, extra.Value);
            }

            IdentifyResults.Add(name, result);
        }
Exemple #12
0
 protected void ResetIdentifier()
 {
     SessionId = "";
     Codec     = WaveFormatEncoding.Unknown;
     Profiles.Clear();
     IdentifyResults.Clear();
     IdentifyResult = SpeechIdentifier.Result.NeedMore;
     MetaData.Clear();
     ExtraData.Clear();
     Content.Clear();
     CookieContainer     = new CookieContainer();
     TotalSnippetsSent   = 0;
     TotalAudioBytesSent = 0;
     TotalProcessCalls   = 0;
     SpeechRequired      = 0;
     SpeechExtracted     = 0;
     IdentifiedClientId  = "";
     IdentifiedScore     = 0;
     IsSessionOpen       = false;
     IsSessionClosing    = false;
     IsAuthorized        = false;
     IsTooSoft           = false;
     IsTooLoud           = false;
 }
Exemple #13
0
 /// <summary>
 /// init
 /// </summary>
 public ThriftServiceUtilities(ManualResetEvent snap, ManualResetEvent snapCompare, IdentifyResults result, byte[] snapStream, byte[] compareStream)
 {
     if ("WIFI".Equals(GlobalCache.NetworkMode))
     {
         wifi.Get(snap, snapCompare, result, snapStream, compareStream);
     }
 }
        /// <summary>
        /// 比对监听
        /// 20170301 取消自动推送功能
        /// </summary>
        /// <param name="obj"></param>
        public void ListenWaitServerRealtimeCmpInfo(object obj)
        {
            bool isCmpSend = false;

            try
            {
                while (true)
                {
                    if (ResetServerRealtimeCmpInfo.WaitOne())//设置监听等待
                    {
                        lock (ChannelManage._IdentifyResults)
                        {
                            IdentifyResults tempIdentifyResults = new IdentifyResults();
                            tempIdentifyResults = _IdentifyResults;
                            byte[] tempCapimageByteRealtimeCmpInfo = CapimageByteRealtimeCmpInfo;
                            byte[] tempCmpimageByteRealtimeCmpInfo = CmpimageByteRealtimeCmpInfo;
                            listViewContIdentifyResults.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                //刷新识别结果列表
                                try
                                {
                                    if (tempCapimageByteRealtimeCmpInfo.Length != 0 && tempCmpimageByteRealtimeCmpInfo.Length != 0)
                                    {
                                        BitmapImage myBitmapImage1 = new BitmapImage();
                                        myBitmapImage1.BeginInit();
                                        myBitmapImage1.StreamSource = new System.IO.MemoryStream(tempCapimageByteRealtimeCmpInfo);
                                        myBitmapImage1.EndInit();
                                        tempIdentifyResults.CapImg = myBitmapImage1;

                                        BitmapImage myBitmapImage2 = new BitmapImage();
                                        myBitmapImage2.BeginInit();
                                        myBitmapImage2.StreamSource = new System.IO.MemoryStream(tempCmpimageByteRealtimeCmpInfo);
                                        myBitmapImage2.EndInit();
                                        tempIdentifyResults.RegImg = myBitmapImage2;
                                        Console.WriteLine("注册名称:" + tempIdentifyResults.Info.Name);
                                        _ListIdentifyResults.Insert(0, tempIdentifyResults);
                                        if (tempIdentifyResults.ChannelName.StartsWith("##@"))
                                        {
                                            isCmpSend = true;
                                        }
                                        tempIdentifyResults.ChannelName = tempIdentifyResults.ChannelName.Replace("##", "").Replace("@", "");

                                        _ChannelManageViewModel.ComImageCount++;
                                        if (_ListIdentifyResults.Count > 100)
                                        {
                                            _ListIdentifyResults.Clear();
                                        }
                                        #region 报警弹窗
                                        if (Login.ClientType == "0")//0-筛选端
                                        {
                                            #region 01
                                            //弹窗
                                            listViewContIdentifyResults.Dispatcher.BeginInvoke(new Action(() =>
                                            {
                                                try
                                                {
                                                    viewModel.Property.CompareLogData = new MyCmpFaceLogWidthImgModel();
                                                    if (!isCmpSend)
                                                    {
                                                        //viewModel.Property.CompareLogData.num = 0;
                                                        viewModel.Property.CompareLogData.type   = tempIdentifyResults.TemplateType;
                                                        viewModel.Property.CompareLogData.score  = tempIdentifyResults.Info.Score;
                                                        viewModel.Property.CompareLogData.name   = tempIdentifyResults.Info.Name;
                                                        viewModel.Property.CompareLogData.ID     = tempIdentifyResults.ID;         //抓拍记录ID
                                                        viewModel.Property.CompareLogData.tcUuid = tempIdentifyResults.Info.ObjID; //模板对象ID
                                                        DateTime s = new DateTime(1970, 1, 1);
                                                        viewModel.Property.CompareLogData.time        = s.AddSeconds(tempIdentifyResults.Info.Time).ToString("yyyy/MM/dd HH:mm:ss");
                                                        viewModel.Property.CompareLogData.channelName = tempIdentifyResults.ChannelName;
                                                    }

                                                    if (tempIdentifyResults.CapImg == null || tempIdentifyResults.RegImg == null)
                                                    {
                                                        viewModel.Property.CompareLogData.SnapImage = myBitmapImage1;
                                                        viewModel.Property.CompareLogData.DBImage   = myBitmapImage2;
                                                    }

                                                    viewModel.Property.CompareLogData.SnapImage = myBitmapImage1;
                                                    viewModel.Property.CompareLogData.DBImage   = myBitmapImage2;
                                                    viewModel.Property.CompareLogData.IsChecked = false;
                                                    viewModel.Property.CompareLogDatas.Add(viewModel.Property.CompareLogData);
                                                    viewModel.Property.CompareLogDatasCache.Add(viewModel.Property.CompareLogData);

                                                    Function.ClearPushedWaringData.ClearTopFifty <MyCmpFaceLogWidthImgModel>();

                                                    if (tempIdentifyResults.CapImg == null || tempIdentifyResults.RegImg == null)
                                                    {
                                                        tempIdentifyResults.CapImg = myBitmapImage1;
                                                        tempIdentifyResults.RegImg = myBitmapImage2;
                                                    }

                                                    if (!warningWindowIsOpen)
                                                    {
                                                        ViewDataModel.WarningData = viewModel;
                                                        viewModel.Wmv             = viewModel;
                                                        wmw = new WarningMessageWindow();
                                                        wmw.Show();
                                                        warningWindowIsOpen = true;
                                                    }
                                                    else
                                                    {
                                                        if (ViewDataModel.WarningData.Property.Flag < 0)
                                                        {
                                                            warningWindowIsOpen = false;
                                                            ViewDataModel.WarningData.Property.Flag = 0;
                                                        }
                                                        viewModel.RefreshProperty();
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    _WriteLog.WriteToLog("listViewContIdentifyResultsDispatcher", ex);
                                                }
                                            }));
                                            #endregion
                                        }
                                        else if (Login.ClientType == "1")//1-接收端
                                        {
                                            try
                                            {
                                                WarningMessage wm = new WarningMessage();
                                                if (!isCmpSend)
                                                {
                                                    if (cmpInfoDictionary.ContainsKey(tempIdentifyResults.Info.Name)) // True
                                                    {
                                                        if (tempIdentifyResults.Info.Time - cmpInfoDictionary[tempIdentifyResults.Info.Name] <= 120)
                                                        {
                                                            wm.SetWarningRed();
                                                            cmpInfoDictionary[tempIdentifyResults.Info.Name] = tempIdentifyResults.Info.Time;
                                                        }
                                                        cmpInfoDictionary[tempIdentifyResults.Info.Name] = tempIdentifyResults.Info.Time;
                                                    }
                                                    else
                                                    {
                                                        cmpInfoDictionary.Add(tempIdentifyResults.Info.Name, tempIdentifyResults.Info.Time);
                                                    }
                                                }
                                                if (tempIdentifyResults.CapImg == null || tempIdentifyResults.RegImg == null)
                                                {
                                                    tempIdentifyResults.CapImg = myBitmapImage1;
                                                    tempIdentifyResults.RegImg = myBitmapImage2;
                                                }
                                                myBitmapImage1 = null;
                                                myBitmapImage2 = null;
                                                wm.SetWarningInfo(tempIdentifyResults.Info.Name, tempIdentifyResults.ChannelName, tempIdentifyResults.Info.Time, tempIdentifyResults.TemplateType, tempIdentifyResults.Info.Score + "", tempIdentifyResults.CapImg, tempIdentifyResults.RegImg, tempIdentifyResults.Info);
                                                wm.Show();
                                            }
                                            catch (Exception ex)
                                            {
                                                _WriteLog.WriteToLog("listViewContIdentifyResultsDispatcher", ex);
                                            }
                                        }
                                        #endregion
                                    }
                                    if (CapimageByteRealtimeCmpInfo.Length <= 0)
                                    {
                                        string strMessage = "抓拍照片为空";
                                        _WriteLog.WriteToLog("ListenWaitServerRealtimeCmpInfo", strMessage);
                                    }
                                    if (CmpimageByteRealtimeCmpInfo.Length <= 0)
                                    {
                                        string strMessage = "模板照片为空";
                                        _WriteLog.WriteToLog("ListenWaitServerRealtimeCmpInfo", strMessage);
                                    }
                                    Thread thread = new Thread(new ThreadStart(Play));
                                    thread.Start();
                                }
                                catch (Exception ex)
                                {
                                    _WriteLog.WriteToLog("ListenWaitServerRealtimeCmpInfo", ex);
                                }
                            }));
                            ResetServerRealtimeCmpInfo.Reset();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _WriteLog.WriteToLog("ListenWaitServerRealtimeCmpInfo", ex);
            }
        }
Exemple #15
0
        void Active(RealtimeCmpInfoLBS info)
        {
            //显示在界面上的结果
            if (compareResult != null)
            {
                compareResult = null;
            }
            compareResult    = new IdentifyResults();
            compareResult.ID = info.CapID;
            if (info.CapID == null || info.CapID == "")
            {
                MB_MODULES.Views.MyMessage.showYes("抓拍照片ID为空");
            }
            compareResult.RegID = info.ObjID;
            if (info.ObjID == null || info.ObjID == "")
            {
                MB_MODULES.Views.MyMessage.showYes("抓拍照片ID为空");
            }
            long     _longtime = info.Time;
            DateTime s         = new DateTime(1970, 1, 1);

            s = s.AddSeconds(_longtime);
            //// 抓拍照片
            //ChannelManage.snapStream = info.CapImg;
            ////得到主照片
            //ChannelManage.campareStream = info.ObjImg;

            GlobalCache.SnapStream        = info.CapImg;
            GlobalCache.SnapCompareStream = info.ObjImg;

            //获得主照片这侧信息
            StringBuilder strRegster = new StringBuilder();

            //注册名称
            strRegster.Append(info.Name + "\r\n");
            //获得通道名称
            string ChannelName = info.Channelname;

            compareResult.ChannelName = info.Channelname;
            strRegster.Append(ChannelName.Replace("##", "").Replace("@", "") + "\r\n");
            //抓拍时间
            int nIndexS = s.ToString().IndexOf(" ");

            strRegster.Append(s.ToString().Substring(0, nIndexS) + "\r\n");
            int nIndexS1 = s.ToString().Length - nIndexS;

            strRegster.Append(s.ToString().Substring(nIndexS + 1, nIndexS1 - 1) + "\r\n");
            //注册类型
            var    typeObj = GlobalCache.FaceTypeList.Cast <STypeInfo>().Cast <STypeInfo>().FirstOrDefault(x => x.Type == info.Type) ?? new STypeInfo();
            string type    = typeObj.Description;//eg:白名单、黑名单、普通...

            strRegster.Append(type + "\r\n");
            compareResult.TemplateType = type;
            //相似度。
            strRegster.Append(info.Score + "\r\n");
            compareResult.RegInfo = strRegster.ToString();
            compareResult.NewRci  = info;
            //MainWindow.nInfoType = info.Type;
            Console.WriteLine("推送了一条比对记录");
            //ChannelManage._IdentifyResults = compareResult;
            //ChannelManage.ResetServerRealtimeCmpInfo.Set();

            //identifyResult = compareResult;
            GlobalCache.IdentifyResult = compareResult;
            resetCompareInfoField.Set();

            ////弹出报警框
            //AlarmWindow _AlarmWindow = new AlarmWindow();
            //_AlarmWindow.CapimageByteRealtimeCmpInfo = info.CapImg;
            //_AlarmWindow.CmpimageByteRealtimeCmpInfo = info.CapImg;
            //_AlarmWindow.RegInfo = strRegster.ToString();
            //_AlarmWindow.nInfoType = info.Type;
            //_AlarmWindow.Show();
        }
Exemple #16
0
        public int UpdateRealtimeCmp(RealtimeCmpInfo info, string channelName)
        {
            try
            {
                if (GlobalCache.AppType == 1)
                {
                    if (!channelName.StartsWith("##"))
                    {
                        return(-1);
                    }
                }
                //显示在界面上的结果
                if (compareResult != null)
                {
                    compareResult = null;
                }
                compareResult    = new IdentifyResults();
                compareResult.ID = info.CapID;
                if (info.CapID == null || info.CapID == "")
                {
                    MB_MODULES.Views.MyMessage.showYes("抓拍照片ID为空");
                }
                compareResult.RegID = info.ObjID;
                if (info.ObjID == null || info.ObjID == "")
                {
                    MB_MODULES.Views.MyMessage.showYes("抓拍照片ID为空");
                }
                long     _longtime = info.Time;
                DateTime s         = new DateTime(1970, 1, 1);
                s = s.AddSeconds(_longtime);
                // 抓拍照片
                //ChannelManage.snapStream = info.CapImg;
                ////得到主照片
                //ChannelManage.campareStream = info.ObjImg;
                //获得主照片这侧信息
                StringBuilder strRegster = new StringBuilder();
                //注册名称
                strRegster.Append(info.Name + "\r\n");
                //获得通道名称
                string ChannelName = channelName;
                compareResult.ChannelName = channelName;
                strRegster.Append(ChannelName.Replace("##", "").Replace("@", "") + "\r\n");
                //抓拍时间
                int nIndexS = s.ToString().IndexOf(" ");
                strRegster.Append(s.ToString().Substring(0, nIndexS) + "\r\n");
                int nIndexS1 = s.ToString().Length - nIndexS;
                strRegster.Append(s.ToString().Substring(nIndexS + 1, nIndexS1 - 1) + "\r\n");
                //注册类型
                var    typeObj = GlobalCache.FaceTypeList.Cast <STypeInfo>().Cast <STypeInfo>().FirstOrDefault(x => x.Type == info.Type) ?? new STypeInfo();
                string type    = typeObj.Description;

                strRegster.Append(type + "\r\n");
                compareResult.TemplateType = type;
                //相似度。
                strRegster.Append(info.Score + "\r\n");
                compareResult.RegInfo = strRegster.ToString();
                compareResult.Info    = info;
                //MainWindow.nInfoType = info.Type;
                Console.WriteLine("推送了一条比对记录");
                //ChannelManage._IdentifyResults = compareResult;
                //ChannelManage.ResetServerRealtimeCmpInfo.Set();

                ////弹出报警框
                //AlarmWindow _AlarmWindow = new AlarmWindow();
                //_AlarmWindow.CapimageByteRealtimeCmpInfo = info.CapImg;
                //_AlarmWindow.CmpimageByteRealtimeCmpInfo = info.CapImg;
                //_AlarmWindow.RegInfo = strRegster.ToString();
                //_AlarmWindow.nInfoType = info.Type;

                //_AlarmWindow.Show();

                info = null;
                return(0);
            }
            catch (Exception ex)
            {
                Logger <UIServerInterForWifi> .Log.Error("", ex);

                return(-1);
            }
        }
        /// <summary>
        /// 比对监听
        /// </summary>
        /// <param name="obj"></param>
        public void ListenWaitServerRealtimeCmpInfo(object obj)
        {
            bool isCmpSend = false;

            try
            {
                while (true)
                {
                    if (ResetServerRealtimeCmpInfo.WaitOne())//设置监听等待
                    {
                        lock (ChannelManage._IdentifyResults)
                        {
                            IdentifyResults tempIdentifyResults = new IdentifyResults();
                            tempIdentifyResults = _IdentifyResults;
                            byte[] tempCapimageByteRealtimeCmpInfo = CapimageByteRealtimeCmpInfo;
                            byte[] tempCmpimageByteRealtimeCmpInfo = CmpimageByteRealtimeCmpInfo;
                            listViewContIdentifyResults.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                //刷新识别结果列表
                                try
                                {
                                    if (tempCapimageByteRealtimeCmpInfo.Length != 0 && tempCmpimageByteRealtimeCmpInfo.Length != 0)
                                    {
                                        BitmapImage myBitmapImage = new BitmapImage();
                                        myBitmapImage.BeginInit();
                                        myBitmapImage.StreamSource = new System.IO.MemoryStream(tempCapimageByteRealtimeCmpInfo);
                                        myBitmapImage.EndInit();
                                        tempIdentifyResults.CapImg = myBitmapImage;

                                        BitmapImage myBitmapImage2 = new BitmapImage();
                                        myBitmapImage2.BeginInit();
                                        myBitmapImage2.StreamSource = new System.IO.MemoryStream(tempCmpimageByteRealtimeCmpInfo);
                                        myBitmapImage2.EndInit();
                                        tempIdentifyResults.RegImg = myBitmapImage2;
                                        Console.WriteLine("注册名称:" + tempIdentifyResults.Info.Name);
                                        _ListIdentifyResults.Insert(0, tempIdentifyResults);
                                        if (tempIdentifyResults.ChannelName.StartsWith("##@"))
                                        {
                                            isCmpSend = true;
                                        }
                                        tempIdentifyResults.ChannelName = tempIdentifyResults.ChannelName.Replace("##", "").Replace("@", "");

                                        _ChannelManageViewModel.ComImageCount++;
                                        if (_ListIdentifyResults.Count > 100)
                                        {
                                            _ListIdentifyResults.Clear();
                                        }
                                        //弹窗部分
                                        if (Login.ClientType == "1" || Login.ClientType == "0")
                                        {
                                            if (comboAutoSend.SelectedIndex == 0)
                                            {
                                                //弹窗
                                                listViewContIdentifyResults.Dispatcher.BeginInvoke(new Action(() =>
                                                {
                                                    try
                                                    {
                                                        viewModel.Property.CompareLogData = new MyCmpFaceLogWidthImgModel();
                                                        if (!isCmpSend)
                                                        {
                                                            //viewModel.Property.CompareLogData.num = 0;
                                                            viewModel.Property.CompareLogData.score = tempIdentifyResults.Info.Score;
                                                            viewModel.Property.CompareLogData.name  = tempIdentifyResults.Info.Name;
                                                            DateTime s = new DateTime(1970, 1, 1);
                                                            viewModel.Property.CompareLogData.time        = s.AddSeconds(tempIdentifyResults.Info.Time).ToString();
                                                            viewModel.Property.CompareLogData.channelName = tempIdentifyResults.ChannelName;
                                                        }

                                                        if (tempIdentifyResults.CapImg == null || tempIdentifyResults.RegImg == null)
                                                        {
                                                            viewModel.Property.CompareLogData.SnapImage = myBitmapImage;
                                                            viewModel.Property.CompareLogData.DBImage   = myBitmapImage2;
                                                        }

                                                        viewModel.Property.CompareLogData.SnapImage = myBitmapImage;
                                                        viewModel.Property.CompareLogData.DBImage   = myBitmapImage2;
                                                        viewModel.Property.CompareLogDatas.Add(viewModel.Property.CompareLogData);

                                                        #region old
                                                        //WarningMessage wm = new WarningMessage();
                                                        //if (!isCmpSend)
                                                        //{
                                                        //    if (cmpInfoDictionary.ContainsKey(tempIdentifyResults.Info.Name)) // True
                                                        //    {
                                                        //        if (tempIdentifyResults.Info.Time - cmpInfoDictionary[tempIdentifyResults.Info.Name] <= 120)
                                                        //        {
                                                        //            wm.SetWarningRed();
                                                        //            cmpInfoDictionary[tempIdentifyResults.Info.Name] = tempIdentifyResults.Info.Time;
                                                        //        }
                                                        //        cmpInfoDictionary[tempIdentifyResults.Info.Name] = tempIdentifyResults.Info.Time;
                                                        //    }
                                                        //    else
                                                        //    {
                                                        //        cmpInfoDictionary.Add(tempIdentifyResults.Info.Name, tempIdentifyResults.Info.Time);
                                                        //    }
                                                        //}
                                                        //if (tempIdentifyResults.CapImg == null || tempIdentifyResults.RegImg == null)
                                                        //{
                                                        //    tempIdentifyResults.CapImg = myBitmapImage;
                                                        //    tempIdentifyResults.RegImg = myBitmapImage2;
                                                        //}
                                                        //myBitmapImage = null;
                                                        //myBitmapImage2 = null;
                                                        //wm.SetWarningInfo(tempIdentifyResults.Info.Name, tempIdentifyResults.ChannelName, tempIdentifyResults.Info.Time, tempIdentifyResults.TemplateType, tempIdentifyResults.Info.Score + "", tempIdentifyResults.CapImg, tempIdentifyResults.RegImg, tempIdentifyResults.Info);
                                                        //wm.Show();
                                                        #endregion

                                                        if (!warningWindowIsOpen)
                                                        {
                                                            ViewDataModel.WarningData = viewModel;
                                                            viewModel.Wmv             = viewModel;
                                                            wmw = new WarningMessageWindow();
                                                            wmw.Show();
                                                            warningWindowIsOpen = true;
                                                        }
                                                        else
                                                        {
                                                            viewModel.RefreshProperty();
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        _WriteLog.WriteToLog("listViewContIdentifyResultsDispatcher", ex);
                                                    }
                                                }));
                                            }
                                            else
                                            {
                                                //自动推送
                                                foreach (var area in BasicInfo.ConfigList)
                                                {
                                                    if (tempIdentifyResults.ChannelName.Contains(area.AreaName))
                                                    {
                                                        if (area.Alarmnum != 1)
                                                        {
                                                            if (cmpInfoDictionary.ContainsKey(tempIdentifyResults.Info.Name)) // True
                                                            {
                                                                if (tempIdentifyResults.Info.Time - cmpInfoDictionary[tempIdentifyResults.Info.Name] <= 120)
                                                                {
                                                                    tempIdentifyResults.Info.Channel = tempIdentifyResults.ChannelName;
                                                                    if (tempIdentifyResults.Info.Score > area.Threshold)
                                                                    {
                                                                        foreach (var ip in area.ReceiveIPOfArea)
                                                                        {
                                                                            if (UpdateCmp(tempIdentifyResults.Info, ip) == 0)
                                                                            {
                                                                                thirft.UpdateCmpLog(tempIdentifyResults.Info.CapID, tempIdentifyResults.Info.ObjID, System.DateTime.Now.ToString("yyyyMMdd"), area.AreaType);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                cmpInfoDictionary[tempIdentifyResults.Info.Name] = tempIdentifyResults.Info.Time;
                                                            }
                                                            else
                                                            {
                                                                cmpInfoDictionary.Add(tempIdentifyResults.Info.Name, tempIdentifyResults.Info.Time);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            tempIdentifyResults.Info.Channel = tempIdentifyResults.ChannelName;
                                                            if (tempIdentifyResults.Info.Score > area.Threshold)
                                                            {
                                                                foreach (var ip in area.ReceiveIPOfArea)
                                                                {
                                                                    if (UpdateCmp(tempIdentifyResults.Info, ip) == 0)
                                                                    {
                                                                        thirft.UpdateCmpLog(tempIdentifyResults.Info.CapID, tempIdentifyResults.Info.ObjID, System.DateTime.Now.ToString("yyyyMMdd"), area.AreaType);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (CapimageByteRealtimeCmpInfo.Length <= 0)
                                    {
                                        string strMessage = "抓拍照片为空";
                                        _WriteLog.WriteToLog("ListenWaitServerRealtimeCmpInfo", strMessage);
                                    }
                                    if (CmpimageByteRealtimeCmpInfo.Length <= 0)
                                    {
                                        string strMessage = "模板照片为空";
                                        _WriteLog.WriteToLog("ListenWaitServerRealtimeCmpInfo", strMessage);
                                    }
                                    Thread thread = new Thread(new ThreadStart(Play));
                                    thread.Start();
                                }
                                catch (Exception ex)
                                {
                                    _WriteLog.WriteToLog("ListenWaitServerRealtimeCmpInfo", ex);
                                }
                            }));
                            ResetServerRealtimeCmpInfo.Reset();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _WriteLog.WriteToLog("ListenWaitServerRealtimeCmpInfo", ex);
                //System.Windows.MessageBox.Show(ex.Message);
            }
        }
Exemple #18
0
        private async Task <bool> HandleResponse(CallMode mode, HttpRequestMessage request, HttpResponseMessage response)
        {
            Content.Clear();
            ExtraData.Clear();

            if (response == null)
            {
                Logger?.LogError("SpeechIdentifier_HttpClient_Version1.HandleResponse(): Timeout occurred");
                IdentifyResult = SpeechIdentifier.Result.Timeout;
                return(false);
            }

            try
            {
                HttpStatusCode code        = response.StatusCode;
                string         description = response.ReasonPhrase;

                Logger?.LogDebug($"SpeechIdentifier_HttpClient_Version1.HandleResponse(): Http Status Code: {code}");
                Logger?.LogDebug($"SpeechIdentifier_HttpClient_Version1.HandleResponse(): Http Status Description: {description}");

                if (code == HttpStatusCode.OK)
                {
                    if (mode == CallMode.Start)
                    {
                        if (!response.Headers.TryGetValues(SpeechApi.SESSION_ID, out var sessionValue))
                        {
                            Logger?.LogError("SpeechIdentifier_HttpClient_Version1.HandleResponse(): Invalid start response, no Vv-Session-Id");
                            return(false);
                        }

                        SessionId = sessionValue.FirstOrDefault();
                        if (string.IsNullOrEmpty(SessionId))
                        {
                            Logger?.LogError("SpeechIdentifier_HttpClient_Version1.HandleResponse(): Invalid start response, empty Vv-Session-Id");
                            return(false);
                        }

                        IsSessionOpen = true;
                    }
                    else if (mode == CallMode.Summarize)
                    {
                        SessionId     = "";
                        IsSessionOpen = false;
                    }
                    else if (mode == CallMode.Cancel)
                    {
                        SessionId     = "";
                        IsSessionOpen = false;
                        return(true);
                    }
                }

                if (response.Headers.TryGetValues(SpeechApi.SET_COOKIE, out var newCookies))
                {
                    foreach (var item in SetCookieHeaderValue.ParseList(newCookies.ToList()))
                    {
                        var uri = new Uri(request.RequestUri, item.Path.Value);
                        Logger?.LogDebug("{0}: {1} - {2} - {3}", SpeechApi.SET_COOKIE, item.Name.Value, item.Value.Value, item.Path.Value);
                        CookieContainer.Add(uri, new Cookie(item.Name.Value, item.Value.Value, item.Path.Value));
                    }
                }

                if (response.Content == null)
                {
                    Logger?.LogError("SpeechIdentifier_HttpClient_Version1.HandleResponse(): Expected Content Type: 'application/json'. Actual Content Type: 'Empty'");
                    return(false);
                }
                else if (!response.Content.Headers.ContentType.MediaType.Equals("application/json"))
                {
                    Logger?.LogError("SpeechIdentifier_HttpClient_Version1.HandleResponse(): Expected Content Type: 'application/json'. Actual Content Type: '{0}'", response.Content.Headers.ContentType.MediaType);
                    return(false);
                }

                var content = await response.Content.ReadAsStringAsync();

                if (content == null || content.Length == 0)
                {
                    Logger?.LogError("SpeechIdentifier_HttpClient_Version1.HandleResponse(): Expected Content Data: Length 0");
                    return(false);
                }

                Logger?.LogDebug("SpeechIdentifier_HttpClient_Version1.HandleResponse(): Http Content: {0}", content);

                SpeechIdentifier_Version1_Response version1Response = JsonConvert.DeserializeObject <SpeechIdentifier_Version1_Response>(content);

                if (code == HttpStatusCode.OK)
                {
                    switch (mode)
                    {
                    case CallMode.Profile:
                        if (version1Response.IdentifyProfile != null)
                        {
                            if (version1Response.IdentifyProfile.Profile.Type == SpeechIdentifier.ProfileType.Unknown)
                            {
                                IdentifyResult = SpeechIdentifier.Result.Invalid;
                                Logger?.LogError("SpeechIdentifier_HttpClient_Version1.HandleResponse(): Invalid ProfileType");
                                return(false);
                            }
                            mLastProfileIndex = AddProfile(version1Response.IdentifyProfile.Index, version1Response.IdentifyProfile.Profile);
                        }
                        break;

                    case CallMode.Start:
                        if (version1Response.IdentifyProfile != null)
                        {
                            if (version1Response.IdentifyProfile.Profile.Type == SpeechIdentifier.ProfileType.Unknown)
                            {
                                IdentifyResult = SpeechIdentifier.Result.Invalid;
                                Logger?.LogError("SpeechIdentifier_HttpClient_Version1.HandleResponse(): Invalid ProfileType");
                                return(false);
                            }
                            mLastProfileIndex = AddProfile(version1Response.IdentifyProfile.Index, version1Response.IdentifyProfile.Profile);
                        }
                        if (version1Response.ResultData != null)
                        {
                            foreach (var kv in version1Response.ResultData)
                            {
                                ExtraData.Add(kv.Key, kv.Value);
                            }
                        }
                        break;

                    case CallMode.Process:
                        if (version1Response.IdentifyResults != null)
                        {
                            foreach (var kv in version1Response.IdentifyResults)
                            {
                                AddResult(kv.Value.Index, kv.Key, kv.Value.Instance);
                            }

                            if (IdentifyResults.Count == 1)
                            {
                                var obj = (DictionaryEntry)IdentifyResults.GetFirst();
                                SpeechIdentifier.InstanceResult result = (SpeechIdentifier.InstanceResult)obj.Value;
                                IdentifiedClientId = Convert.ToString(obj.Key);
                                IdentifiedScore    = result.Score;
                                SpeechExtracted    = result.SpeechExtracted;
                                IdentifyResult     = result.Result;
                            }
                        }
                        if (version1Response.ResultData != null)
                        {
                            foreach (var kv in version1Response.ResultData)
                            {
                                ExtraData.Add(kv.Key, kv.Value);
                            }
                        }
                        break;

                    case CallMode.Summarize:
                        if (version1Response.IdentifyResults != null)
                        {
                            foreach (var kv in version1Response.IdentifyResults)
                            {
                                AddResult(kv.Value.Index, kv.Key, kv.Value.Instance);
                            }

                            if (IdentifyResults.Count == 1)
                            {
                                var obj = (DictionaryEntry)IdentifyResults.GetFirst();
                                SpeechIdentifier.InstanceResult result = (SpeechIdentifier.InstanceResult)obj.Value;
                                IdentifiedClientId = Convert.ToString(obj.Key);
                                IdentifiedScore    = result.Score;
                                SpeechExtracted    = result.SpeechExtracted;
                                IdentifyResult     = result.Result;
                            }
                        }
                        if (version1Response.ResultData != null)
                        {
                            foreach (var kv in version1Response.ResultData)
                            {
                                ExtraData.Add(kv.Key, kv.Value);
                            }
                        }
                        break;
                    }

                    return(true);
                }
                else
                {
                    if (version1Response.Error.HasValue)
                    {
                        IdentifyResult = GetErrorResult(version1Response.Error.Value);
                    }
                    else
                    {
                        IdentifyResult = SpeechIdentifier.Result.Unknown;
                    }

                    if (IdentifyResult == SpeechIdentifier.Result.NeedMore)
                    {
                        if (IsTooSoft)
                        {
                            IdentifyResult = SpeechIdentifier.Result.TooSoft;
                        }
                        else if (IsTooLoud)
                        {
                            IdentifyResult = SpeechIdentifier.Result.TooLoud;
                        }
                    }
                    else if (IdentifyResult == SpeechIdentifier.Result.TooSoft)
                    {
                        IsTooSoft = true;
                    }
                    else if (IdentifyResult == SpeechIdentifier.Result.TooLoud)
                    {
                        IsTooLoud = true;
                    }

                    Logger?.LogError(
                        "SpeechIdentifier_HttpClient_Version1.HandleResponse(): Error detected.\r\n\tUri: {0}\r\n\tResult: {1}\r\n\tCode: {2}\r\n\tDescription: {3}",
                        request.RequestUri,
                        IdentifyResult,
                        version1Response.Error.HasValue ? "" + version1Response.Error.Value + "" : "?",
                        version1Response.Description);

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }