private void evaluate_Click(object sender, EventArgs e)
        {
            var bitmap = GetImage(this.textBox1.Text);
            var output = (Bitmap)bitmap.Clone();

            bitmap = BitmapTool.ResizeImage(bitmap, 300, 300);

            bitmap.Save("input.jpg");

            var boxes = new List <BoundingBox>();

            int divisor = (int)this.divisorUpDown.Value;

            var allExtracts = BitmapTool.SlideWindow(bitmap, 140, 140 / divisor)
                              .Concat(BitmapTool.SlideWindow(bitmap, 100, 100 / divisor))
                              .Concat(BitmapTool.SlideWindow(bitmap, 80, 80 / divisor))
                              .Concat(BitmapTool.SlideWindow(bitmap, 30, 30 / divisor));

            foreach (var extracts in allExtracts.Batch(20))
            {
                boxes.AddRange(BitmapTool.Evaluate(extracts.ToList(), this._yhat, IMAGE_WIDTH, IMAGE_HEIGHT, (float)this.minProbaUpDown.Value / 100.0f));
            }

            this.currentBoundingBoxes.Clear();
            var nms    = new NonMaximumSuppresion();
            var result = nms.Nms(boxes, (float)this.nmsUpDown.Value / 100.0f);

            foreach (var boundingBox in result)
            {
                BitmapTool.DrawBoundingBox(output, boundingBox, Color.FromArgb(50, 0, 0, 255), false);
                this.currentBoundingBoxes.Add(BitmapTool.Capture(bitmap, boundingBox));
            }

            this.pictureBox1.Image = output;
        }
Exemple #2
0
        private void NewFrame_event(object send, NewFrameEventArgs e)
        {
            try
            {
                lock (this._locker)
                {
                    var webcamFrame = e.Frame;

                    if (this._queueIn.Count == 0)
                    {
                        this._queueIn.Enqueue((Bitmap)webcamFrame.Clone());
                    }

                    if (this._queueOut.TryDequeue(out var boundingBox))
                    {
                        this._lastBoundingBoxes = boundingBox;

                        BeginInvoke(new Action(() => { this.Text = (++this._evaluationCount).ToString(); }));
                    }

                    if (this._lastBoundingBoxes != null)
                    {
                        foreach (var box in this._lastBoundingBoxes)
                        {
                            BitmapTool.DrawBoundingBox(webcamFrame, box, Color.FromArgb(50, 0, 0, 255), false);
                        }

                        var nms    = new NonMaximumSuppresion();
                        var result = nms.Nms(this._lastBoundingBoxes, 0.20f);
                        foreach (var box in result)
                        {
                            BitmapTool.DrawBoundingBox(webcamFrame, box, Color.FromArgb(50, 0, 255, 0), false);
                        }
                    }

                    this.pictureBox.Image = (Image)webcamFrame.Clone();
                }
            }
            catch
            {
            }
        }