change infrared to depth

This commit is contained in:
Chikashi Miyama 2019-11-13 21:15:25 +01:00
parent 29ea4ec5cf
commit b0fd65e156
3 changed files with 79 additions and 30 deletions

View file

@ -497,6 +497,18 @@ MonoBehaviour:
enableFptlForForwardOpaque: 0
enableBigTilePrepass: 0
isFptlEnabled: 0
--- !u!114 &671764822 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 946191388, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
m_PrefabInstance: {fileID: 880921870}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c0603bf64edb4c8885cefbc40ee206fe, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &880921870
PrefabInstance:
m_ObjectHideFlags: 0
@ -564,10 +576,45 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6724733047624778891, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
propertyPath: depthFrameReceived.m_PersistentCalls.m_Calls.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6724733047624778891, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
propertyPath: skeleton
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6724733047624778891, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
propertyPath: depth
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6724733047624778891, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
propertyPath: depthFrameReceived.m_PersistentCalls.m_Calls.Array.data[0].m_Mode
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6724733047624778891, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
propertyPath: depthFrameReceived.m_PersistentCalls.m_Calls.Array.data[0].m_CallState
value: 2
objectReference: {fileID: 0}
- target: {fileID: 6724733047624778891, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
propertyPath: depthFrameReceived.m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
objectReference: {fileID: 671764822}
- target: {fileID: 6724733047624778891, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
propertyPath: depthFrameReceived.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: OnTextureReceived
objectReference: {fileID: 0}
- target: {fileID: 6724733047624778891, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
propertyPath: depthFrameReceived.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
value: UnityEngine.Object, UnityEngine
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 367ac1ecba1e2584c816e0372e8d9b31, type: 3}

View file

@ -150,12 +150,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5b54a31bc1a14c1abb51fe86c56c6227, type: 3}
m_Name:
m_EditorClassIdentifier:
infrared: 1
infraredFrameReceived:
depth: 1
depthFrameReceived:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 583502371}
m_MethodName: OnTextureReceived
- m_Target: {fileID: 238320197}
m_MethodName: OnInfraredFrameReceived
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
@ -165,8 +165,8 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 238320197}
m_MethodName: OnInfraredFrameReceived
- m_Target: {fileID: 583502371}
m_MethodName: OnTextureReceived
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
@ -1292,6 +1292,7 @@ VFXRenderer:
m_RendererPriority: 0
m_Materials:
- {fileID: 0}
- {fileID: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0

View file

@ -7,13 +7,13 @@ using UnityEngine.Events;
namespace cylvester
{
[Serializable] public class UnityInfraredCameraEvent : UnityEvent<Texture2D>{ }
[Serializable] public class UnityDepthCameraEvent : UnityEvent<Texture2D>{ }
[Serializable] public class UnitySkeletonEvent : UnityEvent<Body, int>{ }
public class KinectManagerBehaviour : MonoBehaviour
{
[SerializeField] private bool infrared;
[SerializeField] public UnityInfraredCameraEvent infraredFrameReceived;
[SerializeField] private bool depth;
[SerializeField] public UnityDepthCameraEvent depthFrameReceived;
[SerializeField] private bool skeleton;
[SerializeField] public UnitySkeletonEvent skeletonDataReceived;
@ -21,15 +21,15 @@ namespace cylvester
[SerializeField, Range(1, 6)] private int numberOfBodiesTobeTracked = 2;
private KinectSensor sensor_;
private InfraredFrameReader infraredFrameReader_;
private DepthFrameReader depthFrameReader_;
private BodyFrameReader bodyFrameReader_;
private BodyIndexFrameReader bodyIndexFrameReader_;
private ushort [] irData_;
private Texture2D infraredTexture_;
private ushort [] depthData_;
private Texture2D depthTexture_;
private Body[] bodies_;
private EventHandler<InfraredFrameArrivedEventArgs> onInfraredFrameArrived_;
private EventHandler<DepthFrameArrivedEventArgs> onDepthFrameArrived_;
private EventHandler<BodyFrameArrivedEventArgs> onBodyFrameArrived_;
private EventHandler<BodyIndexFrameArrivedEventArgs> onBodyIndexFrameArrived_;
private BodyHolder trackedBodies_;
@ -40,7 +40,7 @@ namespace cylvester
if (sensor_ == null)
throw new IOException("cannot find Kinect Sensor ");
InitInfraredCamera();
InitDepthCamera();
InitSkeletonTracking();
if (!sensor_.IsOpen)
@ -49,38 +49,39 @@ namespace cylvester
}
}
private void InitInfraredCamera()
private void InitDepthCamera()
{
infraredFrameReader_ = sensor_.InfraredFrameSource.OpenReader();
var frameDesc = sensor_.InfraredFrameSource.FrameDescription;
irData_ = new ushort[frameDesc.LengthInPixels];
infraredTexture_ = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.R16, false);
onInfraredFrameArrived_ = (frameReader, eventArgs) =>
depthFrameReader_ = sensor_.DepthFrameSource.OpenReader();
var frameDesc = sensor_.DepthFrameSource.FrameDescription;
depthData_ = new ushort[frameDesc.LengthInPixels];
depthTexture_ = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.R16, false);
onDepthFrameArrived_ = (frameReader, eventArgs) =>
{
if(!infrared)
if(!depth)
return;
using (var infraredFrame = eventArgs.FrameReference.AcquireFrame())
using (var depthFrame = eventArgs.FrameReference.AcquireFrame())
{
if (infraredFrame == null)
if (depthFrame == null)
return;
infraredFrame.CopyFrameDataToArray(irData_);
depthFrame.CopyFrameDataToArray(depthData_);
unsafe
{
fixed (ushort* irDataPtr = irData_)
fixed (ushort* irDataPtr = depthData_)
{
infraredTexture_.LoadRawTextureData((IntPtr) irDataPtr, sizeof(ushort) * irData_.Length);
depthTexture_.LoadRawTextureData((IntPtr) irDataPtr, sizeof(ushort) * depthData_.Length);
}
}
infraredTexture_.Apply();
depthTexture_.Apply();
}
infraredFrameReceived.Invoke(infraredTexture_);
depthFrameReceived.Invoke(depthTexture_);
};
infraredFrameReader_.FrameArrived += onInfraredFrameArrived_;
depthFrameReader_.FrameArrived += onDepthFrameArrived_;
}
private void InitSkeletonTracking()
@ -137,7 +138,7 @@ namespace cylvester
private void OnDestroy()
{
infraredFrameReader_.FrameArrived -= onInfraredFrameArrived_;
depthFrameReader_.FrameArrived -= onDepthFrameArrived_;
bodyFrameReader_.FrameArrived -= onBodyFrameArrived_;
}
}