Пример #1
0
        private void ButtonRegister_Click(object sender, EventArgs e)
        {
            if (_RegisterFeatureData == null)
            {
                MessageBox.Show("没有人脸数据,请面对摄像头并点击视频");
                return;
            }
            if (string.IsNullOrEmpty(this.TextBoxID.Text))
            {
                MessageBox.Show("请输入Id");
                this.TextBoxID.Focus();
                return;
            }
            var fileName = FeaturePath + "\\" + this.TextBoxID.Text + ".dat";

            if (System.IO.File.Exists(fileName))
            {
                if (MessageBox.Show($"您要替换[{this.TextBoxID.Text}]的人脸数据吗?", "咨询", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
                {
                    return;
                }
            }
            System.IO.File.WriteAllBytes(fileName, _RegisterFeatureData);
            var faceModel = new Face.FaceModel
            {
                lFeatureSize = _RegisterFeatureData.Length,
                pbFeature    = Marshal.AllocHGlobal(_RegisterFeatureData.Length)
            };

            Marshal.Copy(_RegisterFeatureData, 0, faceModel.pbFeature, _RegisterFeatureData.Length);
            _FaceLib.Items.Add(new Face.FaceLib.Item()
            {
                OrderId = DateTime.Now.Ticks, ID = this.TextBoxID.Text, FaceModel = faceModel
            });
        }
Пример #2
0
 public static extern int FacePairMatch(IntPtr engine, ref FaceModel faceModel1, ref FaceModel faceModel2, out float score);
Пример #3
0
 public static extern int ExtractFeature(IntPtr engine, ref ImageData imageData, ref FaceFeatureInput faceFeatureInput, out FaceModel pFaceModels);
Пример #4
0
        private void Main_Load(object sender, EventArgs e)
        {
            if (!Directory.Exists(FeaturePath))
            {
                Directory.CreateDirectory(FeaturePath);
            }

            foreach (var file in Directory.GetFiles(FeaturePath))
            {
                var info      = new FileInfo(file);
                var data      = File.ReadAllBytes(file);
                var faceModel = new Face.FaceModel
                {
                    lFeatureSize = data.Length,
                    pbFeature    = Marshal.AllocHGlobal(data.Length)
                };

                Marshal.Copy(data, 0, faceModel.pbFeature, data.Length);
                _FaceLib.Items.Add(new Face.FaceLib.Item()
                {
                    OrderId = 0, ID = info.Name.Replace(info.Extension, ""), FaceModel = faceModel
                });
            }
            _CameraPara = new CameraPara();
            if (!_CameraPara.HasVideoDevice)
            {
                MessageBox.Show("没有检测到摄像头");
                this.Close();
                return;
            }

            this.VideoPlayer.VideoSource = _CameraPara.VideoSource;
            this.VideoPlayer.Start();

            _RateH = 1.0 * this.VideoPlayer.Height / this._CameraPara.FrameHeight;
            _RateW = 1.0 * this.VideoPlayer.Width / this._CameraPara.FrameWidth;

            //var initResult = (Face.ErrorCode)Face.Trace.Init(FaceAppId, FaceTraceKey, _FaceTraceBuffer, BufferSize, out _FaceTraceEnginer, (int)Face.OrientPriority.Only0, 16, 1);
            //if (initResult != Face.ErrorCode.Ok)
            //{
            //    MessageBox.Show("初始化人脸跟踪引擎失败,错误代码为:" + initResult);
            //    this.Close();
            //    return;
            //}

            var initResult = (Face.ErrorCode)Face.Detect.Init(FaceAppId, FaceDetectKey, _FaceDetectBuffer, BufferSize, out _FaceDetectEnginer, (int)Face.OrientPriority.Only0, 16, 1);

            if (initResult != Face.ErrorCode.Ok)
            {
                MessageBox.Show("初始化人脸检测引擎失败,错误代码为:" + initResult);
                this.Close();
                return;
            }

            initResult = (Face.ErrorCode)Face.Match.Init(FaceAppId, FaceMatchKey, _FaceMatchBuffer, BufferSize, out _FaceMatchEngine);
            if (initResult != Face.ErrorCode.Ok)
            {
                MessageBox.Show("初始化人脸比对引擎失败,错误代码为:" + initResult);
                this.Close();
                return;
            }

            //initResult = (Face.ErrorCode)Face.Age.Init(FaceAppId, FaceAgeKey, _FaceAgeBuffer, BufferSize, out _FaceAgeEngine);
            //if (initResult != Face.ErrorCode.Ok)
            //{
            //    MessageBox.Show("初始化年龄识别引擎失败,错误代码为:" + initResult);
            //    this.Close();
            //    return;
            //}

            initResult = (Face.ErrorCode)Face.Gender.Init(FaceAppId, FaceGenderKey, _FaceGenderBuffer, BufferSize, out _FaceGenderEngine);
            if (initResult != Face.ErrorCode.Ok)
            {
                MessageBox.Show("初始化性别识别引擎失败,错误代码为:" + initResult);
                this.Close();
                return;
            }
            Task.Delay(1000).Wait();
            Task.Factory.StartNew(() =>
            {
                Task.Delay(1000).Wait();
                while (!_CancellationTokenSource.IsCancellationRequested)
                {
                    #region 200毫秒左右
                    MatchFrame();
                    #endregion
                }
            }, _CancellationTokenSource.Token);
        }