Skip to content

Instantly share code, notes, and snippets.

@TakashiYoshinaga
Last active May 17, 2020 03:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakashiYoshinaga/3828f5eb8a9623f3b09b0954b1577ac4 to your computer and use it in GitHub Desktop.
Save TakashiYoshinaga/3828f5eb8a9623f3b09b0954b1577ac4 to your computer and use it in GitHub Desktop.
Implementation of visualization of point cloud.
//Kinectからデータを取得し、描画するメソッド
private async Task KinectLoop()
{
//while文でkinectからデータを取り続ける
while (true)
{
//GetCaptureでKinectのデータを取得
using(Capture capture=await Task.Run(() => kinect.GetCapture()).ConfigureAwait(true))
{
//Depth画像との位置・サイズ合わせ済みの画像を取得
Image colorImage = transformation.ColorImageToDepthCamera(capture);
//色情報のみの配列を取得
BGRA[] colorArray = colorImage.GetPixels<BGRA>().ToArray();
//capture.DepthでDepth画像を取得
//さらにDepthImageToPointCloudでxyzに変換
Image xyzImage = transformation.DepthImageToPointCloud(capture.Depth);
//変換後のデータから点の座標のみの配列を取得
Short3[] xyzArray = xyzImage.GetPixels<Short3>().ToArray();
//Kinectで取得した全点の座標や色を代入
for(int i = 0; i < num; i++)
{
//頂点座標の代入
vertices[i].x = xyzArray[i].X * 0.001f;
vertices[i].y = -xyzArray[i].Y * 0.001f;//上下反転
vertices[i].z = xyzArray[i].Z * 0.001f;
//色の代入
colors[i].b = colorArray[i].B;
colors[i].g = colorArray[i].G;
colors[i].r = colorArray[i].R;
colors[i].a = 255;
}
//meshに最新の点の座標と色を渡す
mesh.vertices = vertices;
mesh.colors32 = colors;
mesh.RecalculateBounds();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment