예제 #1
0
        public void Train()
        {
            List <Course> listOfCourses = Course.getCourses();

            foreach (Course course in listOfCourses)
            {
                List <Image <Gray, byte> > images = new List <Image <Gray, byte> >();
                List <int> idsTrainned            = new List <int>();

                List <int> studentIdsInGivenCourse = Student.getStudentIDsGivenCourseId(course.getId());

                var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var settings   = configFile.AppSettings.Settings;

                for (int i = 0; i < studentIdsInGivenCourse.Count; i++)
                {
                    String        extFacesPath = configFile.AppSettings.Settings["ExtFacesPath"].Value + "\\" + studentIdsInGivenCourse[i];
                    DirectoryInfo dInfo        = new DirectoryInfo(extFacesPath);

                    var allImages = dInfo.GetFiles("*.bmp"); //get from this directory all files contain ".bmp"
                    foreach (var image in allImages)
                    {
                        string             photoPath = extFacesPath + "\\" + image;
                        Image <Gray, byte> img       = new Image <Gray, byte>(photoPath).Resize(200, 200, Inter.Cubic);
                        img._EqualizeHist();
                        img.Save(photoPath);
                        images.Add(img);
                        idsTrainned.Add(studentIdsInGivenCourse[i]);
                    }
                }
                string trainingFilePath = configFile.AppSettings.Settings["TrainingFilesPath"].Value;
                String trainFile1       = trainingFilePath + course.getCrsCode() + "-1";
                String trainFile2       = trainingFilePath + course.getCrsCode() + "-2";
                String trainFile3       = trainingFilePath + course.getCrsCode() + "-3";

                if (images.Count > 0)
                {
                    fr1.Train(images.ToArray(), idsTrainned.ToArray()); //this line is self explanatory
                    fr1.Save(trainFile1);                               //saving the trainig
                    //fr2.Train(images.ToArray(), idsTrainned.ToArray());//this line is self explanatory
                    //fr2.Save(trainFile2);//saving the trainig
                    fr3.Train(images.ToArray(), idsTrainned.ToArray());
                    fr3.Save(trainFile3);//saving the trainig
                }
            }

            FinishAddStudent fas = new FinishAddStudent();

            fas.Tag = this;
            fas.Show(this);
            Hide();
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked && count < ExtFaces.Count)
            {
                Image <Gray, byte> ExtracreFaceAsImage = new Image <Gray, byte>(ExtFaces[count]).Resize(295, 268, Inter.Cubic);

                imageBox1.Image = ExtracreFaceAsImage;

                var    configFile   = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var    settings     = configFile.AppSettings.Settings;
                String extFacesPath = configFile.AppSettings.Settings["ExtFacesPath"].Value;

                string path     = @"ids.txt";
                string id       = "";
                string tempPath = "";
                using (System.IO.StreamReader sr = System.IO.File.OpenText(path))
                {
                    id       = sr.ReadLine();
                    tempPath = extFacesPath + id + "\\";
                }
                Debug.WriteLine("path is " + tempPath);
                if (!Directory.Exists(tempPath))
                {
                    //MessageBox.Show("path is " + tempPath, "My Application", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                    Directory.CreateDirectory(tempPath);
                }

                ExtFaces[count - 1].Save(tempPath + id + "_" + count2 + ".bmp");
                count++;
                count2++;
                checkBox1.Checked = false;
            }
            else if (!checkBox1.Checked && count < ExtFaces.Count)
            {
                Image <Gray, byte> ExtracreFaceAsImage = new Image <Gray, byte>(ExtFaces[count]).Resize(295, 268, Inter.Cubic);
                imageBox1.Image = ExtracreFaceAsImage;
                count++;
            }
            if (count == ExtFaces.Count - 1)
            {
                FinishAddStudent fad = new FinishAddStudent();
                fad.Tag = this;
                fad.Show(this);
                Hide();
            }
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked && count < ExtFaces.Count)
            {
                pictureBox1.Image = new Bitmap(ExtFaces[count]);
                    
                var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var settings = configFile.AppSettings.Settings;
                String extFacesPath = configFile.AppSettings.Settings["ExtFacesPath"].Value;

                string path = @"ids.txt";
                string id = "";
                string tempPath = "";
                using (System.IO.StreamReader sr = System.IO.File.OpenText(path))
                {                        
                    id = sr.ReadLine();
                    tempPath = extFacesPath + id + "\\";                    
                }
                Debug.WriteLine("path is " + tempPath);
                if (!Directory.Exists(tempPath))
                {
                    //MessageBox.Show("path is " + tempPath, "My Application", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                    Directory.CreateDirectory(tempPath);
                }
                
                ExtFaces[count - 1].Save(tempPath + id + "_" + count2 + ".bmp");
                count++;
                count2++;
                checkBox1.Checked = false;
            }
            else if (!checkBox1.Checked && count < ExtFaces.Count)
            {
                pictureBox1.Image = new Bitmap(ExtFaces[count]);
                count++;
            }
            if (count == ExtFaces.Count - 1)
            {
                FinishAddStudent fad = new FinishAddStudent();
                fad.Tag = this;
                fad.Show(this);
                Hide();
            }
        }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked && count < ExtFaces.Count)
            {
                pictureBox1.Image = new Bitmap(ExtFaces[count]);

                var    configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var    settings   = configFile.AppSettings.Settings;
                String coursePath = configFile.AppSettings.Settings["CoursesPath"].Value;

                string path     = @"ids.txt";
                string s        = "";
                string tempPath = "";
                using (System.IO.StreamReader sr = System.IO.File.OpenText(path))
                {
                    s        = sr.ReadLine();
                    tempPath = coursePath + courseName_ + "\\" + s + "\\";
                }

                if (!Directory.Exists(tempPath))
                {
                    Directory.CreateDirectory(tempPath);
                }

                ExtFaces[count - 1].Save(tempPath + s + "_" + count2 + ".bmp");
                count++;
                count2++;
                checkBox1.Checked = false;
            }
            else if (!checkBox1.Checked && count < ExtFaces.Count)
            {
                pictureBox1.Image = new Bitmap(ExtFaces[count]);
                count++;
            }
            if (count == ExtFaces.Count - 1)
            {
                FinishAddStudent fad = new FinishAddStudent(courseName_);
                fad.Tag = this;
                fad.Show(this);
                Hide();
            }
        }
