private bool MatchFaces(Bitmap bitmap) { var imageReceived = DetectFaceTrainer(new List <Bitmap> { bitmap }); if ((imageReceived == null) || (imageReceived.Count() == Decimal.Zero)) { return(false); } LBPHFaceRecognizer.PredictionResult ER = recognizer.Predict(imageReceived[0]); return(ER.Label > -1); }
private void FrameProcedure(object sender, EventArgs e) { //A list of string defined at class level _user.Add(""); //Resize the current image taken by camera and save into Bgr _frame //_frame = _camera.QueryFrame().Resize(320, 244, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC); _frame = _camera.QueryFrame().ToImage <Bgr, Byte>(); //Convert the image into gray scale _grayFace = _frame.Convert <Gray, Byte>(); //Face detector, detects the face from gray scale image captured by the camera using a FaceDet xml with threshold values var faceDetectedNow = _faceDet.DetectMultiScale( _grayFace, 1.1, 1, new Size(30, 30), new Size(200, 200)); //Everytime a face is detected by the camera foreach (var f in faceDetectedNow) { //if(faceDetectedNow.Count() != 0) //{ _t = _t + 1; //f.rect (Bounding rectangle for the object (average rectangle of a group) //_result is a gray scale image //Convert the detected image into gray scale and resize it, then save it into _result _result = _frame.Copy(f).Convert <Gray, Byte>().Resize(500, 500, Emgu.CV.CvEnum.Inter.Cubic); //_frame (a Bgr image) //Draw a rectangle(of detected image) on the frame with a specific color and thickness _frame.Draw(f, new Bgr(Color.Red), 2); //_traineImages is a list of images // If there exist any previous training images then if (LoadData._traineImages.Count != 0) { //======================recognizer================================= //predicting result LBPHFaceRecognizer.PredictionResult ER = LoadData.recog.Predict(_result); int temp_result = ER.Label; //int temp_result = LoadData.recog.Predict(_result).Label; imageBox1.SizeMode = PictureBoxSizeMode.StretchImage; imageBox1.Image = _result.Mat; //Displaying predicted result on screen //if ((temp_result != -1)) if ((temp_result != -1) && (ER.Distance < 55)) { Console.Write("---> " + temp_result + " "); _frame.Draw( temp_result.ToString(), new Point(f.X - 2, f.Y - 2), FontFace.HersheyComplex, 1.1, new Bgr(Color.LightGreen) ); //check if attendance is already marked //if yes then do nothing or display a message //if no then mark attendance and put an entry into markedAttendance log if (LoadData.markedAttendance.ToArray().Count() == 0) { //mark attendance markAttendance(temp_result); //========================add entry============================== CheckInLog c1 = new CheckInLog(); c1.ID = temp_result; c1.checkIn = DateTime.Now.AddMinutes(2); LoadData.markedAttendance.Add(c1); Console.WriteLine("first user added: " + c1.ID + " " + c1.checkIn); } else { bool found_flag = false; foreach (CheckInLog C in LoadData.markedAttendance.ToArray())// checking if attendance is already marked or not and if user can mark again { Console.WriteLine("comparing " + C.ID + " WITH " + temp_result); if (C.ID == temp_result) { Console.WriteLine("attendance already marked!!"); DateTime current = DateTime.Now; if ((C.checkIn.TimeOfDay == current.TimeOfDay) || (C.checkIn.TimeOfDay < current.TimeOfDay))//greater or equal { Console.WriteLine("time is equal!!.. can mark attendance now"); //mark attendance markAttendance(temp_result); //========================add entry============================== CheckInLog c1; c1.ID = temp_result; c1.checkIn = DateTime.Now.AddMinutes(2); LoadData.markedAttendance.Add(c1); found_flag = true; Console.WriteLine("user second entry added: " + c1.ID + " " + c1.checkIn); LoadData.markedAttendance.Remove(C); } else { Console.WriteLine("2 mins not passed!!.. can not mark attendance"); found_flag = true; } } } if (found_flag == false) {// If the user if new i.e that no record was found in attendance log //mark attendance markAttendance(temp_result); //========================add entry============================== CheckInLog c1; c1.ID = temp_result; c1.checkIn = DateTime.Now.AddMinutes(2); LoadData.markedAttendance.Add(c1); Console.WriteLine("new user added: " + c1.ID + " " + c1.checkIn); } } } } } imgBoxCamera.Image = _frame; }