// This method is executed by the ThreadPoolTimer, it performs the evaluation on a copy of the VideoFrame private async void EvaluateVideoFrame(ThreadPoolTimer timer) { // If a lock is being held, or WinML isn't fully initialized, return if (!semaphore.Wait(0) || !modelBindingComplete) { return; } try { using (evaluatableVideoFrame) { // ************ WinML Evaluate Frame ************ // Debug.WriteLine($"RelativeTime in Seconds: {evaluatableVideoFrame.RelativeTime?.Seconds}"); await model.EvaluateAsync(binding, "TinyYOLO"); // Remove overlapping and low confidence bounding boxes filteredBoxes = parser.NonMaxSuppress(parser.ParseOutputs(outputArray.ToArray()), 5, .5F); Debug.WriteLine(filteredBoxes.Count <= 0 ? $"No Valid Bounding Boxes" : $"Valid Bounding Boxes: {filteredBoxes.Count}"); } } catch (Exception ex) { Debug.WriteLine($"EvaluateFrameException: {ex}"); } finally { semaphore.Release(); } }
private static void PredictImage(string filename, ImageNetPrediction Predicted) { //获取对象信息 Console.WriteLine(".....The objects in the image are detected as below...."); YoloWinMlParser _parser = new YoloWinMlParser(); IList <YoloBoundingBox> boundingBoxes = _parser.ParseOutputs(Predicted.PredictedLabels, 0.4f); foreach (var box in boundingBoxes) { Console.WriteLine(box.Label + " and its Confidence score: " + box.Confidence + "Location: " + box.Rect); } //过滤 Console.WriteLine(".....The filtered objects as below...."); var filteredBoxes = _parser.NonMaxSuppress(boundingBoxes, 5, 0.6F); Bitmap bitmapSource = Image.FromFile(filename) as Bitmap; Bitmap bitmapOut = new Bitmap(bitmapSource, ImageNetSettings.imageWidth, ImageNetSettings.imageHeight); Graphics graphics = Graphics.FromImage(bitmapOut); foreach (var box in filteredBoxes) { Console.WriteLine(box.Label + " and its Confidence score: " + box.Confidence + "Location: " + box.Rect); graphics.DrawRectangle(Pens.Red, box.Rect.X, box.Rect.Y, box.Rect.Width, box.Rect.Height); graphics.DrawString(box.Label, new Font("宋体", 15), Brushes.Red, box.X + 10, box.Y); } bitmapOut.Save(filename + "_predicted.png"); bitmapOut?.Dispose(); bitmapSource?.Dispose(); }
public async Task <IList <YoloBoundingBox> > AnalyzeImage(VideoFrame videoFrame) { // This appears to be the right way to handle background tasks. // We return to the main thread as fast as we can, and wait for the next call to the Update() // to advance our processing #if SDK_1809 TinyYoloV2O12Input input = new TinyYoloV2O12Input { image = ImageFeatureValue.CreateFromVideoFrame(videoFrame) }; #else TinyYoloV2O1ModelInput input = new TinyYoloV2O1ModelInput { image = videoFrame }; #endif var dims = GetDimensionsFromVideoFrame(videoFrame); int width = dims.Item1; int height = dims.Item2; var predictions = await model.EvaluateAsync(input).ConfigureAwait(false); #if SDK_1809 var boxes = parser.ParseOutputs(predictions.grid.GetAsVectorView().ToArray(), width, height, DetectionThreshold); #else var boxes = parser.ParseOutputs(predictions.grid.ToArray(), width, height, DetectionThreshold); #endif boxes = boxes.Where(b => b.Confidence >= DetectionThreshold).ToList(); // normalize coordinates boxes = parser.NonMaxSuppress(boxes); return(boxes.ToList()); }
public void DetectObjectsUsingModel(ImageInputData imageInputData) { var probs = model.Predict(imageInputData).PredictedLabels; IList <YoloBoundingBox> boundingBoxes = _parser.ParseOutputs(probs); filteredBoxes = _parser.NonMaxSuppress(boundingBoxes, 5, .5F); }
public void DetectObjectsUsingModel(string imagesFilePath) { var imageInputData = new ImageNetData { ImagePath = imagesFilePath }; var probs = model.Predict(imageInputData).PredictedLabels; IList <YoloBoundingBox> boundingBoxes = _parser.ParseOutputs(probs); filteredBoxes = _parser.NonMaxSuppress(boundingBoxes, 5, .5F); }
private void DrawOverlays(VideoFrame inputImage) { YoloCanvas.Children.Clear(); if (_boxes.Count <= 0) { return; } var filteredBoxes = _parser.NonMaxSuppress(_boxes, 5, .5F); foreach (var box in filteredBoxes) { DrawYoloBoundingBox(box, YoloCanvas); } }