コード例 #1
0
ファイル: Main.cs プロジェクト: terryll/Alturos.Yolo
        private void Initialize(YoloConfiguration config)
        {
            if (this._yoloWrapper != null)
            {
                this._yoloWrapper.Dispose();
            }

            var sw = new Stopwatch();

            sw.Start();
            this._yoloWrapper = new YoloWrapper(config.ConfigFile, config.WeightsFile, config.NamesFile, 0);
            sw.Stop();

            var action = new MethodInvoker(delegate()
            {
                var detectionSystemDetail = string.Empty;
                if (!string.IsNullOrEmpty(this._yoloWrapper.EnvironmentReport.GraphicDeviceName))
                {
                    detectionSystemDetail = $"({this._yoloWrapper.EnvironmentReport.GraphicDeviceName})";
                }
                this.toolStripStatusLabelYoloInfo.Text = $"Initialize Yolo in {sw.Elapsed.TotalMilliseconds:0} ms - Detection System:{this._yoloWrapper.DetectionSystem} {detectionSystemDetail}";
            });

            this.statusStrip1.Invoke(action);
            this.buttonSendImage.Invoke(new MethodInvoker(delegate() { this.buttonSendImage.Enabled = true; }));
        }
コード例 #2
0
        private void Initialize(YoloConfiguration config)
        {
            try
            {
                if (this._yoloWrapper != null)
                {
                    this._yoloWrapper.Dispose();
                }

                var gpuConfig  = new GpuConfig();
                var useOnlyCpu = false;
                if (useOnlyCpu)
                {
                    gpuConfig = null;
                }

                this._yoloWrapper = new YoloWrapper(config.ConfigFile, config.WeightsFile, config.NamesFile, gpuConfig);


                var action = new MethodInvoker(delegate()
                {
                    var deviceName = this._yoloWrapper.GetGraphicDeviceName(gpuConfig);
                });
            }
            catch (Exception exception)
            {
                MessageBox.Show($"{nameof(Initialize)} - {exception}", "Error Initialize", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: vitocorleone1/Alturos.Yolo
        private void Initialize(YoloConfiguration config)
        {
            try
            {
                if (this._yoloWrapper != null)
                {
                    this._yoloWrapper.Dispose();
                }

                var useOnlyCpu = this.cpuToolStripMenuItem.Checked;

                var sw = new Stopwatch();
                sw.Start();
                this._yoloWrapper = new YoloWrapper(config.ConfigFile, config.WeightsFile, config.NamesFile, 0, useOnlyCpu);
                sw.Stop();

                var action = new MethodInvoker(delegate()
                {
                    var detectionSystemDetail = string.Empty;
                    if (!string.IsNullOrEmpty(this._yoloWrapper.EnvironmentReport.GraphicDeviceName))
                    {
                        detectionSystemDetail = $"({this._yoloWrapper.EnvironmentReport.GraphicDeviceName})";
                    }
                    this.toolStripStatusLabelYoloInfo.Text = $"Initialize Yolo in {sw.Elapsed.TotalMilliseconds:0} ms - Detection System:{this._yoloWrapper.DetectionSystem} {detectionSystemDetail} Weights:{config.WeightsFile}";
                });

                this.statusStrip1.Invoke(action);
                this.buttonSendImage.Invoke(new MethodInvoker(delegate() { this.buttonSendImage.Enabled = true; }));
            }
            catch (Exception exception)
            {
                MessageBox.Show($"{nameof(Initialize)} - {exception}", "Error Initialize", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #4
0
        private static void Initialize(YoloConfiguration config)
        {
            if (_yoloWrapper != null)
            {
                _yoloWrapper.Dispose();
            }

            _yoloWrapper = new YoloWrapper(config.ConfigFile, config.WeightsFile, config.NamesFile, 0);
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: massaynus/Object-Classifier
        public Form1()
        {
            InitializeComponent();
            textBox1.Enabled       = false;
            textBox1.AcceptsReturn = true;

            configurationDetector = new YoloConfigurationDetector();
            config = configurationDetector.Detect();
        }
コード例 #6
0
ファイル: Main.cs プロジェクト: lisansojib/Alturos.Yolo
        private void Initialize(YoloConfiguration config)
        {
            var sw = new Stopwatch();

            sw.Start();
            this._yoloWrapper = new YoloWrapper(config.ConfigFile, config.WeightsFile, config.NamesFile, 0);
            sw.Stop();

            this.statusStrip1.Invoke(new MethodInvoker(delegate() { this.toolStripStatusLabel1.Text = $"Initialize elapsed in {sw.Elapsed.TotalMilliseconds:0} ms DetectionSystem:{this._yoloWrapper.DetectionSystem} ({this._yoloWrapper.EnvironmentReport.GraphicDeviceName})"; }));
            this.buttonSendImage.Invoke(new MethodInvoker(delegate() { this.buttonSendImage.Enabled = true; }));
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: HaxThePlanet/Alturos.Yolo
            private bool AreValidYoloFiles(YoloConfiguration config)
            {
                if (string.IsNullOrEmpty(config.ConfigFile) ||
                    string.IsNullOrEmpty(config.WeightsFile) ||
                    string.IsNullOrEmpty(config.NamesFile))
                {
                    return(false);
                }

                return(true);
            }
コード例 #8
0
        private bool AreYoloFilesValid(YoloConfiguration config)
        {
            if (string.IsNullOrEmpty(config.ConfigFile) ||
                string.IsNullOrEmpty(config.WeightsFile) ||
                string.IsNullOrEmpty(config.NamesFile))
            {
                return(false);
            }

            if (Path.GetFileNameWithoutExtension(config.ConfigFile) != Path.GetFileNameWithoutExtension(config.WeightsFile))
            {
                return(false);
            }

            return(true);
        }
コード例 #9
0
        public YoloObjectDetector(bool ignoreGPU)
        {
            if (useYoloV3)
            {
                defaultConfigurationPath = "..\\..\\..\\..\\_YoloConfiguration\\MSLRobotBallonButDetection\\";//
                yoloCFGFileName          = "yolov3-MSLRobotBallonButDetection.cfg";
                yoloWeightsFileName      = "yolov3-MSLRobotBallonButDetection_final.weights";
                yoloNamesFileName        = "MSLRobotBallonButDetection.names";
            }
            else if (useTiny)
            {
                defaultConfigurationPath = "..\\..\\..\\..\\_YoloConfiguration\\TinyYolo\\";//
                yoloCFGFileName          = "yolov3-tiny.cfg";
                yoloWeightsFileName      = "yolov3-tiny.weights";
                yoloNamesFileName        = "coco.names";
            }
            // try
            {
                if (this.wrap != null)
                {
                    this.wrap.Dispose();
                }

                string[] files = Directory.GetFiles(defaultConfigurationPath);
                yoloConfig = new YoloConfiguration(defaultConfigurationPath + yoloCFGFileName, defaultConfigurationPath + yoloWeightsFileName, defaultConfigurationPath + yoloNamesFileName);
                wrap       = new YoloWrapper(yoloConfig, ignoreGPU); //By default GPU 0 is used if used

                var detectionSystemDetail = string.Empty;
                if (!string.IsNullOrEmpty(this.wrap.EnvironmentReport.GraphicDeviceName))
                {
                    detectionSystemDetail = $"({this.wrap.EnvironmentReport.GraphicDeviceName})";
                }
                Console.WriteLine(detectionSystemDetail);
            }
            //catch
            {
                // throw new Exception("Couldn't open yolo");
            }


            new Thread(DetectAndLabel).Start();
        }
コード例 #10
0
ファイル: Main.cs プロジェクト: weisiong/Alturos.Yolo
        private void Initialize(YoloConfiguration yoloConfiguration)
        {
            var sw = new Stopwatch();

            sw.Start();
            var successful = this._yoloWrapper.Initialize(yoloConfiguration);

            sw.Stop();

            if (successful)
            {
                this.toolStripStatusLabel1.Text = $"Initialize elapsed in {sw.Elapsed.TotalMilliseconds}ms";
            }
            else
            {
                this.toolStripStatusLabel1.Text = $"Initialize failure";
            }

            this.buttonSendImage.Enabled = true;
        }
コード例 #11
0
ファイル: Main.cs プロジェクト: tonyle8/Yolo.Net
        private void Initialize(YoloConfiguration config)
        {
            try
            {
                if (_yoloWrapper != null)
                {
                    _yoloWrapper.Dispose();
                }

                var gpuConfig  = new GpuConfig();
                var useOnlyCpu = cpuToolStripMenuItem.Checked;
                if (useOnlyCpu)
                {
                    gpuConfig = null;
                }

                toolStripStatusLabelYoloInfo.Text = $"Initialize...";

                var sw = new Stopwatch();
                sw.Start();
                _yoloWrapper = new YoloWrapper(config.ConfigFile, config.WeightsFile, config.NamesFile, gpuConfig);
                sw.Stop();

                var action = new MethodInvoker(delegate
                {
                    var deviceName = _yoloWrapper.GetGraphicDeviceName(gpuConfig);
                    toolStripStatusLabelYoloInfo.Text = $"Initialize Yolo in {sw.Elapsed.TotalMilliseconds:0} ms - Detection System:{_yoloWrapper.DetectionSystem} {deviceName} Weights:{config.WeightsFile}";
                });

                statusStrip1.Invoke(action);
                buttonProcessImage.Invoke(new MethodInvoker(delegate { buttonProcessImage.Enabled = true; }));
                buttonStartTracking.Invoke(new MethodInvoker(delegate { buttonStartTracking.Enabled = true; }));
            }
            catch (Exception exception)
            {
                MessageBox.Show($"{nameof(Initialize)} - {exception}", "Error Initialize", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #12
0
 public Form1()
 {
     InitializeComponent();
     configurationDetector = new ConfigurationDetector();
     config = configurationDetector.Detect();
 }
コード例 #13
0
ファイル: MainWindow.cs プロジェクト: bjced/DarknetSharpDemo
 public YoloEntry(YoloSelection selection, YoloConfiguration conf)
 {
     Selection = selection;
     Conf      = conf;
 }
コード例 #14
0
 private static bool AreValidYoloFiles(YoloConfiguration config) =>
 !string.IsNullOrEmpty(config.ConfigFile) &&
 !string.IsNullOrEmpty(config.WeightsFile) && !string.IsNullOrEmpty(config.NamesFile);
コード例 #15
0
        public void run()
        {
            detect = true;

            const int screenWidth = 1920;
            const int screenHeight = 1080;
            const int captureRegionWidth = 1200;
            const int captureRegionHeight = 675;

            Console.WriteLine("Starting YOLO object detection ...");
            var gpuConfig = new GpuConfig();
            var yoloConfig =
                new YoloConfiguration("yolov4-valorant.cfg", "yolov4-valorant_last.weights", "valorant.names");
            using (var yoloWrapper = new YoloWrapper(yoloConfig, gpuConfig))
            {
                Console.WriteLine("Starting detection loop ...");
                Stopwatch watch = new Stopwatch();
                Rectangle capRegion = new Rectangle((screenWidth / 2) - (captureRegionWidth / 2),
                    (screenHeight / 2) - (captureRegionHeight / 2), captureRegionWidth, 675);
                while (detect)
                {
                    watch.Restart();
                    Bitmap bmp = cap.CaptureRegion(capRegion);

                    byte[] jpgBytes = (byte[]) new ImageConverter().ConvertTo(bmp, typeof(byte[]));
                    var detectedObjects = yoloWrapper.Detect(jpgBytes);

                    using (Graphics capturedScreen = Graphics.FromImage(bmp))
                    {
                        foreach (var detectedObject in detectedObjects)
                        {
                            Color color;
                            switch (detectedObject.Type)
                            {
                                case "player":
                                    color = Color.LawnGreen;
                                    break;
                                case "head_player":
                                    color = Color.Red;
                                    break;
                                default:
                                    color = Color.Black;
                                    break;
                            }

                            capturedScreen.DrawRectangle(new Pen(color), detectedObject.X, detectedObject.Y,
                                detectedObject.Width, detectedObject.Height);
                            capturedScreen.DrawString(
                                detectedObject.Type + "(" + Math.Round(detectedObject.Confidence * 100) + "%)",
                                new Font(FontFamily.GenericMonospace, 15), new SolidBrush(color), detectedObject.X,
                                detectedObject.Y);
                        }

                        watch.Stop();
                        capturedScreen.DrawString(
                            (1000 / watch.ElapsedMilliseconds) + "FPS (" + watch.ElapsedMilliseconds + "ms)",
                            new Font(FontFamily.GenericMonospace, 15), new SolidBrush(Color.LimeGreen), 10, 10);
                    }

                    form.pictureBox1.Image = bmp;
                }
            }
        }