none
how to control cursor with left hand RRS feed

  • Question

  • I actually want to use the left hand to control the cursor, thus i used the mouse simulater library but the method provided by it needs an integer but the skeletal joint provide a float for its x & y coordinate

    currently im using this:

    MouseSimulator.X = (int)skeleton.Joints[JointID.HandLeft].Position.X;

     MouseSimulator.Y = (int)skeleton.Joints[JointID.HandLeft].Position.Y;

    how do i control the cursor with this Joints method??

    irfan,

     

     

     

    Friday, October 28, 2011 8:20 AM

Answers

  • irfan, the range of X-Y positions for a kinect skeleton joint is rounghly -2.0 to 2.0 (coordinate space is in meters, as described in page 23 of programming guide (http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/docs/ProgrammingGuide_KinectSDK.pdf), so under that method you would only see at most a 4 pixel movement with the code you have. You need to scale your coordinate values from skeleton space into your mouse coordinate space using some kind of coordinate mapping. Since this is just a 2D coordinate mapping without rotation, it's simple and you can do something like:

    MouseSimulator.X = (screenWidth*((int)skeleton.Joints[JointID.HandLeft].Position.X + 2.0)/4.0) + (screenWidth/2);
    MouseSimulator.Y = (screenHeight*((int)skeleton.Joints[JointID.HandLeft].Position.Y + 2.0)/4.0) + (screenHeight/2);

    Where screenWidth and screenHeight are variables you previously initialized to have screen dimensions.
    Of course, the code I pasted might not necessarily result in the best experience, and you'll have to play around with the scaling values and calibrate appropriately.

    Eddy


    I'm here to help
    Tuesday, November 1, 2011 2:42 AM

All replies

  • irfan, the range of X-Y positions for a kinect skeleton joint is rounghly -2.0 to 2.0 (coordinate space is in meters, as described in page 23 of programming guide (http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/docs/ProgrammingGuide_KinectSDK.pdf), so under that method you would only see at most a 4 pixel movement with the code you have. You need to scale your coordinate values from skeleton space into your mouse coordinate space using some kind of coordinate mapping. Since this is just a 2D coordinate mapping without rotation, it's simple and you can do something like:

    MouseSimulator.X = (screenWidth*((int)skeleton.Joints[JointID.HandLeft].Position.X + 2.0)/4.0) + (screenWidth/2);
    MouseSimulator.Y = (screenHeight*((int)skeleton.Joints[JointID.HandLeft].Position.Y + 2.0)/4.0) + (screenHeight/2);

    Where screenWidth and screenHeight are variables you previously initialized to have screen dimensions.
    Of course, the code I pasted might not necessarily result in the best experience, and you'll have to play around with the scaling values and calibrate appropriately.

    Eddy


    I'm here to help
    Tuesday, November 1, 2011 2:42 AM
  • Another way to do this is using the Coding4Fun Kinect library :

    http://c4fkinect.codeplex.com/

    It has a method to scale the joints position to screen position.

    Skeleton Data Extension Methods:

    • Joint.ScaleTo(int width, int height)
      • Scales a Joint's Position to the maximum width and height specified
    • Joint.ScaleTo(int width, int height, float maxSkeletonX, float maxSkeletonY)
      • Scales a Joint's Position to the maximum width and height specified
    • Proposed as answer by EdgarTaor Saturday, November 5, 2011 4:17 AM
    Saturday, November 5, 2011 4:16 AM