예제 #5
0
        public void Train()
        {
            string path  = @"courses.txt";
            string path2 = @"enrollement.txt";

            // loop on courses file getting each course and loop on each course getting enrolled students in
            string[] linesCoursesFile = System.IO.File.ReadAllLines(path);

            foreach (string courseLine in linesCoursesFile)
            {
                string[] courseSplitter = courseLine.Split(':');
                string   courseCode     = courseSplitter[0].Trim();

                List <Image <Gray, byte> > images = new List <Image <Gray, byte> >();
                List <int> ids         = new List <int>();
                List <int> idsTrainned = new List <int>();

                string[] linesEnrollementFile = System.IO.File.ReadAllLines(path2);

                foreach (string line in linesEnrollementFile)
                {
                    string[] splitter = line.Split(',');

                    if (splitter[1].Trim().Equals(courseCode))
                    {
                        ids.Add(Int32.Parse(splitter[0].Trim()));
                    }
                }
                var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var settings   = configFile.AppSettings.Settings;

                for (int i = 0; i < ids.Count; i++)
                {
                    String        extFacesPath = configFile.AppSettings.Settings["ExtFacesPath"].Value + "\\" + ids[i];
                    DirectoryInfo dInfo        = new DirectoryInfo(extFacesPath);

                    var allImages = dInfo.GetFiles("*.bmp"); //get from this directory all files contain ".bmp"
                    foreach (var image in allImages)
                    {
                        string             photoPath = extFacesPath + "\\" + image;
                        Image <Gray, byte> img       = new Image <Gray, byte>(photoPath).Resize(200, 200, Inter.Cubic);
                        img._EqualizeHist();
                        img.Save(photoPath);
                        images.Add(img);
                        idsTrainned.Add(ids[i]);
                    }
                }

                string h1Path = configFile.AppSettings.Settings["h1FilePath"].Value + "\\" + "h1_" + courseCode;
                string h2Path = configFile.AppSettings.Settings["h2FilePath"].Value + "\\" + "h2_" + courseCode;
                string h3Path = configFile.AppSettings.Settings["h3FilePath"].Value + "\\" + "h3_" + courseCode;

                if (images.Count > 0)
                {
                    fr1.Train(images.ToArray(), idsTrainned.ToArray()); //this line is self explanatory
                    fr1.Save(h1Path);                                   //saving the trainig
                    //fr2.Train(images.ToArray(), idsTrainned.ToArray());//this line is self explanatory
                    //fr2.Save(h2Path);//saving the trainig
                    fr3.Train(images.ToArray(), idsTrainned.ToArray());
                    fr3.Save(h3Path);//saving the trainig
                }
            }

            FinishAddStudent fas = new FinishAddStudent();

            fas.Tag = this;
            fas.Show(this);
            Hide();
        }
