AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Circular Bloc Recognition

The forum is to discuss topics related to different areas of image processing and computer vision.

Circular Bloc Recognition

Postby mrtrombone » Wed Mar 04, 2009 12:31 am

Hi,

I'm currently working on a project that involves tracking a laser pointer dot on a background. Due to lighting issues, I've implementation detection based on both brightness as well as colour of the dot. My goal is to be able to use the laser dot as the input for mouse cursor control, but the problem right now is that, since the laser is not contained in a single pixel, the pixel that passes the detection requirement can basically be any pixel within the laser. (Actually since the laser dot's center is percieved as white by the webcam, the detected point is generally on the reddish perimeter). This is a problem because when mapping the laser input to the mouse cursor, it makes the cursor very jumpy and unsteady. So I'm currently looking for a way to stabilize this. My idea is that perhaps using some algorithm, I can make out the circular object/blob that the detected point belongs to, and determine the blob's centroid and use that point as my cursor location. Is this possible with AForge.Net?

Thanks,
Andy
mrtrombone
 
Posts: 4
Joined: Wed Mar 04, 2009 12:24 am

Re: Circular Bloc Recognition

Postby andrew.kirillov » Wed Mar 04, 2009 6:57 am

Hello,

mrtrombone wrote:Actually since the laser dot's center is percieved as white by the webcam, the detected point is generally on the reddish perimeter

Are these pixel connected? I mean are they connected into circle? If so, then you may get the object with BlobCounter class, for example. When you get object's rectangle, then it easy to calculate its center. Of course it will not work if these pixels on the perimeter are disconnected - you will just get several objects instead of one. In this case you may try calculating mean X and Y values for all detected red pixels, which look like laser pointer (you may remove standalone noise with erosion before). This should work well if there is only one such spot, which should be the case if you use laser pointer over dedicated solid background.

P.S. A sample image usually may help a lot in such cases.

By the way, you may take a look at Laser Gesture Recognition article, which also was done using AForge.NET Framework's features. It does not control mouse pointer, but ... it also uses laser pointer ;)
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3436
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Circular Bloc Recognition

Postby mrtrombone » Thu Mar 05, 2009 4:42 am

Hi Andrew,

Thanks for the super fast response! :D

I'm pretty sure the red pixels are connected, or at least they look like they are. (I've attached a picture this time). I tried using the BlobCounter class method you mentioned, but having some troubles. The method is only getting 1 blob/rectangle, which is the whole screen/image. I'm not sure if I'm doing this wrong but here's my code...

Code: Select all
        //Finds the laser dot blob
        private Rectangle laserBlobFind(Bitmap image, int xPos, int yPos)
        {
            //System.Console.WriteLine("Looking for blob.");
            Rectangle laserBlob = new Rectangle(0, 0, 0, 0);

            Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap grayImage = filter.Apply(image);

            BlobCounter bc = new BlobCounter();
            bc.ProcessImage(grayImage);
            Rectangle[] rects = bc.GetObjectRectangles();

            //System.Console.WriteLine("{0} rectangles", rects.GetLength(0));

            foreach (Rectangle rect in rects)
            {
                if (rect.Contains(xPos, yPos))
                {
                    //System.Console.WriteLine("Found laser blob");
                    laserBlob = rect;
                }
            }

            //System.Console.WriteLine("Returning from find blob");
            return laserBlob;
        }


the arguments passed in are the original captured image (ie. the image I've attached), and the X,Y coordinates of the detected red spot. also have a few debug lines in that code...

Regarding to the Laser Gesture Recognition article, I'm actually basing my project off that one but trying to improve the laser detection/tracking a little bit more. ;)

Thanks for your help!

Andy
Attachments
laserdot.JPG
picture of laser dot captured by webcam
laserdot.JPG (9.96 KiB) Viewed 10270 times
mrtrombone
 
Posts: 4
Joined: Wed Mar 04, 2009 12:24 am

Re: Circular Bloc Recognition

Postby andrew.kirillov » Thu Mar 05, 2009 7:00 am

Hello,

mrtrombone wrote:The method is only getting 1 blob/rectangle, which is the whole screen/image.

You just need to check documentation for BlobCounter more carefully ... It said there: "The algorithm treats all black pixels as background, but not an object. This means that all objects, which could be located be the algorithm, should have other than black color." So, to get some results, you need to Threshold image before ...

But, you may need to go a bit different way ... You may try one of color filters, which may allow you to keep only the color of interest (red, for example). After filtering colors, you may go to grayscaling and blob counting.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3436
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Circular Bloc Recognition

Postby mrtrombone » Thu Mar 05, 2009 8:22 am

Hi Andrew,

Sorry, didn't read the document carefully enough. =P

Anyways, got the tracking to work...but still jumpy. I'm guessing it's cuz the laser dot image captured is slightly different in each frame and that since the ratio of the computer screen to the captured background is fairly big, any minute movement in the centroid of the laser dot would result in noticeable movement of the mouse cursor.....=/

I'll try and look into that a bit more. (Welcoming any suggestions or ideas of course!)
Thanks for your help again! :D

Andy
mrtrombone
 
Posts: 4
Joined: Wed Mar 04, 2009 12:24 am




Return to Image Processing and Computer Vision