/// <summary> /// Initializes a new instance of the <see cref="CNNProject"/> class. /// </summary> public CNNProject() { ResetNonSerializableAttributes(); this._matchingCounter = new Counter(); this._notMatchingCounter = new Counter(); this._imgDetectionNN = new ImageDetectionNeuralNetwork(); this._imgDetectionNN.InitNetwork(this._imagePatternSize); }
/// <summary> /// Adds the image to the given ListView as well to the connected ImageList /// called by CaptureNewImage and OpenImages /// </summary> /// <param name="lvUsed">The lv used.</param> /// <param name="selectedImage">The selected image.</param> /// <param name="imageName">Name of the image.</param> /// <param name="counterUsed">One of the both counters</param> private void AddImageToList(ListView lvUsed, Image selectedImage, string imageName, Counter counterUsed) { // first: add to ImageList ImageList imlUsed = lvUsed.SmallImageList; imlUsed.Images.Add(imageName, selectedImage); // second: add to ListView ListViewItem lvi = lvUsed.Items.Add(imageName + ".", imlUsed.Images.Count - 1); // not to forget, increments the counter ! counterUsed.Increment(); // scroll down in list (and select the last item, too) lvi.Selected = true; lvi.EnsureVisible(); }
/// <summary> /// Opens some images and includes them to the ListView and ImageList /// </summary> /// <param name="lvUsed">The lv used.</param> /// <param name="counterUsed">The counter used.</param> private void OpenImages(ListView lvUsed, Counter counterUsed) { if (openFileDialog.ShowDialog() == DialogResult.OK) { foreach (string fileName in openFileDialog.FileNames) { try { // uses the next free number string imageName = (counterUsed.Value + 1).ToString().PadLeft(4, '0'); Image selectedImage = Image.FromFile(fileName); // ! AddImageToList(lvUsed, selectedImage, imageName, counterUsed); } // TODO: Do not handle errors by catching non-specific exceptions catch (Exception ex) { StaticClasses.ShowException(ex); } } } }
/// <summary> /// Captures the the current selected area in the PictureBox /// </summary> /// <param name="lvUsed">one of the both ListViews</param> /// <param name="counterUsed">one of the both Counters</param> private void CaptureNewImage(ListView lvUsed, Counter counterUsed) { try { Image selectedImage = pictureBox.GetResizedSelectedArea(_cnnProjectHolder.CNNProject.ImagePatternSize); string imageName = (counterUsed.Value + 1).ToString().PadLeft(4, '0'); // ! AddImageToList(lvUsed, selectedImage, imageName, counterUsed); } catch (RectangleDoesNotFitToImageException ex) { StaticClasses.ShowError(ex.Message); } catch (ImageNotInitializedException ex) { StaticClasses.ShowError(ex.Message); } // TODO: Do not handle errors by catching non-specific exceptions catch (Exception ex) { StaticClasses.ShowException(ex); } }
/// <summary> /// Ready to go (not used atm) /// </summary> public ImageDetectionNeuralNetwork(ProgressBar pbTrain, Label lblTrainInfo) { SetVars(pbTrain, lblTrainInfo); TotalTrainingRounds = new Counter(); }
/// <summary> /// Don't forget to set _pbTrain (ProgressBar) and _lblTrainInfo (Label) afterwards /// </summary> public ImageDetectionNeuralNetwork() { TotalTrainingRounds = new Counter(); }