Пример #1
0
        public IList <YoloBoxRectangle> Detect(SKImage image)
        {
            if (image.Width != Constants.YoloImage.Width || image.Height != Constants.YoloImage.Height)
            {
                image = image.Resize(Constants.YoloImage.Width, Constants.YoloImage.Height);
            }
            var imageData = ImageToFloats(image);
            var tensor1   = new DenseTensor <float>(imageData, new int[] { 1, Constants.YoloImage.Width, Constants.YoloImage.Height, 3 });
            var container = new List <NamedOnnxValue>();

            container.Add(NamedOnnxValue.CreateFromTensor <float>("input_1", tensor1));

            var yolov3Output = _session.Run(container);
            var x13          = yolov3Output.ElementAt(0).AsTensor <float>().ToArray();
            var x26          = yolov3Output.ElementAt(1).AsTensor <float>().ToArray();
            var x52          = yolov3Output.ElementAt(2).AsTensor <float>().ToArray();

            var allBoxes = new List <YoloBox>();

            allBoxes.AddRange(GetBoxes(x13, _labels, 13, 13));
            allBoxes.AddRange(GetBoxes(x26, _labels, 26, 26));
            allBoxes.AddRange(GetBoxes(x52, _labels, 52, 52));

            var rects    = allBoxes.Select(x => x.Rectangle).ToList();
            var filtered = FilterBoundingBoxes(rects, 30, 0.2f);

            return(filtered);
        }