private void btChooseDataLatih_Click(object sender, EventArgs e) { OpenFileDialog chooseTrainfile = new OpenFileDialog { InitialDirectory = @"D:\", Title = "Browse Text Files", CheckFileExists = true, CheckPathExists = true, DefaultExt = "jpg", Filter = "jpg files (*.jpg)|*.jpg", FilterIndex = 2, RestoreDirectory = true, ReadOnlyChecked = true, ShowReadOnly = true, Multiselect = true }; DialogResult trainFile = chooseTrainfile.ShowDialog(); if (trainFile == DialogResult.OK) { dgvDataLatih.Rows.Clear(); alltrainfilename = chooseTrainfile.SafeFileNames; String dirName = (Path.GetDirectoryName(chooseTrainfile.FileName)); training = new image[alltrainfilename.Length]; trainingClass = new bool[alltrainfilename.Length]; this.progressBar1.Value = 0; this.progressBar1.Visible = true; this.progressBar1.Maximum = training.Length; for (int i = 0; i < alltrainfilename.Length; i++) { if (Regex.Match(alltrainfilename[i], minyak).Success) { this.isRealTest = false; training[i] = new image(new Bitmap((String)(dirName + "\\" + alltrainfilename[i])), "minyak", alltrainfilename[i], jarak); trainingClass[i] = true; } else if (Regex.Match(alltrainfilename[i], kering).Success) { this.isRealTest = false; training[i] = new image(new Bitmap((String)(dirName + "\\" + alltrainfilename[i])), "kering", alltrainfilename[i], jarak); trainingClass[i] = false; } else { this.isRealTest = true; training[i] = new image(new Bitmap((String)(dirName + "\\" + alltrainfilename[i])), null, alltrainfilename[i], jarak); trainingClass[i] = false; } this.progressBar1.Value += 1; dgvDataLatih.Rows.Add(alltrainfilename[i], training[i].kelas); dgvDataLatih.Update(); } fitur4training = getFitur(training); isTrainingLoaded = true; } }
private void btChooseTestDir_Click(object sender, EventArgs e) { FolderBrowserDialog folderDlg = new FolderBrowserDialog(); DialogResult result = folderDlg.ShowDialog(); if (result == DialogResult.OK) { dgvDataUji.Rows.Clear(); testingDir = new DirectoryInfo(folderDlg.SelectedPath); TestingImage = testingDir.GetFiles(); this.progressBar1.Value = 0; this.progressBar1.Visible = true; this.progressBar1.Maximum = TestingImage.Length; testing = new image[TestingImage.GetLength(0)]; testingClass = new bool[TestingImage.GetLength(0)]; alltestfilename = new string[TestingImage.GetLength(0)]; for (int i = 0; i < TestingImage.GetLength(0); i++) { if (Regex.Match(TestingImage[i].Name, minyak).Success) { this.isRealTest = false; testing[i] = new image(new Bitmap(TestingImage[i].FullName), "minyak", TestingImage[i].Name, jarak); testingClass[i] = true; } else if (Regex.Match(TestingImage[i].Name, kering).Success) { this.isRealTest = false; testing[i] = new image(new Bitmap(TestingImage[i].FullName), "kering", TestingImage[i].Name, jarak); testingClass[i] = false; } else { this.isRealTest = true; testing[i] = new image(new Bitmap(TestingImage[i].FullName), null, TestingImage[i].Name, jarak); testingClass[i] = false; } this.progressBar1.Value += 1; alltestfilename[i] = TestingImage[i].Name; if (this.isRealTest == false) { dgvDataUji.Rows.Add(alltestfilename[i], testing[i].kelas); } else if (this.isRealTest == true) { dgvDataUji.Rows.Add(alltestfilename[i]); } dgvDataUji.Update(); } fitur4testing = getFitur(testing); isTestingLoaded = true; } }
private void btChooseTrainingDir_Click(object sender, EventArgs e) { FolderBrowserDialog folderDlg = new FolderBrowserDialog(); DialogResult result = folderDlg.ShowDialog(); if (result == DialogResult.OK) { dgvDataLatih.Rows.Clear(); trainingDir = new DirectoryInfo(folderDlg.SelectedPath); TrainingImage = trainingDir.GetFiles(); this.progressBar1.Value = 0; this.progressBar1.Visible = true; this.progressBar1.Maximum = TrainingImage.Length; training = new image[TrainingImage.GetLength(0)]; trainingClass = new bool[TrainingImage.GetLength(0)]; for (int i = 0; i < TrainingImage.GetLength(0); i++) { if (Regex.Match(TrainingImage[i].Name, minyak).Success) { training[i] = new image(new Bitmap(TrainingImage[i].FullName), "minyak", TrainingImage[i].Name, jarak); trainingClass[i] = true; } else if (Regex.Match(TrainingImage[i].Name, kering).Success) { training[i] = new image(new Bitmap(TrainingImage[i].FullName), "kering", TrainingImage[i].Name, jarak); trainingClass[i] = false; } this.progressBar1.Value += 1; String filename = TrainingImage[i].Name; String kelas = training[i].kelas; dgvDataLatih.Rows.Add(filename, kelas); dgvDataLatih.Update(); } fitur4training = getFitur(training); isTrainingLoaded = true; } }