How to make a copy of an Kinect Skeleton object to another Kinect Skeleton object

五迷三道 提交于 2019-12-11 05:53:07

问题


I am using the Kinect Toolbox, so I have a list of ReplaySkeletonFrames in my hand. I am iterating over this list, getting the first tracked skeleton and modifying some properties.

As we know, when we change an object we also change the original object.

I need to make a copy of an skeleton.

Note: I can't use CopySkeletonDataTo() because my frame is a ReplaySkeletonFrame and not the ReplayFrame of the "normal" Kinect.

I tried to make my own method that copies property by property, but some properties could not be copied. look...

 public static Skeleton Clone(this Skeleton actualSkeleton)
    {
        if (actualSkeleton != null)
        {
            Skeleton newOne = new Skeleton();

 // doesn't work - The property or indexer 'Microsoft.Kinect.SkeletonJoints'
 // cannot be used in this context because the set accessor is inaccessible
            newOne.Joints = actualSkeleton.Joints;

 // doesn't work - The property or indexer 'Microsoft.Kinect.SkeletonJoints' 
 // cannot be used in this context because the set accessor is inaccessible
            JointCollection jc = new JointCollection();
            jc = actualSkeleton.Joints;
            newOne.Joints = jc;

            //...

        }

        return newOne;

    }

How to solve it?


回答1:


with more search i ended up whit the following solution: Serialize the skeleton to the memory, deserialize to a new object

Here is the code

 public static Skeleton Clone(this Skeleton skOrigin)
    {
        // isso serializa o skeleton para a memoria e recupera novamente, fazendo uma cópia do objeto
        MemoryStream ms = new MemoryStream();
        BinaryFormatter bf = new BinaryFormatter();

        bf.Serialize(ms, skOrigin);

        ms.Position = 0;
        object obj = bf.Deserialize(ms);
        ms.Close();

        return obj as Skeleton;
    }


来源:https://stackoverflow.com/questions/13556910/how-to-make-a-copy-of-an-kinect-skeleton-object-to-another-kinect-skeleton-objec

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