示例#1
0
        public static async Task <TinyYOLOModel> CreateTinyYOLOModel(StorageFile file)
        {
            LearningModelPreview learningModel = await LearningModelPreview.LoadModelFromStorageFileAsync(file);

            TinyYOLOModel model = new TinyYOLOModel();

            model.learningModel = learningModel;
            return(model);
        }
        private async Task EvaluteImageAsync(VideoFrame videoFrame, bool isImage)
        {
            try
            {
                var startTime = DateTime.Now;
                if (model == null)
                {
                    var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Model/TinyYOLO.onnx"));

                    if (modelFile != null)
                    {
                        model = new TinyYOLOModel();
                        await MLHelper.CreateModelAsync(modelFile, model);
                    }
                }

                var input = new TinyYOLOInput()
                {
                    image = ImageFeatureValue.CreateFromVideoFrame(videoFrame)
                };

                var res = await model.EvaluateAsync(input) as TinyYOLOOutput;

                if (res != null)
                {
                    var data  = res.grid.GetAsVectorView().ToList();
                    var boxes = model.ComputeBoundingBoxes(data);
                    await DrawDetectedObjectRectAsync(boxes, isImage);

                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                    {
                        previewControl.EvalutionTime = (DateTime.Now - startTime).TotalSeconds.ToString();
                    });
                }
            }
            catch (Exception ex)
            {
                await AlertHelper.ShowMessageAsync(ex.ToString());
            }
        }