Esempio n. 1
0
        private void buttontrain_Click(object sender, EventArgs e)
        {
            try
            {
                trainingImages.Clear();
                Names_List_ID.Clear();

                ISession session = ImageDatabase.GetCurrentSession();
                var      images  = session.CreateCriteria(typeof(PersistentImage)).List <PersistentImage>();
                for (int i = 1; i <= images.Count; i++)
                {
                    Image <Bgr, Byte> image = session.Load <PersistentImage>(i);
                    trainingImages.Add(image.Convert <Gray, Byte>());
                    Names_List_ID.Add(i);
                }
                session.Close();

                UpdateStatus(string.Format(" {0} photo for trainin.", images.Count));
            }
            catch (Exception ex)
            {
                UpdateStatus(string.Format("trained error {0}", ex));
            }
            var success = CdmFaceTrain();

            while (!success)
            {
                success = CdmFaceTrain(true);
            }
            ;
        }
Esempio n. 2
0
        private void buttonclearfaces_Click(object sender, EventArgs e)
        {
            ISession     session = ImageDatabase.GetCurrentSession();
            ITransaction tx      = session.BeginTransaction();

            session.CreateSQLQuery("delete from Images").ExecuteUpdate();
            tx.Commit();
            session.Close();
            dataGridView1.Rows.Clear();
        }
Esempio n. 3
0
        void FrameGrabber(object sender, EventArgs e)
        {
            //  UpdateStatus(string.Format("in grabber standardm,{0}", 111));
            //Get the current frame form capture device
            using (currentFrame = grabber.QueryFrame().ToImage <Bgr, Byte>())
            {
                if (currentFrame != null)
                {
                    pictureBoxsource.Image = currentFrame.Bitmap;
                    //   UpdateStatus(string.Format("in grabber standardm,{0}", 333));
                    //   gray_frame = currentFrame.Convert<Gray, Byte>();

                    //var filename = Path.GetTempFileName() + ".jpg";
                    //currentFrame.Save(filename);
                    if (HaveFace(currentFrame))
                    {
                        pictureBoxcurrentimage.Image = currentFrame.Bitmap;
                        UpdateStatus(string.Format("high quality face photo captured,{0}", ++facenum));
                        if (facenum > int.Parse(textBoxpicturesource.Text))
                        {
                            Application.Idle -= new EventHandler(FrameGrabber);
                            grabber.Dispose();
                            return;
                        }
                        ISession     session = ImageDatabase.GetCurrentSession();
                        ITransaction tx      = session.BeginTransaction();

                        try
                        {
                            PersistentImage pImage = new PersistentImage(currentFrame.Width, currentFrame.Height);
                            CvInvoke.cvCopy(currentFrame, pImage, IntPtr.Zero);
                            pImage.DateCreated = DateTime.Now;
                            //  UpdateStatus(string.Format("add face to sqlite error,{0}", 111));
                            session.Save(pImage);
                            // UpdateStatus(string.Format("add face to sqlite error,{0}", 222));
                            tx.Commit();
                        }
                        catch (Exception ex)
                        {
                            UpdateStatus(string.Format("add face to sqlite error,{0}", ex));
                        }


                        session.Close();
                    }
                }
            }
            ;
            //  UpdateStatus(string.Format("in grabber standardm,{0}", 222));
            //Convert it to Grayscale
        }
Esempio n. 4
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == dataGridView1.Columns["viewColumn"].Index)
     {
         int               imageID = (int)dataGridView1.Rows[e.RowIndex].Cells["idColumn"].Value;
         ISession          session = ImageDatabase.GetCurrentSession();
         Image <Bgr, Byte> image   = session.Load <PersistentImage>(imageID);
         session.Close();
         pictureBoxcurrentimage.Image = image.Bitmap;
         //using (ImageViewer viewer = new ImageViewer())
         //{
         //    viewer.Image = image;
         //    viewer.ShowDialog();
         //}
     }
 }
Esempio n. 5
0
        public IList <PersistentImage> GetImages()
        {
            IList <PersistentImage> images = new List <PersistentImage>();

            try
            {
                ISession session = ImageDatabase.GetCurrentSession();
                images = session.CreateCriteria(typeof(PersistentImage)).List <PersistentImage>();
                session.Close();
            }
            catch (Exception ex)
            {
                richTextBox1.AppendText(Environment.NewLine + ex.Message);
            }

            return(images);
        }