简体   繁体   English

指向某处时继续移动鼠标光标

[英]Keep moving mouse cursor while pointing somewhere

So, i'm trying to create a Kinect application where the mouse is controlled by the movements of the head.所以,我正在尝试创建一个 Kinect 应用程序,其中鼠标由头部的运动控制。

        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.根据 Kinect 跟踪的面部给定点的确切位置,我设法控制了它,但是如果有人坐着,这会将鼠标的移动限制在一个非常小的区域内。 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 ).更新 #2现在我已经设法跟踪屏幕的xCentroTelaxCentroTelayCentroTela )并确定该点的第一个跟踪位置( xInicialyInicial )。 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.但是仍然无法将鼠标指向面部指向的方向,即使使用屏幕中心点这样的比较。

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.如果用户将你的头向右移动一点,你什么nothing做,但如果他再移动一点,你开始向右移动鼠标并加速它(将位移乘以一个因子),然后只停止如果用户将头部转向原始位置。 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.请记住移动光标的区域,使光标保持在中心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM