Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
protected override async void OnNavigatedTo(NavigationEventArgs e)
await CameraPreview.StartAsync();
CameraPreview.CameraHelper.FrameArrived += CameraHelper_FrameArrived;
private async void CameraHelper_FrameArrived(object sender, Microsoft.Toolkit.Uwp.Helpers.FrameEventArgs e)
if (e.VideoFrame.SoftwareBitmap == null) return;
if (_objectDetection?.Model == null) return;
await LoadAndEvaluateModelAsync(e.VideoFrame);
catch (Exception exception)
{ Debug.WriteLine(exception); }
private ObjectDetection _objectDetection;
private async void InitModel()
_objectDetection = new ObjectDetection();
var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/model.onnx"));
await _objectDetection.Init(modelFile);
private async Task LoadAndEvaluateModelAsync(VideoFrame videoFrame)
var result = await _objectDetection.PredictImageAsync(videoFrame);
var message = $"{DateTime.Now.ToLongTimeString()}{Environment.NewLine}============================={Environment.NewLine}";
message = result.Aggregate(message, (current, predictionModel) => current + $" {predictionModel.TagName} {(predictionModel.Probability * 100.0f):#0.00}% {Environment.NewLine}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.