SampleApp.MainForm.OnLoad C# (CSharp) Method

OnLoad() protected method

This method just loads the image datasets into memory.
protected OnLoad ( EventArgs e ) : void
e EventArgs
return void
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // Seed the number generator with a fixed number so results
            // are replicable across application runs. Comment the 
            // following line to generate truly random data splits.
            //
            Accord.Math.Random.Generator.Seed = 0;

            cbStrategy.DataSource = Enum.GetValues(typeof(SelectionStrategy));


            // Open Resources folder
            var path = new DirectoryInfo(Path.Combine(Application.StartupPath, "Resources"));

            // Create image list to load images into
            originalImages = new Dictionary<string, Bitmap>();
            displayImages = new Dictionary<string, Bitmap>();

            originalTestImages = new Dictionary<string, Bitmap>();
            originalTrainImages = new Dictionary<string, Bitmap>();

            ImageList imageList = new ImageList();
            imageList.ImageSize = new Size(64, 64);
            imageList.ColorDepth = ColorDepth.Depth32Bit;
            listView1.LargeImageList = imageList;

            int currentClassLabel = 0;

            // For every class folder
            foreach (var classFolder in path.EnumerateDirectories())
            {
                string name = classFolder.Name;

                // Create two list view groups for each class.  Use 80%
                // of training instances and the remaining 20% as testing.
                ListViewGroup trainingGroup = listView1.Groups.Add(name + ".train", name + ".train");
                ListViewGroup testingGroup = listView1.Groups.Add(name + ".test", name + ".test");


                // For each file in the class folder
                FileInfo[] files = GetFilesByExtensions(classFolder, ".jpg", ".png").ToArray();

                // Shuffle the samples
                Vector.Shuffle(files);

                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo file = files[i];

                    Bitmap image = (Bitmap)Bitmap.FromFile(file.FullName);

                    string shortName = file.Name;
                    string imageKey = file.FullName;

                    imageList.Images.Add(imageKey, image);
                    originalImages.Add(imageKey, image);
                    displayImages.Add(imageKey, image);

                    ListViewItem item;
                    if ((i / (double)files.Length) < 0.7)
                    {
                        item = new ListViewItem(trainingGroup);
                        originalTrainImages.Add(imageKey, image);
                    }
                    else
                    {
                        item = new ListViewItem(testingGroup);
                        originalTestImages.Add(imageKey, image);
                    }

                    item.ImageKey = imageKey;
                    item.Name = shortName;
                    item.Text = shortName;
                    item.Tag = new Tuple<double[], int>(null, currentClassLabel);

                    listView1.Items.Add(item);
                }

                currentClassLabel++;
            }
        }
MainForm