Reputation: 371
So, i'm trying to create a Kinect application where the mouse is controlled by the movements of the head.
if (faceFrame.TrackSuccessful)
{
var xBase = System.Windows.Forms.Screen.AllScreens[0].Bounds.Width;
var yBase = System.Windows.Forms.Screen.AllScreens[0].Bounds.Height;
var xCentroTela = xBase / 2;
var yCentroTela = yBase / 2;
var xInicial = Convert.ToInt32(pontosFace[41].X);
var yInicial = Convert.ToInt32(pontosFace[41].Y);
if (flagPosicao == 0)
{
SetCursorPos(xCentroTela, yCentroTela);
flagPosicao = 1;
}
//Works
int topofscreen = ((100 * yBase) * yInicial) / (50 * yCentroTela);
int leftofscreen = ((100 * xBase) * xInicial) / (50 * xCentroTela);
leftofscreen = leftofscreen - xCentroTela;
topofscreen = topofscreen - yCentroTela;
SetCursorPos(leftofscreen, topofscreen);
Thread.Sleep(1);
txty.Text = Convert.ToString(topofscreen);
txtx.Text = Convert.ToString(leftofscreen);
}
I've managed to control it, according to exact position of a given point in the face tracked by the Kinect, but this limits the movement of the mouse into a really small area if the person is seated. This only works if the persons keeps moving his head all around a room.
My question is: Is there a way to set the position of the mouse cursor dynamically? In other words, i don't want to set it to my exact position. I want to set it to where the tracked point is pointing. For example, if i move my head to the upper-left and stop, the mouse should keep moving in that direction.
Or is there a way to increase the tracked point range to larger area?
UPDATED I've updated the code with some improvements. Now, at i'm setting up the mouse cursor to the center of the screen and getting the initial tracked points of the face. Now i'm trying to discover where to go from there.
UPDATE #2
Now i've managed to track the central point of the screen(xCentroTela
and yCentroTela
) and determined the first tracked position of the point (xInicial
and yInicial
).
With that i have set the first tracked position as the center of the screen and trying to go from there. But still having trouble of how mouse to the direction the face is pointing, even using a comparison like the central point of the screen.
Upvotes: 1
Views: 782
Reputation: 4533
You could implement something like this:
If the user move your head a little bit to the right you do nothing
, but if he moves it a little bit more, you start to move the mouse to the right and acellerating it (multiplying the displacement by a factor), and stops only if the user turns the head to the original position.
In other words, you will need to consider a area around the cursor, if the user look in to this area, nothing happens, if the user step out this area, the mouse starts the movement.
Remember to move the area with the cursor keepping the cursor on the center.
Upvotes: 2