Exemplo n.º 1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string name = txtName.Text;

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            bt.ColorBin bin = new bt.ColorBin();
            bin.Name = name;

            _blobTrackerPort.DeleteBin(bin);
        }
Exemplo n.º 2
0
        private void btnTrain_Click(object sender, EventArgs e)
        {
            string name = txtName.Text;

            if (string.IsNullOrEmpty(name) || _radius == 0 || !_ready)
            {
                return;
            }

            Bitmap bmp = picCamera.Image as Bitmap;

            if (bmp == null)
            {
                return;
            }

            int accumRed   = 0;
            int accumGreen = 0;
            int accumBlue  = 0;
            int count      = 0;

            int[] redProjection   = new int[256];
            int[] greenProjection = new int[256];
            int[] blueProjection  = new int[256];

            for (int y = _center.Y - _radius; y <= _center.Y + _radius; y++)
            {
                if (y < 0 || y >= bmp.Height)
                {
                    continue;
                }

                for (int x = _center.X - _radius; x <= _center.X + _radius; x++)
                {
                    if (x < 0 || x >= bmp.Width)
                    {
                        continue;
                    }

                    int dx = _center.X - x;
                    int dy = _center.Y - y;

                    if (dx * dx + dy * dy > _radius)
                    {
                        continue;
                    }

                    Color color = bmp.GetPixel(x, y);

                    count++;
                    accumRed   += color.R;
                    accumGreen += color.G;
                    accumBlue  += color.B;

                    redProjection[color.R]++;
                    greenProjection[color.G]++;
                    blueProjection[color.B]++;
                }
            }

            double meanRed   = (double)accumRed / count;
            double meanGreen = (double)accumGreen / count;
            double meanBlue  = (double)accumBlue / count;

            double redDev   = 1 + CalculateDeviation(meanRed, redProjection);
            double greenDev = 1 + CalculateDeviation(meanGreen, greenProjection);
            double blueDev  = 1 + CalculateDeviation(meanBlue, blueProjection);

            bt.ColorBin bin = new bt.ColorBin();
            bin.Name = name;

            bin.RedMin   = (int)Math.Round(meanRed - redDev);
            bin.RedMax   = (int)Math.Round(meanRed + redDev);
            bin.GreenMin = (int)Math.Round(meanGreen - greenDev);
            bin.GreenMax = (int)Math.Round(meanGreen + greenDev);
            bin.BlueMin  = (int)Math.Round(meanBlue - blueDev);
            bin.BlueMax  = (int)Math.Round(meanBlue + blueDev);

            if (_tracking != null &&
                _tracking.Exists(
                    delegate(bt.FoundBlob test)
            {
                return(test.Name == name);
            })
                )
            {
                _blobTrackerPort.UpdateBin(bin);
            }
            else
            {
                _blobTrackerPort.InsertBin(bin);
            }
            _ready = false;
        }