private void HandleFaceBoundingBoxAvailable(object sender, FaceDetectionEventArgs e) { faceLeft = e.Left; faceRight = e.Right; faceTop = e.Top; faceBottom = e.Bottom; faceLockAcquired = e.LockAcquired; }
private void OnFaceBoundingBoxAvailable(int left, int right, int top, int bottom, Boolean lockAcquired) { if (FaceBoundingBoxAvailable != null) { EventHandler <FaceDetectionEventArgs> handler = FaceBoundingBoxAvailable; FaceDetectionEventArgs e = new FaceDetectionEventArgs(left, right, top, bottom, lockAcquired); handler(this, e); } }
// To do (for the students): Write this two methods (HandleFaceDetected) to handle the face detection. Perhaps pass // the face to a recognizer? private void HandleFaceDetected(object sender, FaceDetectionEventArgs e) { // Test: Uncomment to see the bounding box of the detected face. /* string information = DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " Face detected. Bounding box: (" + e.Left.ToString() + "," + * e.Top.ToString() + "," + e.Right.ToString() + "," + e.Bottom.ToString() + ")"; * ColorListBoxItem item = new ColorListBoxItem(information, faceDetectionColorListBox.BackColor, faceDetectionColorListBox.ForeColor); * faceDetectionColorListBox.Items.Insert(0, item); */ }
private void ThreadSafeHandleFaceDetected(object sender, FaceDetectionEventArgs e) { if (e.LockAcquired) { if (InvokeRequired) { this.Invoke(new MethodInvoker(() => HandleFaceDetected(sender, e))); } else { HandleFaceDetected(sender, e); } } }
private void UserConsistencyChecker(FaceDetectionEventArgs e) { //Ignore too small detections int width = Math.Abs(e.Right - e.Left); int height = Math.Abs(e.Top - e.Bottom); if (width < minRectangleSize && height < minRectangleSize) { return; } if (sw.IsRunning) { sw.Stop(); } else { sw.Start(); return; } interpolatedFrequency = Lerp(interpolatedFrequency, (float)sw.ElapsedMilliseconds, 0.3f); sw.Reset(); Console.WriteLine(interpolatedFrequency); //Only sends to client when interpolatedFrequency passes lower than minFaceFrequency if (minFaceFrequency >= interpolatedFrequency) { if (FaceDetected == false) { Console.WriteLine(interpolatedFrequency + " HIT"); FaceDetected = true; client.Send("FaceDetected"); } } else { if (FaceDetected == true) { FaceDetected = false; client.Send("FaceUndetected"); } } sw.Start(); }