public void DetectFaces() { try { Update_DetectorImageScale_DividedBy_CameraViewImageScale(); var scale = DetectorImageScale_DividedBy_CameraViewImageScale; var detectorImageWidth = (int)(CameraViewImageWidth * scale); var detectorImageHeight = (int)(CameraViewImageHeight * scale); if (false) { Debug.WriteLine("DetectorImageWidth: " + detectorImageWidth); Debug.WriteLine("DetectorImageHeight: " + detectorImageHeight); } if (ApplicationCommonSettings.IsDeveloperRelease) { DetectionElapsedStopwatch.Reset(); DetectionElapsedStopwatch.Start(); } DlibArray2dUcharImage.ResizeImage(detectorImageWidth, detectorImageHeight); DetectedFaceRectsInCameraViewImage = DlibHogSvm.DetectFaces(DlibArray2dUcharImage, DlibHogSvmThreshold) .Select(e => new System.Drawing.Rectangle((int)(e.X / scale), (int)(e.Y / scale), (int)(e.Width / scale), (int)(e.Height / scale))) .ToList(); if (ApplicationCommonSettings.IsDeveloperRelease) { DetectionElapsedMilliseconds = (int)DetectionElapsedStopwatch.ElapsedMilliseconds; } } catch (Exception ex) { if (ApplicationCommonSettings.IsDebugging) { Debugger.Break(); } Console.WriteLine(ex.Message); } }
public void DetectFaces(OpenCvSharp.Mat inputColorImage, double threshold) { if (IsEnabled == false) { return; } Trace.Assert(inputColorImage != null); Elapsed.Restart(); Image.SetBitmap(inputColorImage.ToBitmap()); DetectedFaceRects = DlibHogSvm.DetectFaces(Image, threshold) .Select(e => new OpenCvSharp.Rect(e.X, e.Y, e.Width, e.Height)); Elapsed.Stop(); var fps = (1000.0 / (double)Elapsed.ElapsedMilliseconds); FpsFiltered = 0.7 * FpsFiltered + 0.3 * fps; }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { // dispose managed objects, and dispose objects that implement IDisposable if (Device != null) { // When InitializeOnceAtStartup is not called. Device.CameraViewImageSourceBitmapCapture.CameraViewImageSourceBitmapChanged -= Device_CameraViewImageSourceBitmapCapture_CameraViewImageSourceBitmapChanged; } DetectFaceIntervalMinimumStopwatch.Reset(); DetectFaceIntervalMinimumStopwatch.Start(); while (IsDetecting) { System.Threading.Thread.Sleep(50); if (DetectFaceIntervalMinimumStopwatch.ElapsedMilliseconds > 2000) { if (ApplicationCommonSettings.IsDebugging) { Debugger.Break(); } Console.WriteLine("FaceDetection BackgroundWorkder did not completed."); break; } } if (DlibArray2dUcharImage != null) { DlibArray2dUcharImage.Dispose(); DlibArray2dUcharImage = null; } if (DlibHogSvm != null) { DlibHogSvm.Dispose(); DlibHogSvm = null; } } // release any unmanaged objects and set the object references to null disposed = true; }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { // dispose managed objects, and dispose objects that implement IDisposable if (DlibHogSvm != null) { DlibHogSvm.Dispose(); DlibHogSvm = null; } if (Image != null) { Image.Dispose(); Image = null; } } // release any unmanaged objects and set the object references to null disposed = true; }