void Device_CameraViewImageSourceBitmapCapture_CameraViewImageSourceBitmapChanged(object sender, EventArgs e) { if (Device.Settings.FaceDetectionMethod.Value != PropertyTypes.FaceDetectionMethods.DefaultProcessOnEgsHostApplication) { return; } if (Device.IsDetectingFaces == false) { return; } if (false && ApplicationCommonSettings.IsDebugging) { // Draw the latest result before return; if (SelectedFaceRect.HasValue) { using (var g = System.Drawing.Graphics.FromImage(Device.CameraViewImageSourceBitmapCapture.CameraViewImageSourceBitmap)) { var pen = new System.Drawing.Pen(System.Drawing.Brushes.Green, 5); g.DrawRectangle(pen, SelectedFaceRect.Value); } } } if (DetectFaceIntervalMinimumStopwatch.ElapsedMilliseconds < DetectFaceIntervalMillisecondsMinimum) { return; } DetectFaceIntervalMinimumStopwatch.Reset(); DetectFaceIntervalMinimumStopwatch.Start(); DetectFaceRunWorkerAsync(Device.CameraViewImageSourceBitmapCapture.CameraViewImageSourceBitmap); }
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; }