1

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(xCentroTelaand 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.

2
  • I'm confused when you say "the mouse should keep moving". Do you really want to the mouse to continue to move when the head has stopped? If not, it should be a matter of normalizing the output to the screen resolution. Nov 26, 2012 at 17:02
  • @EvilClosetMonkey Yes. Here's what happening. The kinect tracks the exact point location on my face and move the mouse to that location. But this covers a really small area of the screen. What i want is that the kinect tracks the direction where the point in my face is pointing and moves the mouse to that direction until i move my head to the inicial position. When i do this, the mouse stop moving. Did it make any sense?
    – Boga
    Nov 26, 2012 at 19:56

1 Answer 1

2

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.

2
  • Hey! Yeah, that's what i have in mind, but having a lot of trouble trying to implement it. I've already managed to determine a central point in the screen (with xBaseand yBase). With my code i can track the exact position of the point in the users face and display it on the screen, but i still can't find a way of how take this point and move it to the direction it's pointing.
    – Boga
    Nov 29, 2012 at 8:26
  • Brasileiro na área :) I will test your code and post more sugestions.
    – Ewerton
    Nov 30, 2012 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.