AForge.NET

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

how to control mouse cursor with color tracking using Aforge

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

how to control mouse cursor with color tracking using Aforge

Postby mrvturan96 » Sun Jan 28, 2018 12:48 pm

Hi,
I want to move the mouse cursor according to the color of the object. I could object tracking but I could not control the Mouse. How can I do this?
Code: Select all
public void nesnebul(Bitmap image)
        {

            BlobCounter blobCounter = new BlobCounter();
            blobCounter.MinWidth = 5;
            blobCounter.MinHeight = 5;
            blobCounter.FilterBlobs = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;

            BitmapData objectsData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
            Grayscale 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();
            Blob[] blobs = blobCounter.GetObjectsInformation();
            islemBox.Image = image;



            foreach (Rectangle recs in rects)
            {

                if (rects.Length > 0)
                {
                    Rectangle objectRect = rects[0];

                    Graphics g = kaynakBox.CreateGraphics();
                    using (Pen pen = new Pen(Color.FromArgb(250, 0, 0), 2))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }

                    int objectX = objectRect.X + (objectRect.Width / 2);
                    int objectY = objectRect.Y + (objectRect.Height / 2);


                    this.Cursor  = new Cursor(Cursor.Current.Handle);
                    Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50);

                    int xX = cu.posX(kaynakBox.Width, objectRect.X, objectRect.Width);
                    int yY = cu.posY(kaynakBox.Height, objectRect.Y, objectRect.Height);


                    String area = "";

                    if (objectX < 108 && objectY < 90)
                    {
                        area = "1.Bölge";
                       

                    }
                    else if ((objectX > 108 && objectX < 212) && (objectY < 90))
                    {
                        area = "2.Bölge";
                       
                    }
                    else if ((objectX > 212 && objectX < 360) && (objectY < 90))
                    {
                        area = "3.Bölge";
                       

                    }
mrvturan96
 
Posts: 2
Joined: Wed Jan 24, 2018 7:55 pm

Re: how to control mouse cursor with color tracking using Af

Postby andrew.kirillov » Sun Jan 28, 2018 9:57 pm

Hello,

AForge.NET Framework provides image processing tools to detect objects of certain colors. This is what you already did. However, AForge.NET Framework was never targeted to controlling mouse cursors - it is out of scope for the framework. So you may need to google for the solution.

Ask an image processing question, if you have one. This was the aim of the discussion board.
With best regards,
Andrew


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




Return to Image Processing and Computer Vision

cron