Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Based on this article some code : EMGU Multiple Face Recognition using PCA and Parallel Optimisation[^]
HTML
// The trainingfaces file

 <?xml version="1.0" encoding="utf-8"?>
 <Faces_For_Training>
 <FACE>
 <NAME>john</NAME>
 <Age>25</Age>
 <informations>Student in MS university</informations>
 <FILE>face_john 25Student in MS university_905807542.jpg</FILE>
 </FACE>
 <FACE>
 <NAME>mark</NAME>
 <Age>40</Age>
<informations>engineer ....</informations>
<FILE>face_mark 40engineer ....._390671740.jpg</FILE>
</FACE>
</Faces_For_Training>

I did apply step to save extra information's but failed to load it
private bool LoadTrainingData(string Folder_location)
{
    if (File.Exists(Folder_location +"\\TrainedLabels.xml"))
    {
        try
        {
            //message_bar.Text = "";
            Names_List.Clear();
            Names_List_ID.Clear();
            trainingImages.Clear();
            FileStream filestream = File.OpenRead(Folder_location + "\\TrainedLabels.xml");
            long filelength = filestream.Length;
            byte[] xmlBytes = new byte[filelength];
            filestream.Read(xmlBytes, 0, (int)filelength);
            filestream.Close();

            MemoryStream xmlStream = new MemoryStream(xmlBytes);

            using (XmlReader xmlreader = XmlTextReader.Create(xmlStream))
            {
                while (xmlreader.Read())
                {
                    if (xmlreader.IsStartElement())
                    {
                        switch (xmlreader.Name)
                        {
                            case "NAME":
                                if (xmlreader.Read())
                                {
                                    Names_List_ID.Add(Names_List.Count); //0, 1, 2, 3....
                                    Names_List.Add(xmlreader.Value.Trim());
                                    NumLabels += 3;


                                }
                                break;
                            case "FILE":
                                if (xmlreader.Read())
                                {
                                    //PROBLEM HERE IF TRAININGG MOVED
                                    trainingImages.Add(new Image<Gray, byte>(Application.StartupPath + "\\TrainedFaces\\" + xmlreader.Value.Trim()));
                                }
                                break;
                           // case "Age":
                               //   if (xmlreader.Read())
                                  //{
                                  //    Age_List.Add(xmlreader.Value.Trim());


                               //   }
                                // break;
                        }
                    }
                }
            }
            ContTrain = NumLabels;


Can anybody help me to lead me to right way to load Age and information's beside the name . it load only the name and I tried several ways to load it with name but I failed .
Posted

1 solution


In the following fragment, load_training_data does what you want using XPath[^].


C#
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml;

namespace LoadingFace
    {

    public partial class LoadingFace : Form
        {
                                        // file in project/bin/Debug
        const string PATH = @"TrainedLabels.xml";
                                        // lists
        List < string > ages = new List<string> ( );
        List < string > files = new List<string> ( );
        List < string > informations = new List<string> ( );
        List < string > names = new List<string> ( );

        // *********************************************** LoadingFace

        public LoadingFace ( )
            {
            InitializeComponent ( );

            load_training_data ( PATH );
            }

        // *********************************** retrieved_training_data

        string retrieved_training_data ( XmlNode  root,
                                         string   item )
            {
            string  inner_text;
            XmlNode node = null;

            try
                {
                node = root.SelectSingleNode ( item );
                inner_text = node.InnerText.Trim ( );
                }
            catch
                {
                inner_text = String.Empty;
                }

            return ( inner_text );
            }

        // **************************************** load_training_data

        void load_training_data ( string path )
            {

            try
                {
                XmlNodeList node_list;
                XmlNode     root;
                XmlDocument xml_document = new XmlDocument ( );

                ages.Clear ( );
                files.Clear ( );
                informations.Clear ( );
                names.Clear ( );

                xml_document.Load ( path );
                root = xml_document.DocumentElement;
                node_list = root.SelectNodes ( "face" );
                foreach ( XmlNode node in node_list )
                    {
                    string  age = String.Empty;
                    string  file = String.Empty;
                    string  information = String.Empty;
                    string  name = String.Empty;

                    age = retrieved_training_data ( node, "age" );
                    ages.Add ( age );

                    file = retrieved_training_data ( node, "file" );
                    files.Add ( file );

                    information = retrieved_training_data ( 
                                                    node, 
                                                    "informations" );
                    informations.Add ( information );

                    name = retrieved_training_data ( node, "name" );
                    names.Add ( name );
                    }
                }
            catch ( Exception ex )
                {

                }
            }

        } // class LoadingFace

    } // namespace LoadingFace
</string></string></string></string>


It uses the helper function retrieved_training_data.



Hope that helps.

 
Share this answer
 
Comments
cazanova007 10-Apr-14 16:31pm    
Thank you very much , I did same I did before but the tips that you give me great that I made for each age and info ..etc List<string> I made them all
Eigen_label = Names_List[ER.Label];
Eigen_label2 = Age_List[ER.Label];
Eigen_Label3 = info_List[ER.Label];
string x = Eigen_label + " " + Eigen_label2 + " " + Eigen_Label3;
then I return x for face Result it worked nice . Thank you again for help
gggustafson 10-Apr-14 22:36pm    
I would appreciate it if you marked this solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900