diff --git a/.vs/SubCabinetSolution/v17/.suo b/.vs/SubCabinetSolution/v17/.suo index 0425a45..c0c2566 100644 --- a/.vs/SubCabinetSolution/v17/.suo +++ b/.vs/SubCabinetSolution/v17/.suo Binary files differ diff --git a/.vs/SubCabinetSolution/v17/.suo b/.vs/SubCabinetSolution/v17/.suo index 0425a45..c0c2566 100644 --- a/.vs/SubCabinetSolution/v17/.suo +++ b/.vs/SubCabinetSolution/v17/.suo Binary files differ diff --git a/SubCabinetSolution/ViewModel/MainViewModel.cs b/SubCabinetSolution/ViewModel/MainViewModel.cs index 054cdab..a7920e3 100644 --- a/SubCabinetSolution/ViewModel/MainViewModel.cs +++ b/SubCabinetSolution/ViewModel/MainViewModel.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.ObjectModel; using System.Data; using System.Diagnostics; @@ -7,6 +6,7 @@ using System.IO; using System.Linq; using System.Windows; +using AForge.Controls; using AForge.Video.DirectShow; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; @@ -22,6 +22,7 @@ public class MainViewModel : ViewModelBase { private FilterInfo _currentDevice; + private readonly FaceDetector _faceDetector = new FaceDetector(); /* * TextBlock双向绑定 @@ -146,23 +147,15 @@ { var videoSource = new VideoCaptureDevice(_currentDevice.MonikerString); window.CameraPreviewPlayer.VideoSource = videoSource; - //捕捉画面帧,TODO 人脸检测 window.CameraPreviewPlayer.NewFrame += delegate(object sender, ref Bitmap bitmap) { - try + //捕捉画面帧,人脸检测 + var skBitmap = SKBitmap.Decode(BitmapToBytes(bitmap)); + var faceInfos = _faceDetector.Detect(skBitmap); + Debug.WriteLine($@"检测到的人脸数量:{faceInfos.Length} 个人脸信息"); + foreach (var info in faceInfos) { - var faceDetector = new FaceDetector(); - var skBitmap = SKBitmap.Decode(BitmapToBytes(bitmap)); - var faceInfos = faceDetector.Detect(skBitmap); - Debug.WriteLine($@"识别到的人脸数量:{faceInfos.Length} 个人脸信息"); - foreach (var info in faceInfos) - { - Debug.WriteLine($"{info.Score:f8}\t{info.Location}"); - } - } - catch (Exception e) - { - Debug.WriteLine(e.Message); + Debug.WriteLine($"{info.Score:f8}\t{info.Location}"); } }; window.CameraPreviewPlayer.Start();