Exemplo n.º 1
0
        private void addAllImagesToDBToolStripMenuItem_Click(object sender, EventArgs e)
        {
            humanList = new List <Human>();
            if (FBD.ShowDialog() == DialogResult.OK)
            {
                DirectoryInfo myFolder = new DirectoryInfo(FBD.SelectedPath);
                fileCount = Directory.GetFiles(FBD.SelectedPath).Count();
                InitializeProgressBar();
                foreach (string filename in Directory.GetFiles(FBD.SelectedPath))
                {
                    bitmap = new Bitmap(filename);
                    hog    = new HistogramsOfOrientedGradients();
                    hog.ProcessImage(bitmap);
                    human = new Human();
                    if (filename.Contains("image_human"))
                    {
                        human.IsHuman = 1;
                    }
                    else
                    {
                        human.IsHuman = -1;
                    }
                    line      = AuxiliaryFunctions.ToOneLine(hog.Histograms);
                    byteArray = AuxiliaryFunctions.DoubleArrayToByte(line);
                    human.HOG = byteArray;

                    //XML file
                    humanList.Add(human);


                    index++;

                    if (index % (fileCount / 100) == 0)
                    {
                        progressValue++;
                        label1.Text = (progressValue + " %").ToString();
                        pb.Value    = progressValue <= 100?progressValue:100;
                        Thread.Sleep(10);
                    }
                }
                if (!File.Exists("Database.xml"))
                {
                    AuxiliaryFunctions.Serialize(humanList, "Database.xml");
                }
                else
                {
                    humanList.AddRange(AuxiliaryFunctions.Deserialize <List <Human> >("Database.xml"));
                    AuxiliaryFunctions.Serialize(humanList, "Database.xml");
                }
            }
        }
Exemplo n.º 2
0
        private void trainHumansToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            //XML file
            humanList   = new List <Human>();
            humanList   = AuxiliaryFunctions.Deserialize <List <Human> >("Database.xml");
            trainArray  = new double[humanList.Count][];
            outputArray = new double[humanList.Count];
            fileCount   = humanList.Count;
            InitializeProgressBar();
            for (int i = 0; i < humanList.Count; i++)
            {
                trainArray[i]  = AuxiliaryFunctions.ByteArrayToDouble(humanList[i].HOG);
                outputArray[i] = humanList[i].IsHuman;
                index++;

                if (index % (fileCount / 100) == 0)
                {
                    progressValue++;
                    label1.Text = (progressValue + " %").ToString();
                    pb.Value    = progressValue <= 100 ? progressValue : 100;
                    Thread.Sleep(10);
                }
            }
            //trainArray = humanList.Select(x => AuxiliaryFunctions.ByteArrayToDouble(x.HOG)).ToArray();
            //outputArray = humanList.Select(x => (double)x.IsHuman).ToArray();

            var teacher = new SequentialMinimalOptimization <Gaussian>()
            {
                UseComplexityHeuristic = true,
                UseKernelEstimation    = true
            };
            SupportVectorMachine <Gaussian> svm = teacher.Learn(trainArray, outputArray);

            resultLine = svm.Weights;
            AuxiliaryFunctions.WriteWeight(resultLine, "weight.txt");
            AuxiliaryFunctions.MakeSerialization(svm, "SVM_G.xml");
        }