Beispiel #1
0
        public Form1()
        {
            InitializeComponent();
            //intialize the eigen recognizer to be used later
            myRecognizer = new MEigenRecognizer("E:/Project_1_1/bin/Debug/holdRecFilePath/thephotos.yml");

            //Now get the saved imagesin the TrainedFaces Folder
            try
            {
                //First get the lables of the images in the training set where the lables are the names of users
                //string getLabels = File.ReadAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt");
                // numberOfLables = Convert.ToInt16(Labels[0]);
                List <string> image = new List <string> ();
                CountTrainedFaces = image.Count;
                sqlite_conn       = new SQLiteConnection("Data Source=E:/Project_1_1/Project.db ; Version =3;");

                sqlite_conn.Open();
                sqlite_cmd = sqlite_conn.CreateCommand();
                //create command
                sqlite_cmd.CommandText = "select image_path from studentsFaces ;";
                //datareader to read from db
                sqlite_datareader = sqlite_cmd.ExecuteReader();

                while (sqlite_datareader.Read())
                {
                    image.Add(sqlite_datareader.GetString(0));
                }
                sqlite_cmd.ExecuteNonQuery();
                //close connections
                sqlite_conn.Close();
                sqlite_datareader.Close();

                string[] Labels = new string[image.Count];
                for (int i = 0; i < image.Count; i++)
                {
                    Labels[i] = image[i];
                }

                // sqlite_conn.Close();
                //Now Load the images from the TrainedFaces Folder to our List that the images to be used in the code later
                //And the labels to our List that holds the lables to be used later .
                for (int i = 0; i <= image.Count; i++)
                {
                    LoadFaces = "face" + i + ".bmp";
                    trainingImagesHolder.Add(new Image <Gray, byte>(image[i]));
                    labelsHolder.Add(Labels[i]);
                }
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.ToString());
                MessageBox.Show("Nothing in binary database, please add at least a face"
                                + " (Simply train the prototype with the Add Face Button).", "Triained faces load",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        public Dtrain()
        {
            InitializeComponent();
            try
            {
                myRecognizer      = new MEigenRecognizer("" + Environment.GetEnvironmentVariable("appdata") + "/Project_1_1/holdRecFilePath/thephotos.yml");
                CountTrainedFaces = image.Count;

                sqlite_conn = new SQLiteConnection("Data Source=" + Environment.GetEnvironmentVariable("appdata") + "/Project_1_1/Project.db ; Version =3;");
                sqlite_conn.Open();
                //store old images
                sqlite_cmd = sqlite_conn.CreateCommand();
                //create command
                sqlite_cmd.CommandText = "select image_path , student_id from studentsFaces ;";
                //datareader to read from db
                sqlite_datareader = sqlite_cmd.ExecuteReader();

                while (sqlite_datareader.Read())
                {
                    image.Add(sqlite_datareader.GetString(0));
                    Labels.Add(sqlite_datareader.GetString(1));
                }
                CountTrainedFaces = image.Count;
                sqlite_cmd.ExecuteNonQuery();
                sqlite_conn.Close();
                sqlite_datareader.Close();

                //First get the lables of the images in the training set where the lables are the names of users
                //string getLabels = File.ReadAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt");
                // numberOfLables = Convert.ToInt16(Labels[0]);


                CountTrainedFaces = image.Count;


                //datareader to re

                //Now Load the images from the TrainedFaces Folder to our List that the images to be used in the code later
                //And the labels to our List that holds the lables to be used later .
                for (int i = 0; i <= image.Count; i++)
                {
                    //  LoadFaces = "face" + i + ".bmp";
                    trainingImagesHolder.Add(new Image <Gray, byte>(image[i]));
                    labelsHolder.Add(Labels[i]);
                }
            }
            catch (Exception e)
            {
            }
        }
        public LogIn()
        {
            InitializeComponent();

            try
            {
                myRecognizer = new MEigenRecognizer("" + Environment.GetEnvironmentVariable("appdata") + "/Project_1_1/holdRecFilePath/thephotos.yml");
                sqlite_conn  = new SQLiteConnection("Data Source=" + Environment.GetEnvironmentVariable("appdata") + "/Project_1_1/Project.db ; Version =3;");

                sqlite_conn.Open();
                sqlite_cmd = sqlite_conn.CreateCommand();
                //create command
                sqlite_cmd.CommandText = "select image_path , doctor_id from doctorsFaces ;";
                //datareader to read from db
                sqlite_datareader = sqlite_cmd.ExecuteReader();

                while (sqlite_datareader.Read())
                {
                    image.Add(sqlite_datareader.GetString(0));
                    Labels.Add(sqlite_datareader.GetString(1));
                }


                sqlite_cmd.ExecuteNonQuery();
                sqlite_conn.Close();
                sqlite_datareader.Close();
                for (int i = 0; i < image.Count; i++)
                {
                    //  LoadFaces = "face" + i + ".bmp";
                    trainingImagesHolder.Add(new Image <Gray, byte>(image[i]));
                    labelsHolder.Add(Labels[i]);
                }
                // sqlite_conn.Close();
                //Now Load the images from the TrainedFaces Folder to our List that the images to be used in the code later
                //And the labels to our List that holds the lables to be used later .

                //Now after wwe added the photos to our training set holder and the lables
                integerLablesHolder = new int[labelsHolder.ToArray().Length];
                for (int i = 0; i < labelsHolder.ToArray().Length; i++)
                {
                    string[] arrayLablesHolder = labelsHolder.ToArray();
                    Int32.TryParse(arrayLablesHolder[i], out integerLablesHolder[i]);
                }
                myRecognizer.TrainRecognizer(trainingImagesHolder.ToArray(), integerLablesHolder);
            }
            catch (Exception ex) { }
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            //---------------------------------------------------------------------------------------------------------------------------------
            try
            {
                myStudentRecognizer = new MEigenRecognizer("" + Environment.GetEnvironmentVariable("appdata") + "/Project_1_1/holdRecFilePath/thephotos.yml");
                sqlite_conn         = new SQLiteConnection("Data Source=" + Environment.GetEnvironmentVariable("appdata") + "/Project_1_1/Project.db ; Version =3;");

                //-------------------------------------------------------------------------
                //here we ghet the current subject from the databse
                sqlite_conn.Open();
                sqlite_cmd = sqlite_conn.CreateCommand();
                int d1 = datetime.Hour;
                sqlite_cmd.CommandText = "select subj_id from classRoomT where place = '15' and day = '" + System.DateTime.Now.ToString("dddd") + "' " + "and " + d1 + "between fromT and toT";
                sqlite_datareader      = sqlite_cmd.ExecuteReader();
                while (sqlite_datareader.Read())
                {
                    subj = sqlite_datareader.GetString(0);
                }
                sqlite_conn.Close();
                sqlite_datareader.Close();
                //-------------------------------------------
                //Now get the Students that study this subject
                sqlite_conn.Open();
                sqlite_cmd             = sqlite_conn.CreateCommand();
                sqlite_cmd.CommandText = "select student_id from studentSubjects where subject_id ='" + subj + "';";

                sqlite_datareader = sqlite_cmd.ExecuteReader();
                while (sqlite_datareader.Read())
                {
                    m.Add(int.Parse(sqlite_datareader.GetString(0)));
                }
                sqlite_conn.Close();
                sqlite_datareader.Close();

                //----------------------------------------------
                //Now we retrieve the photos paths and the labels for the found students

                for (int i = 0; i < m.Count; ++i)
                {
                    sqlite_conn.Open();
                    sqlite_cmd             = sqlite_conn.CreateCommand();
                    sqlite_cmd.CommandText = "select image_path , student_id from studentsFaces where student_id = " + m[i];

                    sqlite_datareader = sqlite_cmd.ExecuteReader();
                    while (sqlite_datareader.Read())
                    {
                        image.Add(sqlite_datareader.GetString(0));
                        Labels.Add(sqlite_datareader.GetString(1));
                    }
                    sqlite_cmd.ExecuteNonQuery();
                    //close connections
                    sqlite_conn.Close();
                    sqlite_datareader.Close();
                }
                //------------------------------------------------------------------------
                //Now we get the photos saved in the paths ant convert it to Gray images to be able to use it in recognition
                //the add the labels to to labels holder

                for (int i = 0; i < image.Count; i++)
                {
                    //  LoadFaces = "face" + i + ".bmp";
                    trainingImagesHolder.Add(new Image <Gray, byte>(image[i]));
                    labelsHolder.Add(Labels[i]);
                }

                //----------------------------------------------------------------------------------------------
                //Now after we add the training photos and the labels to TrainingImageHolder and LAbelsHolder
                //we parse labels to intger to be able to path them to the recognizer

                integerLablesHolder = new int[labelsHolder.ToArray().Length];
                for (int i = 0; i < labelsHolder.ToArray().Length; i++)
                {
                    string[] arrayLablesHolder = labelsHolder.ToArray();
                    Int32.TryParse(arrayLablesHolder[i], out integerLablesHolder[i]);
                }
                //--------------------------------------------------------------------------------------------------------------------------------
            }
            catch (Exception ex) {
                // MessageBox.Show(ex.Message);
            }
            try
            {
                myStudentRecognizer.TrainRecognizer(trainingImagesHolder.ToArray(), integerLablesHolder);
                Atten attendance = new Atten();
                attendance.Show();
                this.Hide();
            }
            catch (Exception error)
            {
                //MessageBox.Show(e.ToString());
                NoLecture no = new NoLecture();
                no.Show();
            }
        }
        public Atten()
        {
            InitializeComponent();

            try
            {
                myRecognizer = new MEigenRecognizer("" + Environment.GetEnvironmentVariable("appdata") + "/Project_1_1/holdRecFilePath/thephotos.yml");
                sqlite_conn  = new SQLiteConnection("Data Source=" + Environment.GetEnvironmentVariable("appdata") + "/Project_1_1/Project.db ; Version =3;");


                String s = "";

                DateTime dateTime = new DateTime();

                sqlite_conn.Open();
                sqlite_cmd = sqlite_conn.CreateCommand();
                int d = datetime.Hour;
                Console.WriteLine(System.DateTime.Now.ToString("dddd"));
                sqlite_cmd.CommandText = "select subj_id from classRoomT where place = '15' and day = '" + System.DateTime.Now.ToString("dddd") + "' " + "and " + d + "between fromT and toT";

                sqlite_datareader = sqlite_cmd.ExecuteReader();
                while (sqlite_datareader.Read())
                {
                    subj = sqlite_datareader.GetString(0);
                }
                sqlite_conn.Close();
                sqlite_datareader.Close();
                // Console.WriteLine("subj" +subj);

                /*  if (subj == "") {
                 *    NoLecture no = new NoLecture();
                 *    no.Show();
                 *    this.Hide();
                 * }*/
                sqlite_conn.Open();
                sqlite_cmd             = sqlite_conn.CreateCommand();
                sqlite_cmd.CommandText = "select student_id from studentSubjects where subj_id ='" + subj + "';";

                sqlite_datareader = sqlite_cmd.ExecuteReader();
                while (sqlite_datareader.Read())
                {
                    m.Add(int.Parse(sqlite_datareader.GetString(0)));
                }


                sqlite_conn.Close();
                sqlite_datareader.Close();



                for (int i = 0; i < m.Count; ++i)
                {
                    sqlite_conn.Open();
                    sqlite_cmd             = sqlite_conn.CreateCommand();
                    sqlite_cmd.CommandText = "select image_path , student_id from studentsFaces where student_id = " + m[i];

                    sqlite_datareader = sqlite_cmd.ExecuteReader();
                    while (sqlite_datareader.Read())
                    {
                        image.Add(sqlite_datareader.GetString(0));
                        Labels.Add(sqlite_datareader.GetString(1));
                    }
                    sqlite_cmd.ExecuteNonQuery();
                    //close connections
                    sqlite_conn.Close();
                    sqlite_datareader.Close();
                }

                for (int i = 0; i < image.Count; i++)
                {
                    //  LoadFaces = "face" + i + ".bmp";
                    trainingImagesHolder.Add(new Image <Gray, byte>(image[i]));
                    labelsHolder.Add(Labels[i]);
                }
                // sqlite_conn.Close();
                //Now Load the images from the TrainedFaces Folder to our List that the images to be used in the code later
                //And the labels to our List that holds the lables to be used later .

                //Now after wwe added the photos to our training set holder and the lables
                integerLablesHolder = new int[labelsHolder.ToArray().Length];
                for (int i = 0; i < labelsHolder.ToArray().Length; i++)
                {
                    string[] arrayLablesHolder = labelsHolder.ToArray();
                    Int32.TryParse(arrayLablesHolder[i], out integerLablesHolder[i]);
                }
                myRecognizer.TrainRecognizer(trainingImagesHolder.ToArray(), integerLablesHolder);
            }
            catch (Exception ex) { }
        }