Click here to Skip to main content
15,896,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone I'm done with tracking multiple objects based on color
but I want to fill the distance between its previous x,y and its current position but i don't know to do it


****I'm a beginner and learning so don't make fun of my code

What I have tried:

public void findObject(Bitmap image)
        {
            //BlobCounter blobCounter = new BlobCounter();
            blobCounter.MinWidth = blobCounter.MinHeight = 10;
            blobCounter.MaxWidth = blobCounter.MaxHeight = 40;
            blobCounter.FilterBlobs = true;
            blobCounter.ObjectsOrder = ObjectsOrder.XY;
            objectsData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, image.PixelFormat);

            //Grayscale grayScaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            grayScaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage = grayScaleFilter.Apply(new UnmanagedImage(objectsData));
            image.UnlockBits(objectsData);


            blobCounter.ProcessImage(image);
            //Rectangle[] rects = blobCounter.GetObjectsRectangles();
            rects = blobCounter.GetObjectsRectangles();

            Blob[] blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;
            PointF inp = new PointF(ix, iy);



            for (int i = 0; i < rects.Length; i++)
            {
                Rectangle objectRectangle = rects[i];
                objCount = i;

                Graphics g = pictureBox1.CreateGraphics();
                Graphics f = pictureBox1.CreateGraphics();
                Graphics s = pictureBox1.CreateGraphics();

                int objectX = objectRectangle.X;
                int objectY = objectRectangle.Y;

                ix = objectX;
                iy = objectY;

                objectsXY[i, 0] = objectX;
                objectsXY[i, 1] = objectY;

                Pen penx = new Pen(Color.Red);
                System.Drawing.Point[] points =
                    {
                    new System.Drawing.Point(objectX,objectY),
                    new System.Drawing.Point(objectsXY[i,0],objectsXY[i, 1]),


                };

              

                using (Pen pen = new Pen(Color.FromArgb(2, 227, 252), 2))
                {
                    g.DrawRectangle(pen, objectRectangle);
                    g.DrawString((i + 1).ToString(), new Font("Arial", 15), Brushes.Yellow, objectRectangle);
                    f.FillEllipse(Brushes.Black, objectRectangle.X, objectRectangle.Y, 5, 5);
                 //   s.DrawLine(Brushes.Red , PointF )
                }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900