private void Form1_Load(object sender, EventArgs e) { // gridPersons.DataSource = System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Faces"); try { sconn = new SqlCeConnection("Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\FaceDataBase.sdf;Persist Security Info=false;Password=sasol321;"); scommand = new SqlCeCommand("select * from Persons", sconn); sda = new SqlCeDataAdapter(scommand); cb = new SqlCeCommandBuilder(sda); sda.InsertCommand = cb.GetInsertCommand(); sda.DeleteCommand = cb.GetDeleteCommand(); sda.UpdateCommand = cb.GetUpdateCommand(); personTable = new DataTable(); //gridPersons.AutoGenerateColumns = true; gridPersons.DataSource = personTable; sda.Fill(personTable); gridPersons.Columns[0].HeaderText = "شناسه"; gridPersons.Columns[1].HeaderText = "نام"; gridPersons.Columns[2].HeaderText = "سن"; gridPersons.Columns[3].HeaderText = "جنسیت"; gridPersons.Columns[4].HeaderText = "مسیر"; gridPersons.Columns[5].HeaderText = "تصویر"; ((DataGridViewImageColumn)gridPersons.Columns[5]).ImageLayout = DataGridViewImageCellLayout.Stretch; gridPersons.Columns[5].Width = 150; //gridPersons.Columns[4].Width = 100; for (int i = 0; i < gridPersons.Rows.Count; i++) { gridPersons.Rows[i].Height = 150; } } catch (Exception ex) { MessageBox.Show(ex.Message); } capturer = new FaceLib.Capturer(); faceExaminer = new FaceLib.FaceExaminer(); faceTrainer = new FaceLib.FaceTrainer(); }
private void button7_Click(object sender, EventArgs e) { if (rdVideo.Checked) { OpenFileDialog of = new OpenFileDialog(); of.Filter = "AVI Files|*.avi|Video CD Files|*.dat;*.vcd*|MPEG-4 Files|*.mp4|MPEG Files|*.mpeg" + "|MPEG Files|*.mpe|MPEG Files|*.mpg|Flash Video|*.flv|DIVx Video|*.divx" + "|DVD Files|*.vob|3GP Mobile Video|*.3gp|MKV Files|*.mkv|Windows Media Video Files|*.wmv|Apple Video Files|*.mov"; if (of.ShowDialog() == System.Windows.Forms.DialogResult.OK) { txtSourceVideo.Text = of.FileName; if (capturer == null) { capturer = new FaceLib.Capturer(); } if (System.IO.File.Exists(txtSourceVideo.Text)) { capturer.CaptureVideo(txtSourceVideo.Text); } CameraTimer.Enabled = true; CameraTimer.Start(); } } }
private void pictureBox1_Click(object sender, EventArgs e) { OpenFileDialog of = new OpenFileDialog(); if (chkPicFromCam.Checked) { CaptureSingleShotTimer.Stop(); string strTemp = System.IO.Path.GetTempFileName().Replace(".tmp", ".bmp"); int x = -1, y = -1, w = -1, h = -1; capturer.NextFrame(strTemp, chkAcurateFaceDetection.Checked ? 1 : 0, out x, out y, out w, out h); if (w > 0 && h > 0) { Image img = new Bitmap(strTemp); Bitmap newImg = new Bitmap(w, h); Graphics gr = Graphics.FromImage(newImg); gr.DrawImage(img, new Rectangle(0, 0, w, h), new Rectangle(x, y, w, h), GraphicsUnit.Pixel); string newPath = "Faces\\" + new Random().Next().ToString() + ".bmp"; img.Dispose(); img = null; GC.Collect(); newImg.Save(newPath); picFace.ImageLocation = newPath; System.IO.File.Delete(strTemp.Replace(".bmp", ".tmp")); System.IO.File.Delete(strTemp); } else { MessageBox.Show("تصویر انتخاب شده فاقد چهره می باشد"); } } else { of.Filter = "|*.jpeg;*.jpg;*.JPEG;*.JPG|*.bmp;*.BMP|*.png;.PNG|*.tiff;*.tif;*.TIFF;*.TIF|"; if (of.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (capturer == null) { capturer = new FaceLib.Capturer(); } int x = -1, y = -1, w = -1, h = -1; capturer.ExtractFace(of.FileName, chkAcurateFaceDetection.Checked ? 1 : 0, out x, out y, out w, out h); if (w > 0 && h > 0) { Image img = new Bitmap(of.FileName); Bitmap newImg = new Bitmap(w, h); Graphics gr = Graphics.FromImage(newImg); gr.DrawImage(img, new Rectangle(0, 0, w, h), new Rectangle(x, y, w, h), GraphicsUnit.Pixel); string newPath = "Faces\\" + new Random().Next().ToString() + ".bmp"; newImg.Save(newPath); picFace.ImageLocation = newPath; } else { MessageBox.Show("تصویر انتخاب شده فاقد چهره می باشد"); } } } }