none
Is it possible to make a deep copy of BodyFrame? RRS feed

  • Question

  • Hello,

    I'm trying to make an array of BodyFrame, I initialized the array:

    BodyFrame[] bFrameBuffer = new BodyFrame[10];

    in multiSourceFrameArrived Event i wrote these lines of code:

    using ( var bFrame = msf.BodyFrameReference.AcquireFrame()) { if(bFrame!= null){ bFrameBuffer[i] = bFrame; i= (i+1)%10; }

    }

     

    Everytime bFrame object is disposed because of the using statement, I lose the object that I saved in the array. I suppose this is because the bFrame is copied by reference. It is possible to make deep copy of the bFrame in the array, so I don't lose every element in the array every time the Bframe is disposed?

    Thanks,

    Martino.





    Thursday, June 25, 2015 4:57 PM

Answers

  • Hi Martino,

    The BodyFrame class provides a GetAndRefreshBodyData (http://msdn.microsoft.com/en-us/library/windowspreview.kinect.bodyframe.getandrefreshbodydata.aspx) method that will copy the skeleton data for each player. To persist it in your array, you might consider doing something like the following:

    1. Create a wrapper class for the Body data containing
      Vector4 FloorClipPlane (from BodyFrame.FloorClipPlane)
      TimeSpan RelativeTime (from BodyFrame.RelativeTime)
      IList<Body> Bodies (from BodyFrame.GetAndRefreshBodyData)
    2. When you get a new BodyFrame, create a new instance of your type and copy the relevant data
    3. Release the BodyFrame (it shouldn't be needed any longer)

    BodyFrame.BodyCount will be a constant value (it reports the number of users supported by Kinect). If BodyFrame.BodyFrameSource is needed for your application, you may need to add it to the custom class (take care to track the lifespan of the source).

    Hope this helps,

    David

    Friday, June 26, 2015 10:02 PM
    Moderator