示例#1
0
        private void btnStoreDrawing_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (cboDrawingLabel.Text == "")
                {
                    MessageBox.Show("Please give this drawing a name", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                if (_currentSketch == null)
                {
                    RedrawSmallImage();
                }

                #region Create sketch for storage

                EncogOCR_SketchData sketch = new EncogOCR_SketchData()
                {
                    Name          = cboDrawingLabel.Text,
                    InkCanvasSize = new Size(canvasInk.ActualWidth, canvasInk.ActualHeight),
                    Strokes       = _currentSketch.Strokes.ToArray(),
                };

                sketch.GenerateBitmap(_pixels);
                sketch.GenerateImageControl();

                #endregion

                AddSketch(sketch);
                TrainNetwork();

                //NOTE: Event listeners will clear the rest based on this
                canvasInk.Strokes.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#2
0
        private void RedrawSmallImage()
        {
            //canvasPixels.Source = UtilityWPF.RenderControl(canvasInk, _pixels, _pixels, true);

            _currentSketch = new EncogOCR_SketchData()
            {
                Name    = cboDrawingLabel.Text,
                Strokes = canvasInk.Strokes.
                          Select(o => new EncogOCR_StrokeDefinition(o)).
                          ToArray(),
                InkCanvasSize = new Size(canvasInk.ActualWidth, canvasInk.ActualHeight),
            };

            _currentSketch.GenerateBitmap(_pixels);

            canvasPixels.Source = _currentSketch.Bitmap;

            RecognizeImage();

            if (_visualizer != null)
            {
                _visualizer.AddSketch(_currentSketch.Clone());
            }
        }
示例#3
0
        private void RedrawSmallImage()
        {
            //canvasPixels.Source = UtilityWPF.RenderControl(canvasInk, _pixels, _pixels, true);

            _currentSketch = new EncogOCR_SketchData()
            {
                Name = cboDrawingLabel.Text,
                Strokes = canvasInk.Strokes.
                    Select(o => new EncogOCR_StrokeDefinition(o)).
                    ToArray(),
                InkCanvasSize = new Size(canvasInk.ActualWidth, canvasInk.ActualHeight),
            };

            _currentSketch.GenerateBitmap(_pixels);

            canvasPixels.Source = _currentSketch.Bitmap;

            RecognizeImage();

            if (_visualizer != null)
            {
                _visualizer.AddSketch(_currentSketch.Clone());
            }
        }
示例#4
0
        private void btnStoreDrawing_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (cboDrawingLabel.Text == "")
                {
                    MessageBox.Show("Please give this drawing a name", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                if (_currentSketch == null)
                {
                    RedrawSmallImage();
                }

                #region Create sketch for storage

                EncogOCR_SketchData sketch = new EncogOCR_SketchData()
                {
                    Name = cboDrawingLabel.Text,
                    InkCanvasSize = new Size(canvasInk.ActualWidth, canvasInk.ActualHeight),
                    Strokes = _currentSketch.Strokes.ToArray(),
                };

                sketch.GenerateBitmap(_pixels);
                sketch.GenerateImageControl();

                #endregion

                AddSketch(sketch);
                TrainNetwork();

                //NOTE: Event listeners will clear the rest based on this
                canvasInk.Strokes.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void StrokeCollection_StrokesChanged(object sender, System.Windows.Ink.StrokeCollectionChangedEventArgs e)
        {
            try
            {
                EncogOCR_SketchData sketch = new EncogOCR_SketchData()
                {
                    Name = "",
                    Strokes = canvasInk.Strokes.
                        Select(o => new EncogOCR_StrokeDefinition(o)).
                        ToArray(),
                    InkCanvasSize = new Size(canvasInk.ActualWidth, canvasInk.ActualHeight),
                };

                sketch.GenerateBitmap(IMAGESIZE);

                // The bitmap is white on black, switch to black on white
                double[] inverted = sketch.NNInput.
                    Select(o => 1d - o).
                    ToArray();

                double[] converted = inverted;
                if (_patternStorage != null)
                {
                    converted = _patternStorage.Convert_Local_External(converted);
                }

                DrawImage(imageCurrent, converted);

                panelGuessedImages.Children.Clear();

                if (_patternStorage != null)
                {
                    double[][] recognized = _patternStorage.Recognize(inverted);

                    #region show thumbnails

                    if (recognized != null)
                    {
                        foreach (var guessImage in recognized)
                        {
                            DrawImage(panelGuessedImages.Children, guessImage);
                        }
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }