private string Detection(byte[] imagebyte)
        {
            UIUpdate("In detect");
            var configurationDetector = new ConfigurationDetector();
            var config = configurationDetector.Detect();

            YoloWrapper            yoloWrapper = new YoloWrapper(config);       // 使用YoloWrapper物件(Alturos裡的主要辨識程式)
            IEnumerable <YoloItem> items       = yoloWrapper.Detect(imagebyte); // 呼叫偵測函式,結果儲存於items裡
            string message = string.Empty;

            foreach (YoloItem item in items)
            {
                //if (item.Type == "TroopsHeadquarters")
                //{
                //    message += "1,";
                //}
                //else message += item.Type + ',';

                message += (item.Type == "TroopsHeadquarters" ? "1" : item.Type) + ',' +
                           item.X + ',' +
                           item.Y + ',' +
                           item.Width + ',' +
                           item.Height + ',' +
                           item.Confidence + ';';   // 將目標的種類、座標及信賴值存成字串,以方便傳輸
            }

            return(message);
        }
Exemplo n.º 2
0
        public override Task <Result> GetDetections(Payload request, ServerCallContext context)
        {
            using var yoloWrapper = new YoloWrapper(
                      "C:\\Development\\PointerAppAlyn\\YOLOv3-Object-Detection-with-OpenCV\\profiling\\cfg\\yolov3.cfg",
                      "C:\\Development\\PointerAppAlyn\\YOLOv3-Object-Detection-with-OpenCV\\profiling\\weights\\yolov3.weights",
                      "C:\\Development\\PointerAppAlyn\\YOLOv3-Object-Detection-with-OpenCV\\profiling\\coco.names");
            var items = yoloWrapper.Detect(request.Image.ToByteArray());

            var result = new Result();

            foreach (var yoloItem in items)
            {
                Console.WriteLine(yoloItem.Type);
                result.Detections.Add(new DetectionResult
                {
                    Type = yoloItem.Type,
                    X    = yoloItem.X,
                    Y    = yoloItem.Y,
                    W    = yoloItem.Width,
                    H    = yoloItem.Height
                });
            }

            return(Task.FromResult(result));
        }
Exemplo n.º 3
0
        private void CheckSetting()
        {
            while (true)
            {
                Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
                {
                    if (tb_cfg.Text != "" && tb_names.Text != "" && tb_weights.Text != "")
                    {
                        bd_Setting.Visibility = Visibility.Collapsed;
                        bd_Testing.Visibility = Visibility.Visible;

                        Wrapper         = new YoloWrapper(tb_cfg.Text, tb_weights.Text, tb_names.Text, 0, false);
                        DetectionSystem = Wrapper.DetectionSystem;

                        switch (DetectionSystem)
                        {
                        case DetectionSystem.CPU:
                            tb_state.Text = "CPU 환경 : ";
                            break;

                        case DetectionSystem.GPU:
                            tb_state.Text = "GPU 환경 : ";
                            break;

                        default:
                            break;
                        }
                        t1.Abort();
                    }
                }));
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            YoloWrapper yolodetector;

            try
            {
                yolodetector = new YoloWrapper("yolov5x.cfg", "x_best.weights", 0);
            }
            catch (Exception)
            {
                throw;
            }

            byte[]   picBytes    = GetPictureData("5_YXK54X.jpg");
            bbox_t[] result_list = yolodetector.Detect(picBytes);
            foreach (var result in result_list)
            {
                Console.WriteLine($" hair deteteted -> x:{result.x}, y:{result.y}");
            }

            bbox_t[] result_list_2 = yolodetector.Detect("5_YXK54X.jpg");
            foreach (var result in result_list_2)
            {
                Console.WriteLine($" hair deteteted -> x:{result.x}, y:{result.y}");
            }
            Console.WriteLine("Hello World!");
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        public void DetectNative()
        {
            var configuration = new YoloConfigurationDetector().Detect();

            using (var yoloWrapper = new YoloWrapper(configuration))
            {
                using (var image = new Bitmap(600, 400))
                    using (var canvas = Graphics.FromImage(image))
                    {
                        canvas.Clear(Color.AliceBlue);
                        canvas.FillPie(Brushes.Black, 0, 0, 100, 100, 0, 360);
                        canvas.Flush();

                        BitmapData bmpData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                                            ImageLockMode.ReadOnly,
                                                            image.PixelFormat);

                        var rawImagePtr = bmpData.Scan0;
                        var bmpImagePtr = IntPtr.Zero;

                        try
                        {
                            bmpImagePtr = CreateBmp(rawImagePtr, image.Width, image.Height, out var length);
                            var result = yoloWrapper.Detect(bmpImagePtr, length);
                        }
                        finally
                        {
                            if (bmpImagePtr != IntPtr.Zero)
                            {
                                Marshal.FreeHGlobal(bmpImagePtr);
                            }
                        }
                    }
            }
        }
Exemplo n.º 7
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            // using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "PNG|*.png|JPEG|*.jpeg|JPG|*.jpg"})
            // {
            //   if (ofd.ShowDialog() == DialogResult.OK)
            // {

            pic.Image = Image.FromFile(@"D:\Visual Studio 2017\Projects\Alturos.Yolo-master\Images\Car1.png");
            using (var yoloWrapper = new YoloWrapper("yolov2-tiny-voc.cfg", "yolov2-tiny-voc.weights", "voc.names"))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    pic.Image.Save(ms, ImageFormat.Png);
                    var items = yoloWrapper.Detect(ms.ToArray());
                    yoloItemBindingSource.DataSource = items;
                }

                //


                //items[0].Type -> "Person, Car, ..."
                //items[0].Confidence -> 0.0 (low) -> 1.0 (high)
                //items[0].X -> bounding box
                //items[0].Y -> bounding box
                //items[0].Width -> bounding box
                //items[0].Height -> bounding box
            }
            //}
            //}
        }
Exemplo n.º 8
0
        private void Grabar(object sender, NewFrameEventArgs frame)
        {
            Bitmap    video   = (Bitmap)frame.Frame.Clone();
            Bitmap    temp    = new Bitmap(video.Width, video.Height);
            Graphics  g       = Graphics.FromImage(temp);
            int       left    = video.Width / 4;
            int       top     = video.Height / 4;
            int       width   = video.Width / 2;
            int       height  = video.Height / 2;
            Rectangle srcRect = new Rectangle(left, top, width, height);
            Rectangle dstRect = new Rectangle(0, 0, temp.Width, temp.Height);

            g.DrawImage(video, dstRect, srcRect, GraphicsUnit.Pixel);

            //========================================= Prueba IA =================================================
            picture.Image = video;
            var configurationDetector = new ConfigurationDetector();
            var config       = configurationDetector.Detect();
            var yolo         = new YoloWrapper(config);
            var memoryStream = new MemoryStream();

            video.Save(memoryStream, ImageFormat.Png);
            var items = yolo.Detect(memoryStream.ToArray()).ToList();

            AddDetailsToPictureBox(picture, items, frame);

            //========================================= Prueba IA =================================================

            //picture.Image = temp;
            //pictureBox1.Image = this.Tracker(frame, color1, "celeste");
            //pictureBox2.Image = this.Tracker(frame, color2, "verde");
            //pictureBox3.Image = this.Tracker(frame, color3, "rojo");
        }
Exemplo n.º 9
0
        //without validation i.e., output all yolo detections
        public FrameDNNDarknet(string modelConfig, DNNMode dnnMode)
        {
            var configurationDetector = new ConfigurationDetector(modelConfig);

            frameYolo         = new YoloWrapper(configurationDetector.Detect(), dnnMode);
            frameYoloTracking = new YoloTracking(frameYolo);
        }
Exemplo n.º 10
0
        //distance-based validation
        public FrameDNNDarknet(string modelConfig, DNNMode dnnMode, double rFactor)
        {
            var configurationDetector = new ConfigurationDetector(modelConfig);

            frameYolo         = new YoloWrapper(configurationDetector.Detect(), dnnMode);
            frameYoloTracking = new YoloTracking(frameYolo, Convert.ToInt32(DNNConfig.ValidRange * rFactor));
        }
Exemplo n.º 11
0
        private void narsalarniAniqlashToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var configurationDetector = new ConfigurationDetector();
            var config = configurationDetector.Detect();

            using (var yoloWrapper = new YoloWrapper(config))
            {
                var items = yoloWrapper.Detect(ImageToByte(pictureBox1.Image));
                if (items.Count() > 0)
                {
                    foreach (YoloItem item in items)
                    {
                        Bitmap    bmp       = new Bitmap(pictureBox1.Image);
                        Rectangle rectangle = new Rectangle(item.X, item.Y, item.Width, item.Height);
                        ImgInput = new Image <Bgr, byte>(bmp);
                        ImgInput.Draw(rectangle, new Bgr(0, 0, 255), 2);
                        ImgInput.Draw($"{item.Type} ({string.Format("{0:0.0}", item.Confidence)})",
                                      new Point(item.X - 2, item.Y - 2),
                                      Emgu.CV.CvEnum.FontFace.HersheyDuplex, 0.5, new Bgr(Color.DarkBlue));

                        pictureBox1.Image = ImgInput.Bitmap;
                    }
                }
            }
        }
Exemplo n.º 12
0
        private void Form1_Load(object sender, EventArgs e)
        {
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            if (videoDevices.Count != 0)
            {
                foreach (FilterInfo cam in videoDevices)
                {
                    camerasStripComboBox.Items.Add(cam.Name);
                }
                camerasStripComboBox.SelectedIndex = 0;
            }

            try
            {
                yolo = new YoloWrapper(
                    "yolo-weights\\yolov3.cfg",
                    "yolo-weights\\yolov3.weights",
                    "yolo-weights\\coco.names"
                    );
            }
            catch (Exception)
            {
                MessageBox.Show("Не найдены библиотеки Yolo. " +
                                "Пожалуйста проверьте наличие файлов yolov3.cfg, yolov3.weights, coco.names " +
                                "в каталоге yolo-weights и перезапустите приложение");
                Environment.Exit(1);
            }
        }
Exemplo n.º 13
0
        private void Check(GpuConfig gpuConfig)
        {
            var yoloWrapper = new YoloWrapper("yolov2-tiny-voc.cfg", "yolov2-tiny-voc.weights", "voc.names", gpuConfig);
            var files       = Directory.GetFiles(@".\Images");

            var retrys = 10;

            var sw = new Stopwatch();

            foreach (var file in files)
            {
                var elapsed   = 0.0;
                var fileInfo  = new FileInfo(file);
                var imageData = File.ReadAllBytes(file);

                for (var i = 0; i < retrys; i++)
                {
                    sw.Restart();
                    yoloWrapper.Detect(imageData);
                    sw.Stop();

                    elapsed += sw.Elapsed.TotalMilliseconds;
                }

                var average = elapsed / retrys;
                Console.WriteLine($"{fileInfo.Name} {average}ms");
            }

            yoloWrapper.Dispose();
        }
Exemplo n.º 14
0
        static void TestLogic1()
        {
            var yoloWrapper = new YoloWrapper("yolov2-tiny-voc.cfg", "yolov2-tiny-voc.weights", "voc.names");
            var files       = Directory.GetFiles(@".\Images");

            var retrys = 100;

            for (var i = 0; i < retrys; i++)
            {
                foreach (var file in files)
                {
                    var fileInfo  = new FileInfo(file);
                    var imageData = File.ReadAllBytes(file);

                    var sw = new Stopwatch();
                    sw.Start();
                    var items = yoloWrapper.Detect(imageData).ToList();
                    sw.Stop();
                    Console.WriteLine($"{fileInfo.Name} found {items.Count} results, elapsed {sw.Elapsed.TotalMilliseconds:0.00}ms");

                    if (items.Count > 0)
                    {
                        Console.WriteLine("------------------DETAILS-----------------");

                        foreach (var item in items)
                        {
                            Console.WriteLine($"Type:{item.Type} Confidence:{item.Confidence:0.00}");
                        }

                        Console.WriteLine("------------------------------------------");
                    }
                }
            }
        }
Exemplo n.º 15
0
        public int Detect(string imgPath)
        {
            string target1 = @"D:\Visual Project\TrafficServer\TrafficServer\bin\yolov2-tiny-voc.cfg";
            string target2 = @"D:\Visual Project\TrafficServer\TrafficServer\bin\yolov2-tiny-voc.weights";
            string target3 = @"D:\Visual Project\TrafficServer\TrafficServer\bin\voc.names";

            if (File.Exists(target1))
            {
                var configurationDetector = new ConfigurationDetector();
                using (var yoloWrapper = new YoloWrapper(target1, target2, target3))
                {
                    var sw = new Stopwatch();
                    sw.Start();
                    var items = yoloWrapper.Detect(imgPath);
                    //txtKetQua.Text = "Number of Object Detected: " + items.Count().ToString() + "\tin: " + sw.Elapsed.TotalSeconds + "s\n";
                    int y = 0;
                    foreach (Alturos.Yolo.Model.YoloItem s in items)
                    {
                        if (s.Type.ToString().Equals("car"))
                        {
                            y++;
                        }
                    }
                    sw.Stop();
                    return(items.Count());
                }
                //txtKetQua.Text = "Yes";
            }
            else
            {
                return(0);
            }
        }
        /// <summary>
        /// Analyses a bitmap by detecting all the objects in it and returning them as a list.
        /// </summary>
        /// <param name="image"></param>
        public IEnumerable <YoloItem> DetectItemsInBitmap(Bitmap image)
        {
            var cfgPath     = ServiceContainer.GetService <GlobalEnviromentService>().YOLOConfigLocation;
            var weightsPath = ServiceContainer.GetService <GlobalEnviromentService>().YOLOWeightsLocation;
            var namesPath   = ServiceContainer.GetService <GlobalEnviromentService>().YOLONamesLocation;

            using (var yoloWrapper = new YoloWrapper(cfgPath, weightsPath, namesPath))
            {
                using (var memStream = new MemoryStream())
                {
                    image.Save(memStream, ImageFormat.Png);
                    var items = yoloWrapper.Detect(memStream.ToArray());
                    // We do NOT want sports ball as objects.
                    // TODO: Later I can add a blacklist of all the objects that are not important to ignore them.
                    items = items.Where(i => i.Type != "sports ball").Select(i => i);

                    for (int i = 0; i < items.Count(); i++)
                    {
                        items.ElementAt(i).Type = $"object #{i}";
                    }

                    return(items);
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Compare yolo speed with optimal images in the correct size
        /// Resize before and resize in yolo
        /// </summary>
        public void Start()
        {
            var yoloWrapper  = new YoloWrapper("yolov2-tiny-voc.cfg", "yolov2-tiny-voc.weights", "voc.names");
            var files        = Directory.GetFiles(@".\Images");
            var imageResizer = new ImageResizer();

            var retries = 10;

            Console.WriteLine("|{0,20}|{1,29}|{2,43}|", "", "Resize with yolo", "Resize before yolo");
            Console.WriteLine("|{0,20}|{1,15}|{2,13}|{3,15}|{4,13}|{5,13}|{6,10}|{7,10}|", "Image", "detected items", "elapsed (ms)", " detected items", "resize (ms)", "yolo (ms)", "diff (ms)", "faster");

            foreach (var file in files)
            {
                for (var i = 0; i < retries; i++)
                {
                    var fileInfo  = new FileInfo(file);
                    var imageData = File.ReadAllBytes(file);

                    var result1 = ProcessResizeAfter(yoloWrapper, imageData);
                    var result2 = ProcessResizeBefore(yoloWrapper, imageResizer, imageData);
                    var diff    = result1.Item3 - result2.Item4;

                    Console.WriteLine("|{0,20}|{1,15}|{2,13}|{3,15}|{4,13}|{5,13}|{6,10}|{7,10}|", fileInfo.Name, result1.Item1.Count, result1.Item2, result2.Item1.Count, result2.Item2, result2.Item3, diff.ToString("0.00"), diff > 0);
                }
            }

            yoloWrapper.Dispose();
        }
Exemplo n.º 18
0
 static public YoloWrapper GetYolo(string Game)
 {
     if (File.Exists($"trainfiles/{Game}.cfg") && File.Exists($"trainfiles/{Game}.weights") && File.Exists($"trainfiles/{Game}.names"))
     {
         var yoloWrapper = new YoloWrapper($"trainfiles/{Game}.cfg", $"trainfiles/{Game}.weights", $"trainfiles/{Game}.names");
         Console.Clear();
         if (yoloWrapper.EnvironmentReport.CudaExists == false)
         {
             Console.WriteLine("Install CUDA 10");
             Process.GetCurrentProcess().Kill();
         }
         if (yoloWrapper.EnvironmentReport.CudnnExists == false)
         {
             Console.WriteLine("Cudnn doesn't exist");
             Process.GetCurrentProcess().Kill();
         }
         if (yoloWrapper.EnvironmentReport.MicrosoftVisualCPlusPlus2017RedistributableExists == false)
         {
             Console.WriteLine("Install Microsoft Visual C++ 2017 Redistributable");
             Process.GetCurrentProcess().Kill();
         }
         if (yoloWrapper.DetectionSystem.ToString() != "GPU")
         {
             MessageBox.Show("No GPU card detected. Exiting...");
             Process.GetCurrentProcess().Kill();
         }
         return(yoloWrapper);
     }
     return(null);
 }
Exemplo n.º 19
0
 public Form2(VideoCaptureDevice cameraIn, Form1 f)
 {
     InitializeComponent();
     yoloWrapper = new YoloWrapper(@".\YoloFiles\yolov3-tiny.cfg", @".\YoloFiles\yolov3-tiny.weights", @".\YoloFiles\coco.names");
     bgWorker    = new BackgroundWorker();
     bgWorker.WorkerSupportsCancellation = true;
     bgWorker.DoWork += BgWorker_DoWork;
     synth.SetOutputToDefaultAudioDevice();
     camera           = cameraIn;
     camera.NewFrame += camera_NewFrame;
     camera.Start();
     this.Size    = new Size(camera.VideoResolution.FrameSize.Width, camera.VideoResolution.FrameSize.Height + 150);
     pic.Size     = camera.VideoResolution.FrameSize;
     Log.Location = new Point(0, camera.VideoResolution.FrameSize.Height);
     Log.Size     = new Size(camera.VideoResolution.FrameSize.Width - 15, 110);
     temp         = f;
     //aTimer = new System.Timers.Timer();
     //aTimer.Interval = 2000;
     //aTimer.Elapsed += OnTimedEvent;
     //aTimer.AutoReset = true;
     //aTimer.Enabled = true;
     Log.ReadOnly   = true;
     Log.ScrollBars = ScrollBars.Vertical;
     Log.Text       = "Log:";
     bgWorker.RunWorkerAsync();
 }
Exemplo n.º 20
0
        static void CheckPerformance()
        {
            var yoloWrapper  = new YoloWrapper("yolov2-tiny-voc.cfg", "yolov2-tiny-voc.weights", "voc.names");
            var files        = Directory.GetFiles(@".\Images");
            var imageResizer = new ImageResizer();

            var retrys = 3;

            Console.WriteLine(string.Format("|{0,40}|{1,5}|{2,25}|{3,5}|{4,25}|{5,10}|{6,10}|", "Image", "items", "elapsed (ms)", "items", "elapsed (ms)", "diff (ms)", "faster"));

            foreach (var file in files)
            {
                for (var i = 0; i < retrys; i++)
                {
                    var fileInfo  = new FileInfo(file);
                    var imageData = File.ReadAllBytes(file);

                    var result1 = ProcessResizeAfter(yoloWrapper, imageData);
                    var result2 = ProcessResizeBefore(yoloWrapper, imageResizer, imageData);
                    var diff    = result1.Item3 - result2.Item3;

                    Console.WriteLine(string.Format("|{0,40}|{1,5}|{2,25}|{3,5}|{4,25}|{5,10}|{6,10}|", fileInfo.Name, result1.Item1.Count, result1.Item2, result2.Item1.Count, result2.Item2, diff.ToString("0.00"), diff > 0));
                }
            }
        }
Exemplo n.º 21
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);
            }
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            var windowCapture = new Window("windowCapture");
            var capture       = new VideoCapture(0);
            var image         = new Mat();
            var yoloWrapper   = new YoloWrapper("yolov2-tiny-voc.cfg", "yolov2-tiny-voc.weights", "voc.names", DetectionSystem.GPU);

            while (true)
            {
                capture.Read(image);
                if (image.Empty())
                {
                    break;
                }

                var bytes = image.ToBytes(".png");
                var items = yoloWrapper.Detect(bytes).ToArray();

                foreach (var item in items)
                {
                    var value = (item.Confidence * 100).ToString("0");
                    var text  = $"{item.Type} - {value}%";
                    ImageUtilHelper.AddBoxToImage(image, text, item.X, item.Y, item.X + item.Width, item.Y + item.Height);
                }

                windowCapture.ShowImage(image);

                if ((Cv2.WaitKey(25) & 0xFF) == 'q')
                {
                    Cv2.DestroyAllWindows();
                    break;
                }
            }
        }
Exemplo n.º 23
0
 public TreatmentPhoto(Form1 f1, List <string> lp, YoloWrapper yw)
 {
     this.GlobalForm  = f1;
     this.yoloWrapper = yw;
     this.listPhotos  = lp;
     this.countPhotos = lp.Count;
 }
Exemplo n.º 24
0
 public Logohunter(List <string> brandsPaths)
 {
     _yolowrapper = new YoloWrapper(CFG, WEIGHTS, NAMES);
     _graph       = new TFGraph();
     _graph.Import(File.ReadAllBytes(INCEPTION));
     _cutoffs = LoadBrandsComputeCutoffs(brandsPaths, LoadFeatures());
 }
Exemplo n.º 25
0
        public YoloObjectDetection()
        {
            var configurationDetector = new YoloConfigurationDetector();
            var configuration         = configurationDetector.Detect();

            _yoloWrapper = new YoloWrapper(configuration);
        }
Exemplo n.º 26
0
        private void btnDetect_Click(object sender, EventArgs e)
        {
            var configurationDetector = new ConfigurationDetector();
            var config = configurationDetector.Detect();

            using (var yoloWrapper = new YoloWrapper(config))
            {
                MemoryStream ms = new MemoryStream();
                pictureBox1.Image.Save(ms, ImageFormat.Png);
                var items = yoloWrapper.Detect(ms.ToArray());
                foreach (var item in items)
                {
                    var x      = item.X;
                    var y      = item.Y;
                    var width  = item.Width;
                    var height = item.Height;
                    var type   = item.Type;

                    Pen      pen = new Pen(Color.Red);
                    Graphics g   = pictureBox1.CreateGraphics();
                    g.DrawRectangle(pen, x, y, width, height);
                }

                dataGridView1.DataSource = items;
            }
        }
Exemplo n.º 27
0
        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; }));
        }
Exemplo n.º 28
0
        static void TestTracking()
        {
            Directory.CreateDirectory("trackingImages");

            var configurationDetector = new ConfigurationDetector();
            var config = configurationDetector.Detect();

            using (var yoloWrapper = new YoloWrapper(config))
            {
                var yoloTracking = new YoloTracking(yoloWrapper, 200);

                yoloTracking.SetTrackingObject(new Point(216, 343));
                var files = Directory.GetFiles(@"test");

                //yoloTracking.SetTrackingObject(new Point(385, 480));
                //var files = Directory.GetFiles(@"test3");

                foreach (var file in files)
                {
                    var imageData    = File.ReadAllBytes(file);
                    var trackingItem = yoloTracking.Analyse(imageData);
                    if (trackingItem == null)
                    {
                        continue;
                    }

                    var fileInfo = new FileInfo(file);
                    File.WriteAllBytes($@"trackingImages\{trackingItem.Index}.bmp", trackingItem.TaggedImageData);
                }
            }

            Console.ReadLine();
        }
Exemplo n.º 29
0
        public YoloServiceImpl()
        {
            var configurationDetector = new ConfigurationDetector();
            var config = configurationDetector.Detect();

            yoloWrapper = new YoloWrapper(config);
        }
Exemplo n.º 30
0
        void Startup()
        {
            listImages = new List <string>();
            var configurationDetector = new YoloConfigurationDetector();
            var config = configurationDetector.Detect();

            yoloWrapper = new YoloWrapper(config);  //phải nhớ là cái này được tạo từ đầu rồi, không tạo mới nữa nếu không nó sẽ null
        }