Exemplo n.º 1
0
        private async Task EvaluateVideoFrameAsync(VideoFrame inputFrame)
        {
            if (inputFrame != null)
            {
                try
                {
                    // Get ONNX file
                    string modelPath
                        = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "FruitDetection.onnx");
                    var modelFile = await StorageFile.GetFileFromPathAsync(modelPath);

                    // Create WinML Model
                    var model        = new FruitDetectionModel();
                    var learninModel = await model.CreateFruitDetectionModel(modelFile);

                    // Set image(VideoFrame)
                    var input = new FruitDetectionModelInput
                    {
                        data = inputFrame
                    };

                    // Detect image
                    var output = await learninModel.EvaluateAsync(input);

                    ResultText.Text       = output.classLabel[0];
                    ResultText.Visibility = Visibility.Visible;
                }
                catch (Exception ex)
                {
                }
            }
        }
        public async Task <FruitDetectionModel> CreateFruitDetectionModel(StorageFile file)
        //public static async Task<FruitDetectionModel> CreateFruitDetectionModel(StorageFile file)
        {
            LearningModelPreview learningModel = await LearningModelPreview.LoadModelFromStorageFileAsync(file);

            FruitDetectionModel model = new FruitDetectionModel();

            model.learningModel = learningModel;
            return(model);
        }