Пример #1
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                txtFilePath.Text = file.Path;
                SoftwareBitmap bitmap;
                using (var s = await file.OpenAsync(FileAccessMode.Read))
                {
                    var decoder = await BitmapDecoder.CreateAsync(s);

                    bitmap = await decoder.GetSoftwareBitmapAsync();

                    bitmap = SoftwareBitmap.Convert(bitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                }

                var images = new SoftwareBitmapSource();
                await images.SetBitmapAsync(bitmap);

                imgCeleb.Source = images;

                //VideoFrame
                VideoFrame inputimage = VideoFrame.CreateWithSoftwareBitmap(bitmap);
                inputimage = await GetCropedImage(inputimage);

                celebInput.data = ImageFeatureValue.CreateFromVideoFrame(inputimage);
                celebOutput     = await modelGen.EvaluateAsync(celebInput);

                var resultVector = celebOutput.classLabel.GetAsVectorView();
                txtcelebName.Text = resultVector[0];
                sw.Stop();
                txtProcTime.Text = $"{sw.Elapsed}";
                Debug.WriteLine($"process time = {sw.Elapsed}");
            }
            else
            {
                txtFilePath.Text = "Operation cancelled.";
            }
        }