如何将Kinect Skeleton对象的副本复制到另一个Kinect Skeleton对象

时间:2012-11-25 23:55:54

标签: kinect kinect-sdk kinect.toolbox

我正在使用Kinect工具箱,因此我手中有一个ReplaySkeletonFrames列表。 我正在迭代这个列表,得到第一个跟踪骨架并修改一些属性。

众所周知,当我们更改对象时,我们也会更改原始对象。

我需要复制骨架。

注意:我无法使用CopySkeletonDataTo(),因为我的框架是ReplaySkeletonFrame,而不是“普通”Kinect的ReplayFrame

我尝试创建自己的属性复制属性的方法,但无法复制某些属性。看...

 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;

    }

如何解决?

1 个答案:

答案 0 :(得分:1)

通过更多搜索我得到了以下解决方案:将骨架序列化到内存中,反序列化为新对象

这是代码

 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;
    }
相关问题