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

I use the Kinect Toolbox, so I have a list ReplaySkeletonFramesin my hand. I repeat this list, getting the first tracked skeleton and changing some properties.

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

I need to make a copy of the skeleton.

Note. I can’t use CopySkeletonDataTo()it because my frame ReplaySkeletonFrame, not the ReplayFrame“normal” Kinect.

I tried to create my own method that copies a property by property, but some properties cannot 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
source share
1 answer

: ,

 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;
    }
+1

All Articles