async void GetFrameAsync(object sender, EventArgs e) { if (!VideoPlayer.HasVideo) { return; } RenderTargetBitmap bmp = new RenderTargetBitmap(_vidWidth, _vidHeight, _dpi.Width, _dpi.Height, PixelFormats.Pbgra32); bmp.Render(VideoPlayer); painting.Children?.Clear(); var result = await UploadImage(bmp); var predictions = PredictionResult.FromJson(result); var relevant = predictions.Predictions.Where(x => x.Probability > 0.5); int i = 0; foreach (var prediction in relevant) { var boundingBox = new Rect( prediction.BoundingBox.Left, prediction.BoundingBox.Top, prediction.BoundingBox.Width, prediction.BoundingBox.Height); var rect = new Rectangle(); rect.Stroke = new SolidColorBrush(Color.FromRgb(100, (byte)(i * 10), 0)); rect.StrokeThickness = 1; rect.Height = boundingBox.Height * _vidHeight; rect.Width = boundingBox.Width * _vidWidth; rect.Margin = new Thickness(boundingBox.Left * _vidWidth, boundingBox.Top * _vidHeight, 0, 0); var text = new TextBlock(); text.Text = prediction.TagName; text.Margin = rect.Margin; text.Background = new SolidColorBrush(Color.FromRgb(100, (byte)(i * 10), 0)); text.Foreground = new SolidColorBrush(Color.FromRgb(250, 250, 250)); painting.Children.Add(text); painting.Children.Add(rect); } }
private async void btnTest_Click(object sender, RoutedEventArgs e) { BitmapImage bi = videoPlayer.Source.Clone() as BitmapImage; string folderPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); string fileName = $"{folderPath}\\lulu.png"; //save the image bi.Save(fileName); //test if its lulu Gateway g = new Gateway(); var r = await g.MakePredictionRequest(fullfilepath : fileName); var pr = PredictionResult.FromJson(r); if (pr.Predictions.Any()) { Prediction = (pr.Predictions.First().Probability * 100).ToString("n"); } }