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";
}