static _Default() { System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo( HttpContext.Current.Server.MapPath("Classifiers")); FaceDetector = new DotFermion.LibFaces.FaceDetector(DotFermion.LibFaces.ClassifierType.Front, dir); }
private void button3_Click(object sender, EventArgs e) { System.IO.DirectoryInfo path = System.IO.Directory.GetParent(Assembly.GetExecutingAssembly().Location); DotFermion.LibFaces.FaceDetector detector = new DotFermion.LibFaces.FaceDetector(DotFermion.LibFaces.ClassifierType.Front, path); //MessageBox.Show(detector.ClassifierDir.ToString()); //MessageBox.Show(detector.ClassifierType.ToString()); openFileDialog1.ShowDialog(); Bitmap image = Bitmap.FromStream(openFileDialog1.OpenFile()) as Bitmap; Graphics g = Graphics.FromImage(image); var faces = detector.FindFacesUnmanaged(image); foreach (var f in faces.Faces) { StringBuilder sb = new StringBuilder(); if (f.Face != null) { sb.Append(f.Face.ToString()); g.DrawRectangle(new Pen(Brushes.Red), f.Face); } if (f.Eyes != null && f.Eyes.Count > 0) { sb.Append(" => "); sb.Append(f.Eyes.Count.ToString()); g.DrawRectangles(new Pen(Brushes.Yellow), f.Eyes.ToArray()); } listBox1.Items.Add(sb.ToString()); } pictureBox1.Image = image; }