Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Serializing Kinect-Skeletons and transmitting them via MemoryMappedFiles to another process. These are just snippets and won't run without further Code.
// This process uses the data comming from the kinect processes.
// Read from the MemoryMappedFile
MemoryMappedViewAccessor accessor = memoryMappedFile.createViewAccessor();
// Read to Array
accessor.ReadArray<byte>(0, mmf_result, 0, mmf_result.Length);
// Use a local Array for further instructions
byte[] temp = new byte[mmf_result.Length];
Array.Copy(mmf_result, temp, mmf_result.Length);
// Check if the Byte Array contains only 00-Bytes
empty = temp.All(B => B == default(Byte));
// if not: attempt to create a skelton
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream(temp);
Skeleton skelNew = (Skeleton)bf.Deserialize(ms);
// This process is connected to the kinect.
// MemoryMappedFile has already been setup.
// Skeleton has already been loaded from the sensor.
Skeleton skel = this.skeletons[0];
// 1: Serialize Skeleton to Byte-Array
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, skel);
byte[] serializedSkel = ms.ToArray();
// 2: Transmit Skeleton to MemoryMappedFile
// Transmit Skeleton Data
MemoryMappedViewAccessor writer = memoryMappedFile.createViewAccessor();
writer.WriteArray<byte>(0, serializedSkel, 0, serializedSkel.Length);
// If no Skeleton is available transmit an empty byte-array.
// Otherwise the last Skeleton will remain in the memory-mapped file forever.
byte[] empty = new byte[1] { 0 };
writer.WriteArray<byte>(0, empty, 0, empty.Length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.