public void ProcessWhatIs()
        {
            String filename = GetArg("image");

            try
            {
                var img   = new Bitmap(filename);
                var input = new ImageMLData(img);
                input.Downsample(downsample, false, downsampleHeight,
                                 downsampleWidth, 1, -1);
                int winner = network.Winner(input);
                app.WriteLine("What is: " + filename + ", it seems to be: "
                              + neuron2identity[winner]);
            }
            catch (Exception e)
            {
                app.WriteLine("Error loading: " + filename + ", " + e.Message);
            }
        }
Beispiel #2
0
        private void RecCanvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            recCanvas_drawing = false;

            var size = new Size(RecCanvas.ActualWidth, RecCanvas.ActualHeight);

            // Measure and arrange the surface
            // VERY IMPORTANT
            RecCanvas.Measure(size);
            RecCanvas.Arrange(new Rect(size));
            var renderBitmap = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32);

            renderBitmap.Render(RecCanvas);

            MemoryStream  stream  = new MemoryStream();
            BitmapEncoder encoder = new BmpBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
            encoder.Save(stream);

            var bitmap = new Drawing.Bitmap(stream);

            var downsample = new Downsampler();
            var result     = downsample.DownSample(bitmap, DIGIT_HEIGHT, DIGIT_WIDTH);
            var image      = new Drawing.Bitmap(DIGIT_WIDTH, DIGIT_HEIGHT);

            for (var i = 0; i < DIGIT_HEIGHT; ++i)
            {
                for (var j = 0; j < DIGIT_WIDTH; ++j)
                {
                    image.SetPixel(j, i, Drawing.Color.FromArgb(
                                       255,
                                       (int)result[i * DIGIT_WIDTH + j],
                                       (int)result[i * DIGIT_WIDTH + j],
                                       (int)result[i * DIGIT_WIDTH + j]
                                       ));
                }
            }
            RecComp.Source = Imaging.CreateBitmapSourceFromHBitmap(
                image.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            if (network == null)
            {
                return;
            }

            var input = new ImageMLData(bitmap);

            input.Downsample(downsample, false, DIGIT_HEIGHT, DIGIT_WIDTH, 1, -1);

            int winner = network.Winner(input);

            RecDigit.Text = winner.ToString();

            var data = network.Compute(input);

            for (var i = 0; i < DIGITS_COUNT; ++i)
            {
                Results[i] = new ResultObject
                {
                    Char   = i.ToString(),
                    Result = (data[i] + 1) / 2
                };
            }
        }