Commit a38f2b6c authored by 16이상민's avatar 16이상민

Fixed an issue that prevented importing Kinect Frame

parent ed3a1d8e
using NUnit.Framework; using NUnit.Framework;
using KinectModule;
using Windows.Kinect; using Windows.Kinect;
using KinectModule;
public class KinectAccessManagerTests public class KinectAccessManagerTests
{ {
......
using NUnit.Framework; using NUnit.Framework;
using Windows.Kinect; using Windows.Kinect;
using KinectModule;
using System.Linq; using System.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using KinectModule;
// To test the update function and the updated buffer, you need a stub for the source frame class. // To test the update function and the updated buffer, you need a stub for the source frame class.
......
...@@ -37,4 +37,4 @@ Material: ...@@ -37,4 +37,4 @@ Material:
m_Floats: m_Floats:
- _Cutoff: 0 - _Cutoff: 0
m_Colors: m_Colors:
- _Color: {r: 0, g: 1, b: 0, a: 1} - _Color: {r: 0, g: 1, b: 0, a: 0}
...@@ -187,9 +187,8 @@ GameObject: ...@@ -187,9 +187,8 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 750753103} - component: {fileID: 750753103}
- component: {fileID: 750753108} - component: {fileID: 750753108}
- component: {fileID: 750753104}
m_Layer: 5 m_Layer: 5
m_Name: tmpManagers m_Name: InGameManagers
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
...@@ -213,7 +212,7 @@ RectTransform: ...@@ -213,7 +212,7 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &750753104 --- !u!114 &750753108
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0} m_PrefabParentObject: {fileID: 0}
...@@ -221,21 +220,54 @@ MonoBehaviour: ...@@ -221,21 +220,54 @@ MonoBehaviour:
m_GameObject: {fileID: 750753102} m_GameObject: {fileID: 750753102}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a9d22e7eb4921ca47b18c68e43c0eb6e, type: 3} m_Script: {fileID: 11500000, guid: 397b5aecede4d754abd2fba781e08f97, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
defaultSound: {fileID: 0} --- !u!1 &1026530465
--- !u!114 &750753108 GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1026530467}
- component: {fileID: 1026530466}
m_Layer: 5
m_Name: GameManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1026530466
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0} m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 750753102} m_GameObject: {fileID: 1026530465}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 397b5aecede4d754abd2fba781e08f97, type: 3} m_Script: {fileID: 11500000, guid: 397b5aecede4d754abd2fba781e08f97, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!224 &1026530467
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1026530465}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &1217935565 --- !u!1 &1217935565
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -131,14 +131,14 @@ namespace KinectModule ...@@ -131,14 +131,14 @@ namespace KinectModule
public class SourceBuffer public class SourceBuffer
{ {
private byte[] _ColorBuffer = new byte [KinectConstants.ColorWidth * private byte[] _ColorBuffer = new byte[KinectConstants.ColorWidth *
KinectConstants.ColorHeight * KinectConstants.ColorHeight *
KinectConstants.ColorCount], KinectConstants.ColorCount],
_BodyIndexBuffer = new byte [KinectConstants.DepthWidth * _BodyIndexBuffer = new byte[KinectConstants.DepthWidth *
KinectConstants.DepthHeight]; KinectConstants.DepthHeight];
private ushort[] _DepthBuffer = new ushort[KinectConstants.DepthWidth * private ushort[] _DepthBuffer = new ushort[KinectConstants.DepthWidth *
KinectConstants.DepthHeight]; KinectConstants.DepthHeight];
private IBody[] _BodyBuffer = new IBody [KinectConstants.BodyCount]; private IBody[] _BodyBuffer = new IBody[KinectConstants.BodyCount];
public byte[] ColorBuffer public byte[] ColorBuffer
{ get { return _ColorBuffer; } } { get { return _ColorBuffer; } }
...@@ -326,89 +326,123 @@ namespace KinectModule ...@@ -326,89 +326,123 @@ namespace KinectModule
public RealMultiSourceFrame(MultiSourceFrame sourceFrame) public RealMultiSourceFrame(MultiSourceFrame sourceFrame)
{ {
_ColorFrame = new RealColorFrame(sourceFrame == null ? null : if (sourceFrame == null)
sourceFrame.ColorFrameReference.AcquireFrame()); {
_BodyIndexFrame = new RealBodyIndexFrame(sourceFrame == null ? null : _ColorFrame = new RealColorFrame(null);
sourceFrame.BodyIndexFrameReference.AcquireFrame()); _BodyIndexFrame = new RealBodyIndexFrame(null);
_DepthFrame = new RealDepthFrame(sourceFrame == null ? null : _DepthFrame = new RealDepthFrame(null);
sourceFrame.DepthFrameReference.AcquireFrame()); _BodyFrame = new RealBodyFrame(null);
_BodyFrame = new RealBodyFrame(sourceFrame == null ? null :
sourceFrame.BodyFrameReference.AcquireFrame()); return;
}
using (var colorFrame = sourceFrame.ColorFrameReference.AcquireFrame())
_ColorFrame = new RealColorFrame(colorFrame);
using (var bodyIndexFrame = sourceFrame.BodyIndexFrameReference.AcquireFrame())
_BodyIndexFrame = new RealBodyIndexFrame(bodyIndexFrame);
using (var depthFrame = sourceFrame.DepthFrameReference.AcquireFrame())
_DepthFrame = new RealDepthFrame(depthFrame);
using (var bodyFrame = sourceFrame.BodyFrameReference.AcquireFrame())
_BodyFrame = new RealBodyFrame(bodyFrame);
} }
private class RealColorFrame : IColorFrame private class RealColorFrame : IColorFrame
{ {
private ColorFrame _Frame; private byte[] _Buffer = new byte[KinectConstants.ColorWidth *
KinectConstants.ColorHeight *
KinectConstants.ColorCount];
private bool IsValid = false;
public RealColorFrame(ColorFrame frame) public RealColorFrame(ColorFrame frame)
{ {
_Frame = frame; if (frame != null)
{
var ColorData = GCHandle.Alloc(_Buffer, GCHandleType.Pinned);
frame.CopyConvertedFrameDataToIntPtr(ColorData.AddrOfPinnedObject(), (uint)_Buffer.Length, ColorImageFormat.Rgba);
ColorData.Free();
IsValid = true;
}
} }
public void CopyData(byte[] buffer) public void CopyData(byte[] buffer)
{ {
if (_Frame != null) if (IsValid)
{ Array.Copy(_Buffer, buffer, _Buffer.Length);
var ColorData = GCHandle.Alloc(buffer, GCHandleType.Pinned);
_Frame.CopyConvertedFrameDataToIntPtr(ColorData.AddrOfPinnedObject(), (uint)buffer.Length, ColorImageFormat.Rgba);
ColorData.Free();
}
} }
} }
private class RealBodyIndexFrame : IBodyIndexFrame private class RealBodyIndexFrame : IBodyIndexFrame
{ {
private BodyIndexFrame _Frame; private byte[] _Buffer = new byte[KinectConstants.DepthWidth *
KinectConstants.DepthHeight];
private bool IsValid = false;
public RealBodyIndexFrame(BodyIndexFrame frame) public RealBodyIndexFrame(BodyIndexFrame frame)
{ {
_Frame = frame; if (frame != null)
{
var BodyIndexData = GCHandle.Alloc(_Buffer, GCHandleType.Pinned);
frame.CopyFrameDataToIntPtr(BodyIndexData.AddrOfPinnedObject(), (uint)_Buffer.Length);
BodyIndexData.Free();
IsValid = true;
}
} }
public void CopyData(byte[] buffer) public void CopyData(byte[] buffer)
{ {
if (_Frame != null) if (IsValid)
{ Array.Copy(_Buffer, buffer, _Buffer.Length);
var BodyIndexData = GCHandle.Alloc(buffer, GCHandleType.Pinned);
_Frame.CopyFrameDataToIntPtr(BodyIndexData.AddrOfPinnedObject(), (uint)buffer.Length);
BodyIndexData.Free();
}
} }
} }
private class RealDepthFrame : IDepthFrame private class RealDepthFrame : IDepthFrame
{ {
private DepthFrame _Frame; private ushort[] _Buffer = new ushort[KinectConstants.DepthWidth *
KinectConstants.DepthHeight];
private bool IsValid = false;
public RealDepthFrame(DepthFrame frame) public RealDepthFrame(DepthFrame frame)
{ {
_Frame = frame; if (frame != null)
{
var DepthData = GCHandle.Alloc(_Buffer, GCHandleType.Pinned);
frame.CopyFrameDataToIntPtr(DepthData.AddrOfPinnedObject(), (uint)_Buffer.Length * sizeof(ushort));
DepthData.Free();
IsValid = true;
}
} }
public void CopyData(ushort[] buffer) public void CopyData(ushort[] buffer)
{ {
if (_Frame != null) if (IsValid)
{ Array.Copy(_Buffer, buffer, _Buffer.Length);
var DepthData = GCHandle.Alloc(buffer, GCHandleType.Pinned);
_Frame.CopyFrameDataToIntPtr(DepthData.AddrOfPinnedObject(), (uint)buffer.Length* sizeof(ushort));
DepthData.Free();
}
} }
} }
private class RealBodyFrame : IBodyFrame private class RealBodyFrame : IBodyFrame
{ {
private BodyFrame _Frame; private Body[] _Buffer = new Body[KinectConstants.BodyCount];
private bool IsValid = false;
public RealBodyFrame(BodyFrame frame) public RealBodyFrame(BodyFrame frame)
{ {
_Frame = frame; if (frame != null)
{
frame.GetAndRefreshBodyData(_Buffer);
IsValid = true;
}
} }
public void CopyData(IBody[] buffer) public void CopyData(IBody[] buffer)
{ {
if (_Frame != null) if (IsValid)
_Frame.GetAndRefreshBodyData(buffer.Select(x => (x as RealBody).Value).ToList()); Enumerable.Range(0, KinectConstants.BodyCount)
.ToList()
.ForEach(x => buffer[x] = new RealBody(_Buffer[x]));
} }
} }
} }
...@@ -420,9 +454,14 @@ namespace KinectModule ...@@ -420,9 +454,14 @@ namespace KinectModule
public bool IsTracked public bool IsTracked
{ get { return _Body.IsTracked; } } { get { return _Body.IsTracked; } }
public Dictionary<JointType, IJoint> Joints public Dictionary<JointType, IJoint> Joints
{ get { return _Body.Joints {
get
{
return _Body.Joints
.Select(x => new KeyValuePair<JointType, IJoint>(x.Key, new RealJoint(x.Value))) .Select(x => new KeyValuePair<JointType, IJoint>(x.Key, new RealJoint(x.Value)))
.ToDictionary(x => x.Key, x => x.Value); } } .ToDictionary(x => x.Key, x => x.Value);
}
}
public Body Value public Body Value
{ get { return _Body; } } { get { return _Body; } }
......
...@@ -35,6 +35,8 @@ GraphicsSettings: ...@@ -35,6 +35,8 @@ GraphicsSettings:
- {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: [] m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0} type: 0}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment