Question

I am doing a project where I have to develop an application in which the mouse cursor moves according to the co-ordinates provided to it.These co-ordinates are generated from the position of user's pupil.I am able to get the co-ordinates of the pupil using opencv.Now,I have the following questions:

1.)How do I programme the mouse cursor,so that it moves according to the co-ordinates I give it.Specifically,I am looking for libraries and functions that will do it.After looking online I found out that people use graphics.h library with turbo C.I am doing my project in visual studio 2010,so please let me know of any method that goes with it.

2.)Secondly,how can I use this so-called mouse I have created with C++ and opencv to function as the primary mouse in windows?Do I have to do assembly level programming or device driver writing or is there any other suitable method?

For Q1. I would highly appreciate if you could give me some sample code.

Thanks.

............................ This is what I have done so far .............................. I am having problems with running code.I have integrated WinBGIm v6.0 from http://winbgim.codecutter.org/ (I am using VS2010 ultimate on Windows 7). If I run the sample code everything goes fine.However, when I tried to run this mouse example given in the documentation several errors occurred. Please help me correct the errors, I have no idea what they mean.

/* mouse example */
/*Filename:mint.cpp*/
    #include "winbgim.h"
    void main(void)
    {
    const int LIMIT = 10; // Number of clicks to stop program.
    int maxx, maxy; // Maximum x and y pixel coordinates
    int count = 0; // Number of mouse clicks
    int divisor; // Divisor for the length of a triangle side
    // Put the machine into graphics mode and get the maximum
    coordinates:
    initwindow(450, 300);
    maxx = getmaxx( );
    maxy = getmaxy( );
    // Draw a white circle with red inside and a radius of 50 pixels:
    setfillstyle(SOLID_FILL, RED);
    setcolor(WHITE);
    fillellipse(maxx/2, maxy/2, 50, 50);
    // Print a message and wait for a red pixel to be double clicked:
    settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
    outtextxy(20, 20, "Left click " << LIMIT << " times to end.");
    setcolor(BLUE);
    divisor = 2;
    while (count < LIMIT)
    {
    triangle(maxx/divisor, maxy/divisor);
    delay(500);
    divisor++;
    if (ismouseclick(WM_LBUTTONDOWN))
    {
    (clearmouseclick(WM_LBUTTONDOWN));
    count++;
    }
    }
    // Switch back to text mode:
    closegraph( );
    }
...................................................
The compiler errors are:

c:\program files\microsoft visual studio 10.0\vc\include\winbgim.h(302): error C2086: 'int right' : redefinition
1>c:\program files\microsoft visual studio 10.0\vc\include\winbgim.h(302) : see declaration of 'right'
1>c:\users\administrator\desktop\winbgm\driver\mint.cpp(20): error C2296: '<<' : illegal, left operand has type 'const char [12]'
1>c:\users\administrator\desktop\winbgm\driver\mint.cpp(25): error C3861: 'triangle': identifier not found
Build FAILED.
Was it helpful?

Solution

  1. You can use a port of BGI library for Windows (WinBGIm). Here's a link to a general idea of how to do it (sample project in VS2010).
    Project: http://muhammadallee.pbworks.com/w/file/53399106/WinBGIm-Demo.zip (You would need to go to Project Properties->Linker->Input and correct the path of the lib file there. Alternatively, use this project: http://www.cs.colorado.edu/~main/bgi/visual/BGI2010.zip Documentation:
    http://www.cs.colorado.edu/~main/bgi/doc/

  2. It will use the Windows standard mouse. So you don't have to worry about it. You can simply set the coordinates of the mouse via SetMousePos() that you are using the set the coordinates of your own mouse.

Your code contains errors

Instead of

outtextxy(20, 20, "Left click " LIMIT << " times to end.");

Use this code

char msg[80] = "";
sprintf(msg, "Left click %d times to end.", LIMIT);

And comment out

triangle(maxx/divisor, maxy/divisor);

Also, download from the links that I have mentioned. After these changes, it ran fine.

PS: If it solves your problem, you can mark this as answer :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top