如何将Kinect骨架对象复制到另一个Kinect骨架对象 [英] How to make a copy of an Kinect Skeleton object to another Kinect Skeleton object

查看:142
本文介绍了如何将Kinect骨架对象复制到另一个Kinect骨架对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Kinect工具箱,所以我手边有一个ReplaySkeletonFrames列表. 我正在遍历此列表,获取了第一个跟踪的骨架并修改了一些属性.

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.

我需要复制一个骨架.

注意:我不能使用CopySkeletonDataTo(),因为我的镜架是ReplaySkeletonFrame而不是普通" Kinect的ReplayFrame.

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;

    }

如何解决?

推荐答案

我进行了更多搜索,最终得到了以下解决方案:将框架序列化到内存,反序列化到新对象

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

这是代码

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

这篇关于如何将Kinect骨架对象复制到另一个Kinect骨架对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