Exemplo n.º 1
0
        private void Button_Start_Click(object sender, EventArgs e)
        {
            Settings.Default.apiKey     = this.textBox_apiKey.Text.Trim();
            Settings.Default.secretKey  = this.textBox_secretKey.Text.Trim();
            Settings.Default.idCardPath = this.textBox_idCardPath.Text.Trim();
            Settings.Default.Save();

            FaceApi faceApi = new FaceApi();

            faceApi.Init(Settings.Default.apiKey, Settings.Default.secretKey);

            // 定时截屏比对
            Task.Factory.StartNew(() =>
            {
                LogInvoke li = new LogInvoke(WriteLog);
                while (true)
                {
                    if (_cts.IsCancellationRequested)
                    {
                        break;
                    }

                    try
                    {
                        var img = this.VideoPlayer.GetCurrentVideoFrame();
                        if (img != null)
                        {
                            var image1 = Convert.ToBase64String((byte[])new ImageConverter().ConvertTo(img, typeof(byte[])));
                            img.Dispose();
                            var image2 = Convert.ToBase64String(File.ReadAllBytes(Settings.Default.idCardPath));

                            _detectResult = faceApi.Detect(image1);
                            if (_detectResult.error_code == 0)
                            {
                                BeginInvoke(li, new object[] { $"人脸数量:{_detectResult.result.face_num}" });

                                var result2 = faceApi.Match(image1, image2);
                                if (result2.error_code == 0)
                                {
                                    BeginInvoke(li, new object[] { $"比对分数:{result2.result.score}" });
                                }
                                else
                                {
                                    BeginInvoke(li, new object[] { $"比对分数:{result2.error_msg}" });
                                }
                            }
                            else
                            {
                                BeginInvoke(li, new object[] { $"人脸数量:{_detectResult.error_msg}" });
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        BeginInvoke(li, new object[] { ex.Message });
                    }
                    finally
                    {
                        Thread.Sleep(100);
                    }
                }
            }, _cts.Token);

            WriteLog("启动完成");
        }
Exemplo n.º 2
0
        public void UHFtaskTH()
        {
            if (!UHF.connect())
                return;

            while (true)
            {
                Task A_card = new Task();
                LogInvoke updatelog = new LogInvoke(updateUIlog);
                StatusInvoke statusreport = new StatusInvoke(updateUIprocess);

                System.Threading.Thread.Sleep(1);

                this.Invoke(statusreport, new object[] { 0, "寻卡" });

                UHF.requestID(ref A_card);

                if (A_card.BOXID.Substring(0, 3) != "300")
                    continue;

                if (!A_card.status)
                    continue;

                this.Invoke(statusreport, new object[] { 30, "读卡ID" });

                UHF.requestData(ref A_card);

                this.Invoke(statusreport, new object[] { 80, "读取数据" });
                if (A_card.status)
                {
                    netupdate(ref A_card);

                    this.Invoke(statusreport, new object[] { 90, "同步数据库" });
                }

                this.Invoke(updatelog, new Object[] { A_card });

                this.Invoke(statusreport, new object[] { 100, "任务结束" });

            }
        }