private void trainBoW(object sender, RoutedEventArgs e) { //train bow imageInfo.Text = "Training BoW"; WPFFolderBrowserDialog dd = new WPFFolderBrowserDialog(); dd.Title = "Select a folder"; if (dd.ShowDialog() == true) { String[] names = UtilFn.GetFilesFrom(dd.FileName, filtersDir, false); if (names.Length == 0) { MessageBox.Show("NO IMAGES IN SELECTED FOLDER."); } ushort c = 0; List <Bitmap> ims = new List <Bitmap>(); foreach (String fn in names) { if (c++ == 2000) { break; } ims.Add(new Bitmap(fn)); } bow = new BagOfVisualWords(20); // br features bow.Learn(ims.ToArray()); } else { MessageBox.Show("Something went wrong."); } imageInfo.Text = "Done"; }
private void loadButton(object sender, RoutedEventArgs e) { images = new List <BitmapImage>(); imagesEdited = new List <BitmapImage>(); i = 0; j = 0; if (checkBox.IsChecked == true) { allcurr.IsChecked = false; allcurr.IsEnabled = true; WPFFolderBrowserDialog dd = new WPFFolderBrowserDialog(); dd.Title = "Select a folder"; if (dd.ShowDialog() == true) { String[] names = UtilFn.GetFilesFrom(dd.FileName, filtersDir, false); if (names.Length == 0) { return; } foreach (String fn in names) { images.Add(new BitmapImage(new Uri(fn))); imagesEdited.Add(new BitmapImage(new Uri(fn))); } } else { imageInfo.Text = "Something went wrong."; } } else { allcurr.IsChecked = false; allcurr.IsEnabled = false; Microsoft.Win32.OpenFileDialog op = new Microsoft.Win32.OpenFileDialog(); op.Title = "Select a picture"; op.Filter = filters; if (op.ShowDialog() == true) { images.Add(new BitmapImage(new Uri(op.FileName))); imagesEdited.Add(new BitmapImage(new Uri(op.FileName))); } else { imageInfo.Text = "Something went wrong."; } } if (0 == images.Count) { allcurr.IsChecked = false; allcurr.IsEnabled = false; MessageBox.Show("No images"); return; } cvsim.Source = imagesEdited[i]; cvsim2.Source = images[i]; if (1 == images.Count) { rightOriginal.IsEnabled = false; rightEdited.IsEnabled = false; } else { rightOriginal.IsEnabled = true; rightEdited.IsEnabled = true; } cvs.Width = cvsim.Source.Width; cvs.Height = cvsim.Source.Height; cvs2.Width = cvsim2.Source.Width; cvs2.Height = cvsim2.Source.Height; rectSel = new System.Windows.Shapes.Rectangle { Stroke = new SolidColorBrush(Colors.Orange), StrokeThickness = 4, Width = cvs.Width, Height = cvs.Height }; Canvas.SetLeft(rectSel, 0); Canvas.SetTop(rectSel, 0); rectSel2 = new System.Windows.Shapes.Rectangle { Stroke = new SolidColorBrush(Colors.LimeGreen), StrokeThickness = 4, Width = cvs.Width - 20, Height = cvs.Height - 20 }; Canvas.SetLeft(rectSel2, 10); Canvas.SetTop(rectSel2, 10); if (cvs.Children.Count > 1) { cvs.Children.RemoveRange(1, cvs.Children.Count); } selected = new bool[imagesEdited.Count]; imageInfo.Text = ""; }