Skip to content

Instantly share code, notes, and snippets.

@TakashiYoshinaga
TakashiYoshinaga / KinectScript.cs
Last active May 17, 2020 03:15
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画像との位置・サイズ合わせ済みの画像を取得
@TakashiYoshinaga
TakashiYoshinaga / KinectScript.cs
Last active December 6, 2019 00:44
Implementation of mesh initialization for drawing point cloud
//Meshを用いてPointCloudを描画する準備をする
private void InitMesh()
{
//Depth画像の横幅と縦幅を取得し、全点数を算出
int width = kinect.GetCalibration().DepthCameraCalibration.ResolutionWidth;
int height = kinect.GetCalibration().DepthCameraCalibration.ResolutionHeight;
num = width * height;
//meshをインスタンス化
mesh = new Mesh();
@TakashiYoshinaga
TakashiYoshinaga / KinectScript.cs
Last active December 6, 2019 00:39
Instantiation of transformation
//Kinectの初期化
private void InitKinect()
{
//0番目のKinectと接続
kinect = Device.Open(0);
//Kinectの各種モードを設定して動作開始
kinect.StartCameras(new DeviceConfiguration
{
ColorFormat = ImageFormat.ColorBGRA32,
ColorResolution = ColorResolution.R720p,
@TakashiYoshinaga
TakashiYoshinaga / KinectScript.cs
Last active December 6, 2019 00:38
Declaration of Valuables and Methods
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//AzureKinectSDKの読み込み
using Microsoft.Azure.Kinect.Sensor;
//非同期処理をする準備
using System.Threading.Tasks;
public class KinectScript : MonoBehaviour
{
//Kinectを扱う変数
@TakashiYoshinaga
TakashiYoshinaga / KinectScript.cs
Last active June 3, 2021 02:33
Visualization of Point Cloud of Azure Kinect
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//AzureKinectSDKの読み込み
using Microsoft.Azure.Kinect.Sensor;
//非同期処理をする準備
using System.Threading.Tasks;
public class KinectScript : MonoBehaviour
{
//Kinectを扱う変数
@TakashiYoshinaga
TakashiYoshinaga / KinectScript.cs
Created December 5, 2019 07:05
Connection Test with Azure Kinect
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//(追加1)AzureKinectSDKの読み込み
using Microsoft.Azure.Kinect.Sensor;
public class KinectScript : MonoBehaviour
{
//(追加2)Kinectを扱う変数
Device kinect;
@TakashiYoshinaga
TakashiYoshinaga / Form1.cs
Created December 5, 2019 03:35
Acquisition of DepthImage of Azure Kinecct
private void SetDepthBitmap(Capture capture)
{
//Depth画像を取得
Image depthImage = capture.Depth;
//Depth画像の各ピクセルの値(奥行)のみを取得
ushort[] depthArray = depthImage.GetPixels<ushort>().ToArray();
//depthBitmapの各画素に値を書き込む準備
BitmapData bitmapData = depthBitmap.LockBits(new Rectangle(0, 0, depthBitmap.Width, depthBitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
unsafe
{
@TakashiYoshinaga
TakashiYoshinaga / Form1.cs
Created December 5, 2019 03:24
Transformation of ColorImage into Depth Image
private void SetColorBitmap(Capture capture)
{
//カラー画像をDepth画像の位置に合わせる
Image colorImage = transformation.ColorImageToDepthCamera(capture);
//各Pixelの色情報を格納した配列を取得
BGRA[] colorArray = colorImage.GetPixels<BGRA>().ToArray();
//colorBitmapへの書き込み準備
BitmapData bitmapData = colorBitmap.LockBits(new Rectangle(0, 0, colorBitmap.Width, colorBitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
unsafe
{
@TakashiYoshinaga
TakashiYoshinaga / Form1.cs
Last active December 5, 2019 02:45
Grabbing Images of Kinect
private async Task KinectLoop()
{
//loopがtrueの間はデータを取り続ける
while (loop)
{
//kinectから新しいデータをもらう
using (Capture capture = await Task.Run(() => kinect.GetCapture()).ConfigureAwait(true))
{
//カラー/Depth画像にKinectで取得した情報を書き込む
SetColorBitmap(capture);
@TakashiYoshinaga
TakashiYoshinaga / Form1.cs
Created December 5, 2019 02:20
Initialization of color and depth image
private void InitBitmap()
{
//(追加1)カラー画像の横幅(width)と縦幅(height)を取得
int width = kinect.GetCalibration().DepthCameraCalibration.ResolutionWidth;
int height = kinect.GetCalibration().DepthCameraCalibration.ResolutionHeight;
//(追加2)PictureBoxに貼り付けるBitmap画像を作成。サイズはkinectのカラー画像と同じ
colorBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
depthBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
}