| public partial class Biometric : Form |
| { |
| MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_TRIPLEX, 0.6d, 0.6d); |
| HaarCascade faceDetected; |
| Image<Bgr, Byte> frame; |
| Capture camera; |
| Image<Gray, byte> result; |
| Image<Gray, byte> trainedFace = null; |
| Image<Gray, byte> grayFace = null; |
| List<Image<Gray, byte>> trainingImage = new List<Image<Gray, byte>>(); |
| List<string> labels = new List<string>(); |
| List<string> users = new List<string>(); |
| int count, numLabeles, t; |
| string name, names = null; |
| |
| public Biometric() |
| { |
| InitializeComponent(); |
| student = LoadDetails(Register.StudentId); |
| StartWebcam(); |
| } |
| |
| private void StartWebcam() |
| { |
| try |
| { |
| faceDetected = new HaarCascade("haarcascade_frontalface_default.xml"); |
| camera = new Capture(); |
| camera.QueryFrame(); |
| Application.Idle += new EventHandler(FrameProcedure); |
| } |
| catch (Exception ex) |
| { |
| MessageBox.Show(ex.Message); |
| } |
| } |
| |
| private void FrameProcedure(object sender, EventArgs e) |
| { |
| users.Add(""); |
| frame = camera.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC); |
| grayFace = frame.Convert<Gray, Byte>(); |
| MCvAvgComp[][] faceDetectedNow = grayFace.DetectHaarCascade(faceDetected, 1.2, 10, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20)); |
| |
| if (faceDetectedNow[0].Count() > 1) |
| { |
| AbortRegistraction(student.StudentId); |
| LogEvent(student.StudentId, "Two person detected. registration aborted"); |
| MessageBox.Show("Two person detected. registration aborted"); |
| Login login = new Login(); |
| login.Show(); |
| this.Close(); |
| } |
| |
| foreach (MCvAvgComp f in faceDetectedNow[0]) |
| { |
| result = frame.Copy(f.rect).Convert<Gray, Byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC); |
| frame.Draw(f.rect, new Bgr(Color.Green), 3); |
| if (trainingImage.ToArray().Length != 0) |
| { |
| MCvTermCriteria termCriterias = new MCvTermCriteria(count, 0.001); |
| EigenObjectRecognizer recognizer = new EigenObjectRecognizer(trainingImage.ToArray(), labels.ToArray(), 1500, ref termCriterias); |
| name = recognizer.Recognize(result); |
| frame.Draw(name, ref font, new Point(f.rect.X - 2, f.rect.Y - 2), new Bgr(Color.Red)); |
| } |
| users.Add(""); |
| } |
| cameraBox.Image = frame; |
| name = ""; |
| users.Clear(); |
| } |
| } |