From f6cf76f73dbecd0362fc7544f0d3c7e138aea4a9 Mon Sep 17 00:00:00 2001 From: uc-hoba Date: Mon, 21 May 2018 12:23:38 +0800 Subject: [PATCH] update Kinect Grpc and add submodule --- .gitmodules | 4 +++ .../Grpc/KinectBufferComposite.compute | 10 +++--- .../Grpc/KinectGrpcServer.cs | 36 +++++++++---------- of_v0.9.8/addons/ofxUCKinectV2 | 1 + 4 files changed, 28 insertions(+), 23 deletions(-) create mode 160000 of_v0.9.8/addons/ofxUCKinectV2 diff --git a/.gitmodules b/.gitmodules index 1cbf962..ff735be 100644 --- a/.gitmodules +++ b/.gitmodules @@ -29,3 +29,7 @@ path = of_v0.9.8/uc_libs/lib_grpc url = https://github.com/UltraCombos/lib_grpc branch = master +[submodule "of_v0.9.8/addons/ofxUCKinectV2"] + path = of_v0.9.8/addons/ofxUCKinectV2 + url = https://github.com/UltraCombos/ofxUCKinectV2 + branch = master diff --git a/Unity_2018_Frozen/Assets/KinectOpticalFlow/Grpc/KinectBufferComposite.compute b/Unity_2018_Frozen/Assets/KinectOpticalFlow/Grpc/KinectBufferComposite.compute index 4f52f87..8fe34e1 100644 --- a/Unity_2018_Frozen/Assets/KinectOpticalFlow/Grpc/KinectBufferComposite.compute +++ b/Unity_2018_Frozen/Assets/KinectOpticalFlow/Grpc/KinectBufferComposite.compute @@ -9,8 +9,8 @@ RWStructuredBuffer kinect_motion_buffer; RWStructuredBuffer position_buffer; RWStructuredBuffer velocity_buffer; -Texture2D depth_high_texture; -Texture2D depth_low_texture; +Texture2D depth_texture; +//Texture2D depth_low_texture; Texture2D velocity_texture; float4x4 kinect_matrix; @@ -22,8 +22,8 @@ float3 clip_box; void CSMain(uint3 id : SV_DispatchThreadID) { int index = id.y * WIDTH + id.x; - int high = (int)(depth_high_texture[id.xy].x * 255.0); - int low = (int)(depth_low_texture[id.xy].x * 255.0); + int high = (int)(depth_texture[id.xy].y * 255.0); + int low = (int)(depth_texture[id.xy].x * 255.0); float depth = (float)((high << 8) + low) * 0.001; float2 vel = velocity_texture[id.xy].xy * 255.0 - 128.0; @@ -69,7 +69,7 @@ void CSMain(uint3 id : SV_DispatchThreadID) } float3 kpos = mul(kinect_matrix, float4(t_p3d, 1.0)).xyz; - float3 kvel = mul(kinect_matrix, float4(-vel3d, 0.0)).xyz; + float3 kvel = mul(kinect_matrix, float4(vel3d, 0.0)).xyz; if ((kpos.x < -clip_box.x * 0.5 || kpos.x > clip_box.x * 0.5 || kpos.z < -clip_box.z * 0.5 || kpos.z > clip_box.z * 0.5 || diff --git a/Unity_2018_Frozen/Assets/KinectOpticalFlow/Grpc/KinectGrpcServer.cs b/Unity_2018_Frozen/Assets/KinectOpticalFlow/Grpc/KinectGrpcServer.cs index 4924765..428c70b 100644 --- a/Unity_2018_Frozen/Assets/KinectOpticalFlow/Grpc/KinectGrpcServer.cs +++ b/Unity_2018_Frozen/Assets/KinectOpticalFlow/Grpc/KinectGrpcServer.cs @@ -68,10 +68,10 @@ namespace UltraCombos.Kinect2MotionTransmit public ComputeBuffer FinalVelocityBuffer { get { return final_velocity_buffer; } } - Texture2D depth_high_texture; - byte[] depth_high_data; - Texture2D depth_low_texture; - byte[] depth_low_data; + Texture2D depth_texture; + byte[] depth_data; + //Texture2D depth_low_texture; + //byte[] depth_low_data; Texture2D velocity_texture; byte[] velocity_data; @@ -91,13 +91,13 @@ namespace UltraCombos.Kinect2MotionTransmit private void Start() { buffer = new ComputeBuffer(width * height, sizeof(float) * 4); - Debug.LogFormat("[Kinect Grpc] Buffer is created by count {0} and stride {1}", buffer.count, buffer.stride); - depth_high_data = new byte[buffer.count / 2]; - depth_low_data = new byte[buffer.count / 2]; + Debug.LogFormat("Buffer is created by count {0} and stride {1}", buffer.count, buffer.stride); + depth_data = new byte[buffer.count ]; + //depth_low_data = new byte[buffer.count / 2]; velocity_data = new byte[buffer.count]; - depth_high_texture = new Texture2D(width, height, TextureFormat.BC4, false); - depth_low_texture = new Texture2D(width, height, TextureFormat.BC4, false); + depth_texture = new Texture2D(width, height, TextureFormat.BC5, false); + //depth_low_texture = new Texture2D(width, height, TextureFormat.BC4, false); velocity_texture = new Texture2D(width, height, TextureFormat.BC5, false); final_position_buffer = new ComputeBuffer(width * height, sizeof(float) * 4); @@ -152,19 +152,19 @@ namespace UltraCombos.Kinect2MotionTransmit kinect.matrix = Matrix4x4.TRS(pos, q, Vector3.one); kinect.ClipBox = new Vector3(data.ClipSizeX, data.ClipSizeY, data.ClipSizeZ); - data.DepthHighData.CopyTo(depth_high_data, 0); - data.DepthLowData.CopyTo(depth_low_data, 0); + data.DepthHighData.CopyTo(depth_data, 0); + //data.DepthLowData.CopyTo(depth_low_data, 0); data.VelocityData.CopyTo(velocity_data, 0); - depth_high_texture.LoadRawTextureData(depth_high_data); - depth_high_texture.Apply(); - depth_low_texture.LoadRawTextureData(depth_low_data); - depth_low_texture.Apply(); + depth_texture.LoadRawTextureData(depth_data); + depth_texture.Apply(); + //depth_low_texture.LoadRawTextureData(depth_low_data); + //depth_low_texture.Apply(); velocity_texture.LoadRawTextureData(velocity_data); velocity_texture.Apply(); - shader.SetTexture(0, "depth_high_texture", depth_high_texture); - shader.SetTexture(0, "depth_low_texture", depth_low_texture); + shader.SetTexture(0, "depth_texture", depth_texture); + //shader.SetTexture(0, "depth_low_texture", depth_low_texture); shader.SetTexture(0, "velocity_texture", velocity_texture); shader.SetBuffer(0, "kinect_motion_buffer", buffer); shader.SetBuffer(0, "position_buffer", kinect.position); @@ -257,7 +257,7 @@ namespace UltraCombos.Kinect2MotionTransmit }; server.Start(); - Debug.Log("[Kinect Grpc] Start Server"); + Debug.Log("Start Server"); } catch (System.Exception e) { diff --git a/of_v0.9.8/addons/ofxUCKinectV2 b/of_v0.9.8/addons/ofxUCKinectV2 new file mode 160000 index 0000000..7a21425 --- /dev/null +++ b/of_v0.9.8/addons/ofxUCKinectV2 @@ -0,0 +1 @@ +Subproject commit 7a21425420a8c2f2a0dbef23c3b3684f114d7a15