public override bool Equals(Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            TestSetFile p = obj as TestSetFile;

            if ((System.Object)p == null)
            {
                return(false);
            }

            // Return true if the fields match:
            if (p.testSets.Count != testSets.Count)
            {
                return(false);
            }

            for (int i = 0; i < testSets.Count; i++)
            {
                if (!testSets[i].Equals(p.testSets[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
        public static TestSetFile readFromFile()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(TestSetFile));

            string path = "";

            if (ConfigurationManager.AppSettings["testSetPath"] == null || ConfigurationManager.AppSettings["testSetPath"].ToString() == "")
            {
                path = "TestSet.xml";
                ConfigurationManager.AppSettings["testSetPath"] = path;
            }
            else
            {
                path = ConfigurationManager.AppSettings["testSetPath"].ToString();
            }

            if (!File.Exists(path))
            {
                createFile(path);
            }
            FileStream fs = new FileStream(path, FileMode.Open);

            TestSetFile temp = (TestSetFile)serializer.Deserialize(fs);

            fs.Close();

            return(temp);
        }
Beispiel #3
0
        public EditTestSetDialog(TestSetFile tsf, int itemIndex)
        {
            InitializeComponent();

            testSetFile    = tsf;
            this.itemIndex = itemIndex;
        }
        //class used to read and write data with the default XML parser
        //also contains methods to compare and copy the data


        public object Clone()
        {
            TestSetFile tsf = (TestSetFile)this.MemberwiseClone();

            tsf.testSets = new List <TestSet>();
            foreach (TestSet ts in testSets)
            {
                tsf.testSets.Add((TestSet)ts.Clone());
            }

            return(tsf);
        }
Beispiel #5
0
        private void TestsetManagerForm_Load(object sender, EventArgs e)
        {
            string testSetPath = string.Empty;

            testSetPath = ConfigManager.GetSetting("testSetPath");
            //Console.WriteLine("load ...");

            //read test set
            if (oldTestSet == null)
            {
                //Console.WriteLine("hit");
                oldTestSet     = TestSetFile.readFromFile();
                currentTestSet = (TestSetFile)oldTestSet.Clone();
            }

            //display test set
            loadItemsIntoListBox();
        }
Beispiel #6
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.");
            }
        }