예제 #6
0
        public void Train()
        {
            List <Image <Gray, byte> > images = new List <Image <Gray, byte> >();
            List <int> ids = new List <int>();


            var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var settings   = configFile.AppSettings.Settings;

            String coursePath = configFile.AppSettings.Settings["CoursesPath"].Value;

            string path     = @"ids.txt";
            string s        = "";
            string tempPath = "";

            using (System.IO.StreamReader sr = System.IO.File.OpenText(path))
            {
                s        = sr.ReadLine();
                tempPath = coursePath + courseName_ + "\\";
            }

            DirectoryInfo dInfo = new DirectoryInfo(tempPath);

            DirectoryInfo[] subdirs = dInfo.GetDirectories();

            for (int i = 0; i < subdirs.Length; i++)
            {
                var allImages = subdirs[i].GetFiles("*.bmp"); //get from this directory all files contain ".bmp"

                foreach (var image in allImages)
                {
                    string             temp = tempPath + subdirs[i] + "\\" + image;
                    Image <Gray, byte> img  = new Image <Gray, byte>(temp).Resize(200, 200, Inter.Cubic);
                    img._EqualizeHist();
                    img.Save(temp);
                    images.Add(img);
                    ids.Add(Int32.Parse(subdirs[i].Name));
                }
            }
            tempPath += "trainingFiles\\";
            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }

            string h1Path = tempPath + "h1";
            string h2Path = tempPath + "h2";
            string h3Path = tempPath + "h3";


            fr1.Train(images.ToArray(), ids.ToArray()); //this line is self explanatory
            fr1.Save(h1Path);                           //saving the trainig
            //fr2.Train(images.ToArray(), ids.ToArray());//this line is self explanatory
            //fr2.Save(h2Path);//saving the trainig
            fr3.Train(images.ToArray(), ids.ToArray());
            fr3.Save(h3Path);//saving the trainig

            FinishAddStudent fas = new FinishAddStudent(courseName_);

            fas.Tag = this;
            fas.Show(this);
            Hide();
        }
예제 #7
0
        public void Train()
        {
            string path = @"courses.txt";
            string path2 = @"enrollement.txt";
            
            // loop on courses file getting each course and loop on each course getting enrolled students in
            string[] linesCoursesFile = System.IO.File.ReadAllLines(path);

            foreach (string courseLine in linesCoursesFile)
            {
                string[] courseSplitter = courseLine.Split(':');
                string courseCode = courseSplitter[0].Trim();

                List<Image<Gray, byte>> images = new List<Image<Gray, byte>>();
                List<int> ids = new List<int>();
                List<int> idsTrainned = new List<int>();

                string[] linesEnrollementFile = System.IO.File.ReadAllLines(path2);
                
                foreach (string line in linesEnrollementFile)
                {   
                    string[] splitter = line.Split(',');
                    
                    if (splitter[1].Trim().Equals(courseCode))
                    {
                        ids.Add(Int32.Parse(splitter[0].Trim()));
                    }
                }
                var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var settings = configFile.AppSettings.Settings;
                
                for(int i=0 ; i<ids.Count ; i++)
                {
                    String extFacesPath = configFile.AppSettings.Settings["ExtFacesPath"].Value + "\\" + ids[i];
                    DirectoryInfo dInfo = new DirectoryInfo(extFacesPath);

                    var allImages = dInfo.GetFiles("*.bmp"); //get from this directory all files contain ".bmp"
                    foreach (var image in allImages)
                    {
                        string photoPath = extFacesPath + "\\" + image;
                        Image<Gray, byte> img = new Image<Gray, byte>(photoPath).Resize(200, 200, Inter.Cubic);
                        img._EqualizeHist();
                        img.Save(photoPath);
                        images.Add(img);
                        idsTrainned.Add( ids[i] );
                    }
                }
                
                string h1Path = configFile.AppSettings.Settings["h1FilePath"].Value + "\\" + "h1_" + courseCode;
                string h2Path = configFile.AppSettings.Settings["h2FilePath"].Value + "\\" + "h2_" + courseCode;
                string h3Path = configFile.AppSettings.Settings["h3FilePath"].Value + "\\" + "h3_" + courseCode;
                
                if(images.Count > 0)
                {
                    fr1.Train(images.ToArray(), idsTrainned.ToArray());//this line is self explanatory
                    fr1.Save(h1Path);//saving the trainig 
                    //fr2.Train(images.ToArray(), idsTrainned.ToArray());//this line is self explanatory
                    //fr2.Save(h2Path);//saving the trainig 
                    fr3.Train(images.ToArray(), idsTrainned.ToArray());
                    fr3.Save(h3Path);//saving the trainig
                }
            }

            FinishAddStudent fas = new FinishAddStudent();
            fas.Tag = this;
            fas.Show(this);
            Hide();
        }