Ejemplo n.º 1
0
        private async void recognizeButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker fileOpenPicker = new FileOpenPicker();

            fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            fileOpenPicker.FileTypeFilter.Add(".jpg");
            fileOpenPicker.FileTypeFilter.Add(".bmp");
            fileOpenPicker.FileTypeFilter.Add(".png");
            fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
            var inputFile = await fileOpenPicker.PickSingleFileAsync();

            if (inputFile == null)
            {
                // The user cancelled the picking operation
                return;
            }
            TimeSpan duration;

            imageLabel.Text = "Recognizing...";
            DateTime       startTime = DateTime.UtcNow;
            SoftwareBitmap softwareBitmap;

            using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read))
            {
                // Create the decoder from the stream
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                // Get the SoftwareBitmap representation of the file
                softwareBitmap = await decoder.GetSoftwareBitmapAsync();

                softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore);
                var source = new SoftwareBitmapSource();
                await source.SetBitmapAsync(softwareBitmap);

                previewImage.Source = source;

                VideoFrame vf = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap);

                ModelInput.data = vf;
                try
                {
                    ModelOutput = await ModelGen.EvaluateAsync(ModelInput);

                    string labelText = "";
                    labelText      += string.Format("{0}\r\n", ModelOutput.classLabel[0]);
                    duration        = DateTime.UtcNow - startTime;
                    labelText      += string.Format("\r\n\r\n\r\n\r\n{0:#}ms", duration.TotalMilliseconds);
                    imageLabel.Text = labelText;
                }
                catch (Exception ex)
                {
                    imageLabel.Text = ex.Message;
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <Ee7165d4_x002D_31e3_x002D_468e_x002D_ba0c_x002D_565f0b33d377_1bc49a81_x002D_827d_x002D_48b3_x002D_84bf_x002D_3a9555b4c54eModelOutput> EvaluateAsync(Ee7165d4_x002D_31e3_x002D_468e_x002D_ba0c_x002D_565f0b33d377_1bc49a81_x002D_827d_x002D_48b3_x002D_84bf_x002D_3a9555b4c54eModelInput input)
        {
            Ee7165d4_x002D_31e3_x002D_468e_x002D_ba0c_x002D_565f0b33d377_1bc49a81_x002D_827d_x002D_48b3_x002D_84bf_x002D_3a9555b4c54eModelOutput output = new Ee7165d4_x002D_31e3_x002D_468e_x002D_ba0c_x002D_565f0b33d377_1bc49a81_x002D_827d_x002D_48b3_x002D_84bf_x002D_3a9555b4c54eModelOutput();
            LearningModelBindingPreview binding = new LearningModelBindingPreview(learningModel);

            binding.Bind("data", input.data);
            binding.Bind("classLabel", output.classLabel);
            binding.Bind("loss", output.loss);
            LearningModelEvaluationResultPreview evalResult = await learningModel.EvaluateAsync(binding, string.Empty);

            return(output);
        }