Exemplo n.º 1
0
        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 void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device)
        {
            currentEncodingProperties = encodingProperties;
            canvasDevice = device != null?CanvasDevice.CreateFromDirect3D11Device(device) : CanvasDevice.GetSharedDevice();

            parser        = new YoloWinMlParser();
            filteredBoxes = new List <YoloBoundingBox>();

            await LoadModelAsync();

            frameProcessingTimer = ThreadPoolTimer.CreatePeriodicTimer(EvaluateVideoFrame, poolTimerInterval);
        }