Beispiel #1
0
 /// <summary>
 ///
 ///        //////////////////////////////START OF FACE READER CODE///////////////////
 ///
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Reader_FaceFrameArrived(object sender, FaceFrameArrivedEventArgs e)
 {
     using (FaceFrame faceFrame = e.FrameReference.AcquireFrame())
     {
         if (faceFrame != null)
         {
             this.faceFrameResult = faceFrame.FaceFrameResult;
             if (this.faceFrameResult != null)
             {
                 string RClosed        = DetectionResult.Maybe.ToString();
                 string LClosed        = DetectionResult.Maybe.ToString();
                 var    faceProperties = this.faceFrameResult.FaceProperties;
                 foreach (var PropF in faceProperties)
                 {
                     if (PropF.Key.ToString() == "RightEyeClosed")
                     {
                         TOPRINT += PropF.Key.ToString() + " : ";
                         if (PropF.Value == DetectionResult.Maybe)
                         {
                             TOPRINT += DetectionResult.No + Environment.NewLine;
                         }
                         else
                         {
                             TOPRINT += PropF.Value.ToString() + Environment.NewLine;
                         }
                         RClosed = PropF.Value.ToString();
                     }
                     if (PropF.Key.ToString() == "LeftEyeClosed")
                     {
                         TOPRINT += PropF.Key.ToString() + " : ";
                         if (PropF.Value == DetectionResult.Maybe)
                         {
                             TOPRINT += DetectionResult.No + Environment.NewLine;
                         }
                         else
                         {
                             TOPRINT += PropF.Value.ToString() + Environment.NewLine;
                         }
                         LClosed = PropF.Value.ToString();
                     }
                 }
                 if (LClosed == "Yes" && RClosed == "Yes")
                 {
                     EndBlink = 1;
                     if (BetweenBlink > 0)
                     {
                         FrameBetFreq.Add(BetweenBlink);
                         if (FrameBetFreq.Count > 20)
                         {
                             FrameBetFreq.RemoveAt(0);
                         }
                     }
                     BetweenBlink = 0;
                     FrameBlink  += 1;
                     if (FrameBlink >= 15)
                     {
                         TOPRINT += "Not a blink, Eyes kept closed";
                         EndBlink = 0;
                     }
                 }
                 else
                 {
                     if (EndBlink == 1)
                     {
                         if (PointsData != null)
                         {
                             if (FrameBetFreq.Count >= 5)
                             {
                                 UnknownSubj.FreqOfBlinks = CalcFreq(FrameBetFreq);
                             }
                             UnknownSubj.SpeedOfBlinks.Add(CalculateSpeed(PointsData));
                             UnknownSubj.AccelOfBlinks.Add(CalculateAccel(PointsData));
                             UnknownSubj.SpeedOfBlinks.RemoveAt(0);
                             UnknownSubj.AccelOfBlinks.RemoveAt(0);
                             List <double> SpeedDif = UnknownSubj.SpeedOfBlinks(0);
                             List <double> AccelDif = UnknownSubj.AccelOfBlinks(0);
                             int           freqdif  = 0;
                             foreach (BiometricData Subject in Record)
                             {
                                 for (int n = 0; n < Subject.SpeedOfBlinks.Count; n++)
                                 {
                                     for (int i = 0; i < Subject.SpeedOfBlinks(n).Count; i++)
                                     {
                                         for (int j = 0; j < Subject.SpeedOfBlinks(n)(i).Count; j++)
                                         {
                                             foreach (double point in Subject.SpeedOfBlinks(n)(i)(j))
                                             {
                                                 SpeedDif.Add(UnknownSubj.SpeedOfBlinks(0)(i)(j) - Subject.SpeedOfBlinks(n)(i)(j));
                                             }
                                         }
                                     }
                                     for (int i = 0; i < Subject.AccelOfBlinks(n).Count; i++)
                                     {
                                         for (int j = 0; j < Subject.AccelOfBlinks(n)(i).Count; j++)
                                         {
                                             foreach (double point in Subject.AccelOfBlinks(n)(i)(j))
                                             {
                                                 AccelDif.Add(UnknownSubj.AccelOfBlinks(0)(i)(j) - Subject.AccelOfBlinks(n)(i)(j));
                                             }
                                         }
                                     }
                                     freqdif = UnknownSubj.FreqOfBlinks - Subject.FreqOfBlinks;
                                     double StotalDiff = 0;
                                     double AtotalDiff = 0;
                                     for (int j = 0; j < SpeedDif(0).Count; j++)
                                     {
                                         StotalDiff += Math.Abs(SpeedDif(0)(j));
                                     }
                                     for (int j = 0; j < AccelDif(0).Count; j++)
                                     {
                                         AtotalDiff += Math.Abs(AccelDif(0)(j));
                                     }
                                     if (StotalDiff < 5 && AtotalDiff < 5 && freqdif < 5)
                                     {
                                         UnknownSubj.Name = Subject.Name;
                                     }
                                 }
                             }
                             TOPRINT += "Subject in frame: " + UnknownSubj.Name.ToString;
                         }
                     }
                     FrameBlink    = 0;
                     BetweenBlink += 1;
                     TOPRINT      += "Frame betweem blink, Frame: " + BetweenBlink.ToString() + Environment.NewLine;
                     if (LClosed == "Yes" || RClosed == "Yes")
                     {
                         TOPRINT += "Wink! not a blink!" + Environment.NewLine;
                     }
                     EndBlink = 0;
                 }
             }
         }
         Writer.WriteLine(TOPRINT);
         TOPRINT = "";
     }
 }