Exception understood on update Kinect Joint positions

为君一笑 提交于 2019-12-24 11:09:30

问题


I am doing a very simple stuff, my goal is to move one skeleton based on the position of the other skeleton, for this i am based myself on a HipCenter position. (This algoritm could be wrong, this question is about a exception ocurring in the foreach loop)

Here is my actual code:

public static Skeleton MoveTo(this Skeleton skOrigin, Skeleton skDestiny)
{
     Skeleton skReturn = skOrigin; // just making a copy

        // find the factor to move, based on the HipCenter.
        float whatToMultiplyX = skOrigin.Joints[JointType.HipCenter].Position.X / skDestiny.Joints[JointType.HipCenter].Position.X;
        float whatToMultiplyY = skOrigin.Joints[JointType.HipCenter].Position.Y / skDestiny.Joints[JointType.HipCenter].Position.Y;
        float whatToMultiplyZ = skOrigin.Joints[JointType.HipCenter].Position.Z / skDestiny.Joints[JointType.HipCenter].Position.Z;


        SkeletonPoint movedPosition = new SkeletonPoint();
        Joint movedJoint = new Joint();
        foreach (JointType item in Enum.GetValues(typeof(JointType)))
        {
            // Updating the position
            movedPosition.X = skOrigin.Joints[item].Position.X * whatToMultiplyX;
            movedPosition.Y = skOrigin.Joints[item].Position.Y * whatToMultiplyY;
            movedPosition.Z = skOrigin.Joints[item].Position.Z * whatToMultiplyZ;

            // Setting the updated position to the skeleton that will be returned.
            movedJoint.Position = movedPosition;
            skReturn.Joints[item] = movedJoint;
        }

        return skReturn;
    }

Using F10 to debug everything works fine ultin the second pass in te foreach loop. When i am passing for the second time in the foreach i get a exception on this line

skReturn.Joints[item] = movedJoint;

The exception says:

JointType index value must match Joint.JointType 

But the value is actualy the Spine.

Whats wrong?


回答1:


Solved, here is the solution

 Joint newJoint = new Joint(); // declare a new Joint

// Iterate in the 20 Joints
foreach (JointType item in Enum.GetValues(typeof(JointType)))
{
    newJoint = skToBeMoved.Joints[item];

            // applying the new values to the joint
            SkeletonPoint pos = new SkeletonPoint()
            {
                X = (float)(newJoint.Position.X + (someNumber)),
                Y = (float)(newJoint.Position.Y + (someNumber)),
                Z = (float)(newJoint.Position.Z + (someNumber))
            };

            newJoint.Position = pos;
            skToBeChanged.Joints[item] = newJoint;
        }

This will work.



来源:https://stackoverflow.com/questions/13544978/exception-understood-on-update-kinect-joint-positions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!