private void listBox2_SelectedIndexChanged(object sender, EventArgs e) { File.Create(parameter["hog_test_file"]).Dispose(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); if (listBox2.SelectedIndex < 0) { return; } else { try { List <Mat> ListImage = new List <Mat>(); Mat img_display = new Mat(); string dir = listBox2.SelectedItem.ToString(); img_display = Cv2.ImRead(dir); pictureBox2.Image = img_display.ToBitmap(); // Process predict sw.Start(); Cv2.Resize(img_display, img_display, sizes2); ListImage.Add(img_display); FeatureExtraction.compute_hog_test(ListImage, sizes2, 100, parameter["hog_test_file"]); SVMProblem Test = SVMProblemHelper.Load(parameter["hog_test_file"]); double[] Target = Test.Predict(model_load); sw.Stop(); label13.Text = MAPPING[(int)(Target[0])].ToString(); label10.Text = sw.ElapsedMilliseconds.ToString() + " (ms)"; string time = sw.ElapsedMilliseconds.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btn_FeatureExtraction_Click(object sender, EventArgs e) { try { if (!flag) { string path_train = textBox1.Text; string path_validation = textBox2.Text; get_data(path_train, path_validation); } string size = parameter["resize"]; sizes = new OpenCvSharp.Size(Convert.ToInt32(size.Split(',')[0]), Convert.ToInt32(size.Split(',')[1])); File.Create(parameter["hog_train_file"]).Dispose(); File.Create(parameter["hog_val_file"]).Dispose(); List <Mat> ListImageTrain = new List <Mat>(); List <Mat> ListImageVal = new List <Mat>(); // train int index_train = 0; foreach (var tmp in TRAIN_DATA) { ListImageTrain.Clear(); foreach (var tmp2 in tmp.Value) { try { Mat img = Cv2.ImRead(tmp2); Cv2.Resize(img, img, sizes); ListImageTrain.Add(img); } // if read image error catch (Exception ex) { continue; } } FeatureExtraction.compute_hog(ListImageTrain, sizes, index_train, parameter["hog_train_file"]); index_train += 1; } // val int index_val = 0; foreach (var tmp in VALIDATION_DATA) { ListImageVal.Clear(); foreach (var tmp2 in tmp.Value) { try { Mat img = Cv2.ImRead(tmp2); Cv2.Resize(img, img, sizes); ListImageVal.Add(img); } // if read image error catch (Exception ex) { continue; } } FeatureExtraction.compute_hog(ListImageVal, sizes, index_val, parameter["hog_val_file"]); index_val += 1; } MessageBox.Show("Completed"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }