Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int selectedIndex = lvResults.SelectedIndices[0];

            if (selectedIndex >= 0 && selectedIndex < rcgnResultList.Count)
            {
                string sourceFile = rcgnResultList[selectedIndex].FileName;
                string destFile   = Program.trainingSetDir + @"\" + Path.GetFileName(sourceFile);

                // Check if this image is already part of the training set
                if (File.Exists(destFile))
                {
                    System.Windows.Forms.MessageBox.Show("This image already exist in the training set.");
                    return;
                }

                // Copy the result image file to training set folder
                System.IO.File.Copy(sourceFile, destFile, true);

                // Add the item to the training set
                TrainingItem item = new TrainingItem();
                item.FileName = Path.GetFileName(sourceFile);
                item.Label    = txtLabel.Text;
                item.AddToCSV(Program.trainingSetCSVFile);

                // Process the update training set and update the display tabs
                //ilTrainingSet.Images.Clear();
                //lvTrainingSet.Items.Clear();
                //ilEigenFaces.Images.Clear();
                //lvEigenFaces.Items.Clear();
                //Program.Train();
                //showTrainingSet();
                //showEigenFaces();
            }
        }
        // Converts the images in a directory into the appropriate dimension
        // and saves them to the trianing set directory
        public static void Convert()
        {
            // Load the images in the directory with training set images
            DirectoryInfo di = new DirectoryInfo(@".\trainingset\tests");
            FileInfo[] fi = di.GetFiles("*", SearchOption.TopDirectoryOnly);

            // Empty the data csv file
            System.IO.File.WriteAllText(trainingSetCSVFile, "FileName, Label\r\n");

            foreach (FileInfo file in fi)
            {
                //// Convert the image into gray and the training width and height
                //Image<Gray, Byte> image = new Image<Gray, Byte>(file.FullName);
                //image = image.Resize(trainingImgWidth, trainingImgHeight, INTER.CV_INTER_CUBIC);

                //// Save file in bmp
                //string label = Path.GetFileNameWithoutExtension(file.FullName);
                //string fileName = label + imageExt;
                //image.Save(@".\trainingset\" + fileName);

                List<RecognizerResult> list = Detect(file.FullName);
                string fileName = Path.GetFileName(list[0].FileName);
                File.Move(list[0].FileName, trainingSetDir + @"/" + fileName);

                // Add item to CSV
                TrainingItem item = new TrainingItem();
                item.FileName = fileName;
                item.Label = Path.GetFileNameWithoutExtension(list[0].FileName);
                item.AddToCSV(trainingSetCSVFile);
            }
        }
Example #3
0
        // Converts the images in a directory into the appropriate dimension
        // and saves them to the trianing set directory
        public static void Convert()
        {
            // Load the images in the directory with training set images
            DirectoryInfo di = new DirectoryInfo(@".\trainingset\tests");

            FileInfo[] fi = di.GetFiles("*", SearchOption.TopDirectoryOnly);

            // Empty the data csv file
            System.IO.File.WriteAllText(trainingSetCSVFile, "FileName, Label\r\n");

            foreach (FileInfo file in fi)
            {
                //// Convert the image into gray and the training width and height
                //Image<Gray, Byte> image = new Image<Gray, Byte>(file.FullName);
                //image = image.Resize(trainingImgWidth, trainingImgHeight, INTER.CV_INTER_CUBIC);

                //// Save file in bmp
                //string label = Path.GetFileNameWithoutExtension(file.FullName);
                //string fileName = label + imageExt;
                //image.Save(@".\trainingset\" + fileName);

                List <RecognizerResult> list = Detect(file.FullName);
                string fileName = Path.GetFileName(list[0].FileName);
                File.Move(list[0].FileName, trainingSetDir + @"/" + fileName);

                // Add item to CSV
                TrainingItem item = new TrainingItem();
                item.FileName = fileName;
                item.Label    = Path.GetFileNameWithoutExtension(list[0].FileName);
                item.AddToCSV(trainingSetCSVFile);
            }
        }
Example #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int selectedIndex = lvResults.SelectedIndices[0];
            if (selectedIndex >= 0 && selectedIndex < rcgnResultList.Count)
            {
                string sourceFile = rcgnResultList[selectedIndex].FileName;
                string destFile = Program.trainingSetDir + @"\" + Path.GetFileName(sourceFile);

                // Check if this image is already part of the training set
                if (File.Exists(destFile))
                {
                    System.Windows.Forms.MessageBox.Show("This image already exist in the training set.");
                    return;
                }

                // Copy the result image file to training set folder
                System.IO.File.Copy(sourceFile, destFile, true);

                // Add the item to the training set
                TrainingItem item = new TrainingItem();
                item.FileName = Path.GetFileName(sourceFile);
                item.Label = txtLabel.Text;
                item.AddToCSV(Program.trainingSetCSVFile);

                // Process the update training set and update the display tabs
                //ilTrainingSet.Images.Clear();
                //lvTrainingSet.Items.Clear();
                //ilEigenFaces.Images.Clear();
                //lvEigenFaces.Items.Clear();
                //Program.Train();
                //showTrainingSet();
                //showEigenFaces();
            }
        }