document.write("
private void btnCapture_Click(object sender, EventArgs e)
{
if (!Directory.Exists(Application.StartupPath + "/Faces"))
{
Directory.CreateDirectory(Application.StartupPath + "/Faces");
}
count = count + 1;
grayFace = camera.QueryGrayFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
MCvAvgComp[][] detectedFaces = grayFace.DetectHaarCascade(faceDetected, 1.2, 10, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20));
foreach (MCvAvgComp f in detectedFaces[0])
{
trainedFace = frame.Copy(f.rect).Convert<Gray, byte>();
break;
}
trainedFace = result.Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
trainingImage.Add(trainedFace);
labels.Add(student.StudentName);
biometric.FaceId = string.Format("{0}.bmp", student.StudentName);
trainingImage.ToArray()[1 - 1].Save(Application.StartupPath + "/Faces/" + biometric.FaceId);
trainingImage.Add(new Image<Gray, byte>(Application.StartupPath + "/Faces/" + biometric.FaceId));
SaveBiometric(student.StudentId);
btnCapture.Enabled = false;
}
Capture face pattern - Snippet hosted by \"Cacher\"
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();
}
}
Load face recognition - Snippet hosted by \"Cacher\"
");