none
Save position of right hand as "home"-position RRS feed

  • Question

  • When the Kinect has tracked my right hand (JointType.HandRight), I want it to save the current position of the hand as a "home"-position which later can be referred to when for example my right hand moves to the right from the "home"-position. I'm a novice in programming and would highly appreciate code for show and an explanation (and note if there's anything in the existing code that's wrong or missing)! Thanks!

            // Find the right hand joint
            IList<Microsoft.Kinect.Body> bodies;
            void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
            {
                var reference = e.FrameReference.AcquireFrame();
                using (var frame = reference.BodyFrameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        bodies = new Microsoft.Kinect.Body[frame.BodyFrameSource.BodyCount];
    
                        frame.GetAndRefreshBodyData(bodies);
    
                        foreach (var body in bodies)
                        {
                            if (body != null)
                            {
                                if (body.IsTracked)
                                {
                                    // Find the joint
                                    Joint handRight = body.Joints[Microsoft.Kinect.JointType.HandRight];
    
                                    // Around here maybe having the code which saves the current position as "home"
    
                                }
                            }
                        }
                    }
                }
            }


    Monday, April 13, 2015 9:39 AM

All replies

  • You can just create a variable for storing that info:

    IList<Microsoft.Kinect.Body> bodies;
    Joint homeRightHandPosition;
    void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
    {
    //...
    if(body.IsTracked)
    {
    homeRightHandPosition = body.Joints[JointType.HandRight];
    }
    //...
    }
    
    This was a "simple answer", information storage in apps depends a little on how you are planning to use that info later.

    Monday, April 13, 2015 11:54 AM
  • I am planning to use that information to later refer it to if my right hand moves from the home position. It will be used for the control of an robotic arm as when I move my right hand to the right from the home position, the robot will move to the right from its own home position.

    Do you know how I can make the sensor respond when I move my hand in different directions? As if I move my hand to the right it will respond?

    Tuesday, April 14, 2015 8:57 AM
  • You don't want the sensor to respond, but the robot. You are already in the right place where the Kinect will tell you the right hand position, but you will need to decide how "home position" is set, i.e. when the app will consider current position as home position. Then you could compute for each body frame, what is the position vector from the home point and make your robot move depending on than vector.

    Did you watched the jump start videos? I think they're very helpful to getting into Kinect development.

    Also, do you really need a multisource frame reader? From what you are describing, I would say that only a body frame reader is needed.

    Tuesday, April 14, 2015 2:01 PM
  • I could make an IF code line where if I close my hand, the kinect will respond to that action as saving that position as "home" and while I have my hand closed the robot will respond when I move my hand from that positioned home. How do I perform what you said in the following: "Then you could compute for each body frame, what is the position vector from the home point and make your robot move depending on than vector"? I suppose you'r talking about making the work space in x, y, z work as the robot will perform the same movement as my hand? I'm right now a little of a novice in programming as I've gotten a little rusty while I haven't programmed that much during the years. I've checked the Kinect v2 documentation but I don't know what information nor code I could use.

    I have watched the jump start videos and they gave me a better understanding in the kinect but didn'tfeel that they were helpful for the coding and for my specific work, but I could be wrong.

    Once again I've haven't got a good understanding of the differences yet so if you say body frame is enough you'r probably right, could you tell me the differences? And do I change thus only the multisource for the body frame in the code?

    Thank you for the help and sorry for my late response!

    Thursday, April 16, 2015 7:05 AM
  • Try to browse the API docs a little. In-line help in Visual Studio is also useful to get to know what's inside an object.

    Here is the basic class list. If you look at Body class, you see it contains a dictionary of Joints. You can search that dictionary with the list in JointType and you get a Joint object. That's what you are doing with the line

    body.Joints[JointType.HandRight]

    If you look at the Joint class, you find you can get the position for that joint and that each position has X, Y, Z coordinates. For example if you wanted to calculate the distance between both hands (I know that's not what you want, it's an example for the sake of simplicity) you could do:

    //Get the positions
    pRH = body.Joints[JointType.HandRight].Position;
    pLH = body.Joints[JointType.HandLeft].Position;
    //Some maths
    sqDistance = Math.Pow(pRH.X-pLH.X, 2) + Math.Pow(pRH.Y-pLH.Y, 2) + Math.Pow(pRH.Z-pLH.Z, 2);
    distance = Math.Sqrt(sqDistance);

    Think also that the Kinect programming model you choose is based on C# (and WPF or Windows Store apps). When asking in the forum, some previous knowledge about these technologies is assumed. If you are not familiar with this kind of framework, maybe it will be a good idea to learn a little of C# before working with the Kinect API.


    Friday, April 17, 2015 8:37 AM