Esempio n. 1
0
        static void Main(string[] args)
        {
            using var image = Image.FromFile("Assets/test.jpg");

            using var scorer = new YoloScorer <YoloCocoP5Model>("Assets/Weights/yolov5n.onnx");

            List <YoloPrediction> predictions = scorer.Predict(image);

            using var graphics = Graphics.FromImage(image);

            foreach (var prediction in predictions) // iterate predictions to draw results
            {
                double score = Math.Round(prediction.Score, 2);

                graphics.DrawRectangles(new Pen(prediction.Label.Color, 1),
                                        new[] { prediction.Rectangle });

                var(x, y) = (prediction.Rectangle.X - 3, prediction.Rectangle.Y - 23);

                graphics.DrawString($"{prediction.Label.Name} ({score})",
                                    new Font("Consolas", 16, GraphicsUnit.Pixel), new SolidBrush(prediction.Label.Color),
                                    new PointF(x, y));
            }

            image.Save("Assets/result.jpg");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var scorer = new YoloScorer <YoloCocoModel>();

            using var stream = new FileStream("assets/test.jpg", FileMode.Open);

            var image = Image.FromStream(stream);

            List <YoloPrediction> predictions = scorer.Predict(image);

            using var graphics = Graphics.FromImage(image);

            foreach (var prediction in predictions) // iterate each prediction to draw results
            {
                double score = Math.Round(prediction.Score, 2);

                graphics.DrawRectangles(new Pen(prediction.Label.Color, 1),
                                        new[] { prediction.Rectangle });

                var(x, y) = (prediction.Rectangle.X - 2, prediction.Rectangle.Y - 21);

                graphics.DrawString($"{prediction.Label.Name} ({score})", new Font("Consolas", 3),
                                    new SolidBrush(prediction.Label.Color), new PointF(x, y));
            }

            image.Save("assets/result.jpg");
        }
Esempio n. 3
0
 public void InitScorer()
 {
     Logging.Log("Initialising ObjectDetector service.");
     try
     {
         scorer = new YoloScorer <YoloCocoModel>();
     }
     catch (Exception ex)
     {
         Logging.LogError($"Unexpected exception initialising Object detection: {ex}");
         scorer = null; // disable.
     }
 }