This commit is contained in:
Takashi Yoshinaga
2019-09-01 17:11:07 +09:00
parent a4250062ec
commit 40bc3dc596
669 changed files with 157 additions and 240 deletions
+66 -78
View File
@@ -1,7 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Microsoft.Azure.Kinect.Sensor.WinForms;
using Microsoft.Azure.Kinect.Sensor;
using System.Runtime.InteropServices;
using System;
@@ -11,16 +10,17 @@ public class KinectScript : MonoBehaviour
{
int depthWidth;
int depthHeight;
Transformation transformation;
int pointNum;
int nearClip = 300;
Mesh mesh;
int visNum;
Vector3[] vertices;
int[] vertexIndeces;
int[] indeces;
Color32[] col;
Texture2D tex;
Texture2D texture;
Transformation transformation;
Device device;
int nearThreshold = 300;
private void OnDestroy()
{
@@ -29,13 +29,8 @@ public class KinectScript : MonoBehaviour
void Start()
{
InitKinect();
InitRenderingInfo();
InitKinect();
InitMesh();
Task t = KinectLoop(device);
}
void InitKinect()
@@ -44,7 +39,7 @@ public class KinectScript : MonoBehaviour
device.StartCameras(new DeviceConfiguration
{
ColorFormat = ImageFormat.ColorBGRA32,
ColorResolution = ColorResolution.R1080p,
ColorResolution = ColorResolution.R720p,
DepthMode = DepthMode.NFOV_Unbinned,
SynchronizedImagesOnly = true,
CameraFPS = FPS.FPS30,
@@ -52,30 +47,29 @@ public class KinectScript : MonoBehaviour
transformation = device.GetCalibration().CreateTransformation();
depthWidth = device.GetCalibration().DepthCameraCalibration.ResolutionWidth;
depthHeight = device.GetCalibration().DepthCameraCalibration.ResolutionHeight;
depthWidth = device.GetCalibration().depth_camera_calibration.resolution_width;
depthHeight = device.GetCalibration().depth_camera_calibration.resolution_height;
pointNum = depthWidth * depthHeight;
}
void InitRenderingInfo()
void InitMesh()
{
mesh = new Mesh();
mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
visNum = depthWidth * depthHeight;
tex = new Texture2D(depthWidth, depthHeight);
col = new Color32[visNum];
texture = new Texture2D(depthWidth, depthHeight);
col = new Color32[pointNum];
vertices = new Vector3[visNum];
Vector2[] uv = new Vector2[visNum];
vertices = new Vector3[pointNum];
Vector2[] uv = new Vector2[pointNum];
Vector3[] normals = new Vector3[visNum];
vertexIndeces = new int[6 * (depthWidth - 1) * (depthHeight - 1)];
Vector3[] normals = new Vector3[pointNum];
indeces = new int[6 * (depthWidth - 1) * (depthHeight - 1)];
int index = 0;
for (int y = 0; y < depthHeight; y++)
{
for (int x = 0; x < depthWidth; x++)
{
int index = (y * depthWidth) + x;
uv[index] = new Vector2(((float)(x+0.5f) / (float)(depthWidth)), ((float)(y+0.5f) / ((float)(depthHeight))));
normals[index] = new Vector3(0, -1, 0);
index++;
@@ -85,7 +79,7 @@ public class KinectScript : MonoBehaviour
mesh.vertices = vertices;
mesh.uv = uv;
mesh.normals = normals;
gameObject.GetComponent<MeshRenderer>().materials[0].mainTexture = tex;
gameObject.GetComponent<MeshRenderer>().materials[0].mainTexture = texture;
gameObject.GetComponent<MeshFilter>().mesh = mesh;
}
@@ -100,80 +94,74 @@ public class KinectScript : MonoBehaviour
{
Image modifiedColor = transformation.ColorImageToDepthCamera(capture);
BGRA[] colorArray = modifiedColor.GetPixels<BGRA>().ToArray();
Image hoge = transformation.DepthImageToPointCloud(capture.Depth);
Short3[] PointCloud = hoge.GetPixels<Short3>().ToArray();
int width = depthWidth;
int height = depthHeight;
Image cloudImage = transformation.DepthImageToPointCloud(capture.Depth);
Short3[] PointCloud = cloudImage.GetPixels<Short3>().ToArray();
int triangleIndex = 0;
for (int y = 0; y < height; y++)
int pointIndex = 0;
int topLeft, topRight, bottomLeft, bottomRight;
int tl, tr, bl, br;
for (int y = 0; y < depthHeight; y++)
{
for (int x = 0; x < width; x++)
for (int x = 0; x < depthWidth; x++)
{
int index = (y * width) + x;
vertices[pointIndex].x = PointCloud[pointIndex].X * 0.001f;
vertices[pointIndex].y = -PointCloud[pointIndex].Y * 0.001f;
vertices[pointIndex].z = PointCloud[pointIndex].Z * 0.001f;
vertices[index].x = PointCloud[index].X * 0.001f;
vertices[index].y = -PointCloud[index].Y * 0.001f;
vertices[index].z = PointCloud[index].Z * 0.001f;
col[pointIndex].a = 255;
col[pointIndex].b = colorArray[pointIndex].B;
col[pointIndex].g = colorArray[pointIndex].G;
col[pointIndex].r = colorArray[pointIndex].R;
col[index].a = 255;
col[index].b = colorArray[index].B;
col[index].g = colorArray[index].G;
col[index].r = colorArray[index].R;
if (x != (width - 1) && y != (height - 1))
if (x != (depthWidth - 1) && y != (depthHeight - 1))
{
int topLeft = index;
int topRight = topLeft + 1;
int bottomLeft = topLeft + width;
int bottomRight = bottomLeft + 1;
int tl = PointCloud[index].Z;
int tr = PointCloud[index + 1].Z;
int bl = PointCloud[index + depthWidth].Z;
int br = PointCloud[index + 1 + depthWidth].Z;
if (tl > nearThreshold && tr > nearThreshold && bl > nearThreshold)
topLeft = pointIndex;
topRight = topLeft + 1;
bottomLeft = topLeft + depthWidth;
bottomRight = bottomLeft + 1;
tl = PointCloud[topLeft].Z;
tr = PointCloud[topRight].Z;
bl = PointCloud[bottomLeft].Z;
br = PointCloud[bottomRight].Z;
if (tl > nearClip && tr > nearClip && bl > nearClip)
{
vertexIndeces[triangleIndex++] = topLeft;
vertexIndeces[triangleIndex++] = topRight;
vertexIndeces[triangleIndex++] = bottomLeft;
indeces[triangleIndex++] = topLeft;
indeces[triangleIndex++] = topRight;
indeces[triangleIndex++] = bottomLeft;
}
else
{
vertexIndeces[triangleIndex++] = 0;
vertexIndeces[triangleIndex++] = 0;
vertexIndeces[triangleIndex++] = 0;
indeces[triangleIndex++] = 0;
indeces[triangleIndex++] = 0;
indeces[triangleIndex++] = 0;
}
if (bl > nearThreshold && tr > nearThreshold && br > nearThreshold)
if (bl > nearClip && tr > nearClip && br > nearClip)
{
vertexIndeces[triangleIndex++] = bottomLeft;
vertexIndeces[triangleIndex++] = topRight;
vertexIndeces[triangleIndex++] = bottomRight;
indeces[triangleIndex++] = bottomLeft;
indeces[triangleIndex++] = topRight;
indeces[triangleIndex++] = bottomRight;
}
else
{
vertexIndeces[triangleIndex++] = 0;
vertexIndeces[triangleIndex++] = 0;
vertexIndeces[triangleIndex++] = 0;
indeces[triangleIndex++] = 0;
indeces[triangleIndex++] = 0;
indeces[triangleIndex++] = 0;
}
}
pointIndex++;
}
}
tex.SetPixels32(col);
tex.Apply();
texture.SetPixels32(col);
texture.Apply();
mesh.vertices = vertices;
mesh.triangles = vertexIndeces;
mesh.triangles = indeces;
mesh.RecalculateBounds();
}
}
+86 -86
View File
@@ -14,14 +14,14 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_PixelRect:
serializedVersion: 2
x: 0
y: 43
width: 1920
height: 997
x: 7.3333335
y: 50
width: 1265
height: 703
m_ShowMode: 4
m_Title:
m_RootView: {fileID: 6}
m_MinSize: {x: 950, y: 300}
m_MinSize: {x: 950, y: 374}
m_MaxSize: {x: 10000, y: 10000}
--- !u!114 &2
MonoBehaviour:
@@ -42,12 +42,12 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 30
width: 1920
height: 947
m_MinSize: {x: 681, y: 498}
m_MaxSize: {x: 14004, y: 14048}
width: 1265
height: 653
m_MinSize: {x: 679, y: 324}
m_MaxSize: {x: 12004, y: 8024}
vertical: 0
controlID: 103
controlID: 49
--- !u!114 &3
MonoBehaviour:
m_ObjectHideFlags: 52
@@ -63,12 +63,12 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 1308
x: 862
y: 0
width: 612
height: 947
m_MinSize: {x: 277, y: 74}
m_MaxSize: {x: 4002, y: 4024}
width: 403
height: 653
m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 15}
m_Panes:
- {fileID: 15}
@@ -92,8 +92,8 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 325
height: 573
width: 214
height: 379
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 16}
@@ -117,17 +117,17 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 573
width: 1308
height: 374
m_MinSize: {x: 232, y: 274}
m_MaxSize: {x: 10002, y: 10024}
m_ActualView: {fileID: 14}
y: 379
width: 862
height: 274
m_MinSize: {x: 100, y: 100}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 19}
m_Panes:
- {fileID: 14}
- {fileID: 19}
m_Selected: 0
m_LastSelected: 1
m_Selected: 1
m_LastSelected: 0
--- !u!114 &6
MonoBehaviour:
m_ObjectHideFlags: 52
@@ -148,9 +148,9 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1920
height: 997
m_MinSize: {x: 950, y: 300}
width: 1265
height: 703
m_MinSize: {x: 950, y: 374}
m_MaxSize: {x: 10000, y: 10000}
--- !u!114 &7
MonoBehaviour:
@@ -169,7 +169,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1920
width: 1265
height: 30
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
@@ -190,8 +190,8 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 977
width: 1920
y: 683
width: 1265
height: 20
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
@@ -214,10 +214,10 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1308
height: 947
m_MinSize: {x: 404, y: 498}
m_MaxSize: {x: 10002, y: 14048}
width: 862
height: 653
m_MinSize: {x: 404, y: 324}
m_MaxSize: {x: 8004, y: 8024}
vertical: 1
controlID: 50
--- !u!114 &10
@@ -239,8 +239,8 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1308
height: 573
width: 862
height: 379
m_MinSize: {x: 404, y: 224}
m_MaxSize: {x: 8004, y: 4024}
vertical: 0
@@ -260,10 +260,10 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 325
x: 214
y: 0
width: 983
height: 573
width: 648
height: 379
m_MinSize: {x: 204, y: 224}
m_MaxSize: {x: 4004, y: 4024}
m_ActualView: {fileID: 17}
@@ -351,10 +351,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 0
y: 646
width: 1306
height: 354
x: 7.3333335
y: 459.33334
width: 860
height: 254
m_PersistentViewDataDictionary: {fileID: 0}
m_SearchFilter:
m_NameFilter:
@@ -374,14 +374,14 @@ MonoBehaviour:
m_LastFolders:
- Assets
m_LastFoldersGridSize: -1
m_LastProjectPath: C:\Users\Yoshinaga\Desktop\Share\AzureKinectUnitySample
m_LastProjectPath: C:\Users\Yoshinaga\Documents\GitHub\Azure-Kinect-Sample-for-Unity
m_LockTracker:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 62300000
m_LastClickedID: 12386
m_ExpandedIDs: 000000006230000000ca9a3bffffff7f
m_SelectedIDs: 3a320000
m_LastClickedID: 12858
m_ExpandedIDs: 000000007e290000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@@ -409,7 +409,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs:
m_ExpandedIDs: 000000007e290000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@@ -436,7 +436,7 @@ MonoBehaviour:
m_ListAreaState:
m_SelectedInstanceIDs:
m_LastClickedInstanceID: 0
m_HadKeyboardFocusLastEvent: 1
m_HadKeyboardFocusLastEvent: 0
m_ExpandedInstanceIDs: c6230000
m_RenameOverlay:
m_UserAcceptedRename: 0
@@ -485,10 +485,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 1308
y: 73
width: 610
height: 927
x: 869.3334
y: 80
width: 401
height: 633
m_PersistentViewDataDictionary: {fileID: 0}
m_ObjectsLockedBeforeSerialization: []
m_InstanceIDsLockedBeforeSerialization:
@@ -520,17 +520,17 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 0
y: 73
width: 323
height: 553
x: 7.3333335
y: 80
width: 212
height: 359
m_PersistentViewDataDictionary: {fileID: 0}
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: b8350000
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: a2edffff
m_ExpandedIDs: c6fbffff
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@@ -575,10 +575,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 325
y: 73
width: 979
height: 553
x: 221.33334
y: 80
width: 644
height: 359
m_PersistentViewDataDictionary: {fileID: 0}
m_WindowGUID: 1ed7a1dd888ffe74ca312206bb543050
m_SceneLighting: 1
@@ -616,9 +616,9 @@ MonoBehaviour:
speed: 2
m_Value: 0
m_Rotation:
m_Target: {x: 0.020545978, y: 0.11730118, z: 0.0024274134, w: -0.99288094}
m_Target: {x: -0.13043383, y: -0.006843828, z: 0.00090044463, w: -0.9914331}
speed: 2
m_Value: {x: 0.020545978, y: 0.11730118, z: 0.0024274134, w: -0.99288094}
m_Value: {x: -0.13043383, y: -0.006843828, z: 0.00090044463, w: -0.9914331}
m_Size:
m_Target: 1.8747299
speed: 2
@@ -655,10 +655,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 325
y: 73
width: 979
height: 553
x: 221.33334
y: 80
width: 644
height: 359
m_PersistentViewDataDictionary: {fileID: 0}
m_MaximizeOnPlay: 0
m_Gizmos: 0
@@ -670,10 +670,10 @@ MonoBehaviour:
m_VRangeLocked: 0
hZoomLockedByDefault: 0
vZoomLockedByDefault: 0
m_HBaseRangeMin: -489.5
m_HBaseRangeMax: 489.5
m_VBaseRangeMin: -268
m_VBaseRangeMax: 268
m_HBaseRangeMin: -214.66667
m_HBaseRangeMax: 214.66667
m_VBaseRangeMin: -114
m_VBaseRangeMax: 114
m_HAllowExceedBaseRangeMin: 1
m_HAllowExceedBaseRangeMax: 1
m_VAllowExceedBaseRangeMin: 1
@@ -691,25 +691,25 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 17
width: 979
height: 536
width: 644
height: 342
m_Scale: {x: 1, y: 1}
m_Translation: {x: 489.5, y: 268}
m_Translation: {x: 322, y: 171}
m_MarginLeft: 0
m_MarginRight: 0
m_MarginTop: 0
m_MarginBottom: 0
m_LastShownAreaInsideMargins:
serializedVersion: 2
x: -489.5
y: -268
width: 979
height: 536
x: -322
y: -171
width: 644
height: 342
m_MinimalGUI: 1
m_defaultScale: 1
m_TargetTexture: {fileID: 0}
m_CurrentColorSpace: 0
m_LastWindowPixelSize: {x: 979, y: 553}
m_LastWindowPixelSize: {x: 966, y: 538.5}
m_ClearInEditMode: 1
m_NoCameraWarning: 1
m_LowResolutionForAspectRatios: 01000000000100000100
@@ -735,8 +735,8 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 0
y: 646
width: 1306
height: 354
x: 7.3333335
y: 459.33334
width: 860
height: 254
m_PersistentViewDataDictionary: {fileID: 0}
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
08d7169d4e90bf00.08d7169d50f31900
08d72a00e6fe3300.08d72a00e9608d00
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
{"cameraMode":{"drawMode":0,"name":"Shaded","section":"Shading Mode"},"sceneLighting":true,"audioPlay":false,"sceneViewState":{"showFog":true,"showMaterialUpdate":false,"showSkybox":true,"showFlares":true,"showImageEffects":true,"showParticleSystems":true},"in2DMode":false,"pivot":{"x":0.0,"y":0.0,"z":0.0},"rotation":{"x":0.020545978099107744,"y":0.11730118095874787,"z":0.002427413361147046,"w":-0.9928809404373169},"size":1.874729871749878,"orthographic":false}
{"cameraMode":{"drawMode":0,"name":"Shaded","section":"Shading Mode"},"sceneLighting":true,"audioPlay":false,"sceneViewState":{"showFog":true,"showMaterialUpdate":false,"showSkybox":true,"showFlares":true,"showImageEffects":true,"showParticleSystems":true},"in2DMode":false,"pivot":{"x":0.0,"y":0.0,"z":0.0},"rotation":{"x":-0.1304338276386261,"y":-0.00684382813051343,"z":0.0009004446328617632,"w":-0.9914330840110779},"size":1.874729871749878,"orthographic":false}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More