Ejemplo n.º 1
0
 private void btnLearnRedThresholds_Click(object sender, EventArgs e)
 {
     if (!Worker_LearnThresholds.IsBusy)
     {
         WriteToLog("Started learning...");
         btnLearnRedThresholds.Text = "Stop";
         Worker_LearnThresholds.RunWorkerAsync();
         btnStart.BackColor = Color.PaleVioletRed;
     }
     else
     {
         WriteToLog("Stopping learning...");
         btnLearnRedThresholds.Text = "Learn Red Thresholds";
         Worker_LearnThresholds.CancelAsync();
         btnLearnRedThresholds.BackColor = SystemColors.Control;
     }
 }
Ejemplo n.º 2
0
        private void Worker_LearnThresholds_DoWork(object sender, DoWorkEventArgs e)
        {
            LearningHelper learninghelper   = new LearningHelper();
            int            samplescollected = 0;

            while (!Worker_LearnThresholds.CancellationPending)
            {
                while (GetKillNumber() == 0 && !Worker_LearnThresholds.CancellationPending)
                {
                    ScreenData scrData = GetScreenData();
                    if (GetKillNumber() == 0)
                    {
                        scrData.Kill = false;
                        learninghelper.AddData(scrData);
                        samplescollected++;
                    }
                }

                List <int> thisKill = new List <int>();
                while (GetKillNumber() > 0 && !Worker_LearnThresholds.CancellationPending)
                {
                    ScreenData scrData = GetScreenData();
                    if (GetKillNumber() > 0)
                    {
                        scrData.Kill = true;
                        learninghelper.AddData(scrData);
                        samplescollected++;
                    }
                }
            }


            Worker_LearnThresholds.ReportProgress(0, String.Format("Collected a total of {0} samples", samplescollected));

            Worker_LearnThresholds.ReportProgress(0, "Creating model from samples....");

            double accuracy = learninghelper.LearnFromData(5000);

            Worker_LearnThresholds.ReportProgress(0, String.Format("Model created. Accuracy on 20% of testdata is {0}", accuracy));

            learninghelper.SaveModel(@"./learning/KillDetectionModel.mdl");
        }