Exemple #1
0
 private void TestsetManagerForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     //before closing ask if the user wants to save changes, if they were made
     if (!oldTestSet.Equals(currentTestSet))
     {
         DialogResult dialogResult = MessageBox.Show("Wijzigingen opslaan?", "Opslaan", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             //Save changes to *.xml file
             oldTestSet = (TestSetFile)currentTestSet.Clone();
             currentTestSet.writeToFile();
         }
         else if (dialogResult == DialogResult.No)
         {
             //Revert changes
             currentTestSet = (TestSetFile)oldTestSet.Clone();
         }
     }
 }
        private void executeFaceRecognition()
        {
            //array containing the 16 facial parameters resulting from the program
            double[] facialParamters = doFaceRecognitionTask(mainPictureBox.Image);

            //When the algorithm is unsuccesful, the facial parameters can be null
            if (facialParamters != null)
            {
                //Gezicht inscannen
                if (scanRadioButton.Checked == true)
                {
                    //retrieve the TestSet-file location, if it doesn't exist create it and save the (new) path in the config-file
                    if ((ConfigManager.GetSetting("testSetPath") != null || ConfigManager.GetSetting("testSetPath") != ""))
                    {
                        TestSetFile tsf     = TestSetFile.readFromFile();
                        string      imgPath = saveImageToTestSetDir(mainPictureBox.Image, (nameTextBox.Text == "" ? "<unknown>" : nameTextBox.Text));
                        tsf.testSets.Add(new TestSet((nameTextBox.Text == "" ? "<unknown>" : nameTextBox.Text), facialParamters, imgPath));
                        tsf.writeToFile();

                        log(imgPath);
                        log("inscannen succesvol.");
                    }
                }

                //Gezicht vergelijken
                else if (recognizeRadioButton.Checked == true || sequenceRadioButton.Checked == true)
                {
                    //retrieve the TestSet-file location form the config-file, if it doesn't exist do nothing
                    if ((ConfigManager.GetSetting("testSetPath") != null || ConfigManager.GetSetting("testSetPath") != ""))
                    {
                        string bestMatchName       = "";
                        double bestMatchDifference = 999;
                        string bestMatchPath       = "";

                        //compare the facial parameters to each item in the TestSet-file
                        TestSetFile tsf = TestSetFile.readFromFile();
                        foreach (TestSet ts in tsf.testSets)
                        {
                            double difference = 0;
                            for (int i = 0; i < ts.Parameters.Length; i++)
                            {
                                difference += Math.Abs(ts.Parameters[i] - facialParamters[i]);
                            }
                            //the representation is currently compared by the average difference in values
                            difference /= facialParamters.Length;

                            if (difference < bestMatchDifference)
                            {
                                bestMatchDifference = difference;
                                bestMatchName       = ts.Name;
                                bestMatchPath       = ts.ImagePath;
                            }
                        }
                        if (tsf.testSets.Count < 1 || bestMatchPath == null)
                        {
                            //Test set is empty!
                            log("TestSet is leeg. Scan eerst een aantal gezichten in! ");
                        }
                        else
                        {
                            resultPictureBox.Image = new Bitmap(bestMatchPath);
                            log("Best match is: " + bestMatchName + "  (gemiddeld verschil:" + bestMatchDifference + ")");
                        }
                    }
                    else
                    {
                        log("Testset-file bestaat niet of is niet gevonden.");
                    }
                }

                for (int i = 0; i < facialParamters.Length; i++)
                {
                    //uncomment if you want to print the found facial parameters in the feedbackTextBox
                    //log("param#" + (i + 1) + ": " + facialParamters[i]);
                }
            }
            else
            {
                log("Geen facial parameters beschikbaar.");
                log("Match berekenen is mislukt.");
            }
        }