2012-11-25 5 views
1

Kinect 도구 상자를 사용 중이므로 ReplaySkeletonFrames의 목록이 있습니다. 이 목록에서 처음으로 추적되는 뼈대를 가져 와서 일부 속성을 수정합니다.Kinect 해골 개체를 다른 Kinect 해골 개체로 복사하는 방법

우리가 알고있는 것처럼 우리가 객체를 변경하면 원래 객체도 변경됩니다.

해골 사본을 만들어야합니다.

참고 : 내 프레임이 ReplaySkeletonFrame이고 "일반"Kinect가 ReplayFrame이 아니기 때문에 CopySkeletonDataTo()을 사용할 수 없습니다.

속성별로 속성을 복사하는 자체 메서드를 만들려고했지만 일부 속성을 복사 할 수 없습니다. 봐 ...

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

내가 다음과 같은 솔루션은 오순절 결국이 문제를 조사하는 동안 새로운 객체 여기

에 직렬화, 메모리에 대한 골격을 직렬화 코드

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

은 이전에 내가 가로 질러 아래 링크를 보았지만'Skeleton'이 아직 직렬화 가능하면 발견하지 못했습니다. 이것은 기본적으로 똑같은 일을하지만 더 일반적인 방법으로 그렇게하므로 '해골'객체를 확장 할 필요가 없으며 반복해서 사용할 수 있습니다. http://stackoverflow.com/questions/78536/cloning-objects-in-c-sharp –

+0

멋지다, 나는이 기술을 몰랐다. – Ewerton