Blob与跟踪对象不匹配

时间:2016-03-28 07:42:54

标签: c# image-processing blob tracking aforge

enter image description here

我需要使用颜色跟踪。 当我在surface pro 4中运行代码时,blob与我的目标对象不匹配。 但是当我在Acer上测试时,代码是正确的。 有谁知道为什么?

 public void forobject(Bitmap image)//put setted color value into image1
        {
            BlobCounter blobCounter = new BlobCounter();
            blobCounter.MinWidth = 5;
            blobCounter.MinHeight = 5;
            blobCounter.FilterBlobs = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            //Grayscale griFiltre = new Grayscale(0.2125, 0.7154, 0.0721);
            //Grayscale griFiltre = new Grayscale(0.2, 0.2, 0.2);
            //Bitmap griImage = griFiltre.Apply(image);

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

            // grayscaling
            Grayscale grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            // unlock image
            image.UnlockBits(objectsData);


            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[] blobs = blobCounter.GetObjectsInformation();

            pictureBox_tracking.Image = image;//????



            if (rdiobtn_singletracking.Checked)
            {
                // Single Tracking--------

                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle objectRect = rects[0];
                        //Graphics g = Graphics.FromImage(image);
                        Graphics g = pictureBox_real.CreateGraphics();
                        using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                        {
                            g.DrawRectangle(pen, objectRect);
                        }
                        //Drawn by the rectangle coordinates is taken away.
                        //int objectX = objectRect.X; //+ (objectRect.Width / 2);
                        //int objectY = objectRect.Y; //+ (objectRect.Height / 2);
                        x = objectRect.X;
                        y = objectRect.Y;
                        w = objectRect.Width;
                        h = objectRect.Height;
                        //  g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                        g.Dispose();
}

0 个答案:

没有答案