Track by color with kinect and c#

678 Views Asked by At

I have a problem with my latest project, I'm new to kinect and my programming skills are not excellent. I need my program to detect my stick (by color), so I can make a lasergun (red line comming out of the stick on my computer) with it. I'm having a lot of troubles with this color tracking. This far I have the following code:

private void zoekGekleurdeStok(Image<Bgr, Byte> openCVImg)
    {
        pxLock img = new pxLock();

        Bitmap b = BitmapFromWriteableBitmap(colorBitmap);
        DataTable pxLocation = img.GetPixelLocation(b, c);


        if (pxLocation.Rows.Count <= 0) { return; }
        //Setup Rectangle
        int boxWidth = 20;
        int boxHeight = 20;
        //Get Pixel Position
        int iX = Convert.ToInt32(pxLocation.Rows[0]["Column"]);
        int iY = Convert.ToInt32(pxLocation.Rows[0]["Row"]);

        //Configure Rectangle
        //System.Drawing.Rectangle rect = new Rectangle(iX, iY, boxWidth, boxHeight);
        System.Drawing.Rectangle rect = new System.Drawing.Rectangle(iX, iY, boxWidth, boxHeight);
        //Configure Pen Style
        System.Drawing.Pen RedPen = new System.Drawing.Pen(System.Drawing.Color.Red, 2);
        RedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
        //Draw Rectangle
        //e.Graphics.DrawRectangle(RedPen, rect); /  /e.Graphics.FillRectangle(Brushes.Red, rect);

        System.Drawing.Point p3 = new System.Drawing.Point();
        p3.X = iX;
        p3.Y = iY;


        System.Drawing.Point p4 = new System.Drawing.Point();

        p4.X = iX + 30;
        p4.Y = iY + 30;
        LineSegment2D line = new LineSegment2D();
        line.P1 = p3;
        line.P2 = p4;


        openCVImg.Draw(line, new Bgr(System.Drawing.Color.Red), 5);
    }

But I believe that it takes to long to fill in my pxLocation, and the sub is called time after time. After days of not producing any good code I'm thinking I should switch to a different language or programma?

Perhaps anybody here, has experience with this. I just want to make a simple color tracking program with my kinect.

I hope you guys understand my explenation, my English isn't very well. I'm sorry for that.

Thanks in advance.

0

There are 0 best solutions below