Ejemplo n.º 1
0
 private Bitmap ReadBitmap(string path)
 {
     if (path.EndsWith("pgm"))
     {
         return(PNM.ReadPNM(listdata[pathIndex].filePath) as Bitmap);
     }
     else
     {
         return(new Bitmap(listdata[pathIndex].filePath));
     }
 }
Ejemplo n.º 2
0
        private void SetPathToWindow(TrainingData path)
        {
            FilePathValue.Text     = path.filePath.Substring(path.filePath.LastIndexOf('\\') + 1);
            currentData.filePath   = path.filePath;
            CBGender.SelectedValue = path.label;
            Bitmap source;

            if (currentData.filePath.EndsWith("pgm"))
            {
                Bitmap     bmp      = PNM.ReadPNM(currentData.filePath) as Bitmap;
                ColorImage imgDetec = new ColorImage(bmp);
                faces = _genderClassifier.GetFaces(imgDetec);
                foreach (Rectangle face in faces)
                {
                    imgDetec.Draw(face, new Emgu.CV.Structure.Bgr(System.Drawing.Color.AliceBlue), 1);
                }
                TBFaces.Text = string.Format("Faces: {0}", faces.Count);
                source       = imgDetec.ToBitmap();
            }
            else
            {
                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(currentData.filePath, UriKind.Absolute);
                bi3.EndInit();
                ColorImage imgDetec = new ColorImage(bi3.ToBitmap());
                faces = _genderClassifier.GetFaces(imgDetec);
                foreach (Rectangle face in faces)
                {
                    imgDetec.Draw(face, new Emgu.CV.Structure.Bgr(System.Drawing.Color.AliceBlue), 1);
                }
                TBFaces.Text = string.Format("Faces: {0}", faces.Count);
                source       = imgDetec.ToBitmap();
            }
            TBDimen.Text = string.Format("W: {0} H: {1}", (int)source.Width, (int)source.Height);
            if (CBTrainer.IsChecked == true)
            {
                GrayImage img = new GrayImage(source);
                img.Processing();
                source = img.ToBitmap();
            }
            Photo.Source = source.ToBitmapImage();
        }