This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Kinectからデータを取得し、描画するメソッド | |
private async Task KinectLoop() | |
{ | |
//while文でkinectからデータを取り続ける | |
while (true) | |
{ | |
//GetCaptureでKinectのデータを取得 | |
using(Capture capture=await Task.Run(() => kinect.GetCapture()).ConfigureAwait(true)) | |
{ | |
//Depth画像との位置・サイズ合わせ済みの画像を取得 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Kinectの初期化 | |
private void InitKinect() | |
{ | |
//0番目のKinectと接続 | |
kinect = Device.Open(0); | |
//Kinectの各種モードを設定して動作開始 | |
kinect.StartCameras(new DeviceConfiguration | |
{ | |
ColorFormat = ImageFormat.ColorBGRA32, | |
ColorResolution = ColorResolution.R720p, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
//AzureKinectSDKの読み込み | |
using Microsoft.Azure.Kinect.Sensor; | |
//非同期処理をする準備 | |
using System.Threading.Tasks; | |
public class KinectScript : MonoBehaviour | |
{ | |
//Kinectを扱う変数 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
//AzureKinectSDKの読み込み | |
using Microsoft.Azure.Kinect.Sensor; | |
//非同期処理をする準備 | |
using System.Threading.Tasks; | |
public class KinectScript : MonoBehaviour | |
{ | |
//Kinectを扱う変数 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
//(追加1)AzureKinectSDKの読み込み | |
using Microsoft.Azure.Kinect.Sensor; | |
public class KinectScript : MonoBehaviour | |
{ | |
//(追加2)Kinectを扱う変数 | |
Device kinect; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task KinectLoop() | |
{ | |
//loopがtrueの間はデータを取り続ける | |
while (loop) | |
{ | |
//kinectから新しいデータをもらう | |
using (Capture capture = await Task.Run(() => kinect.GetCapture()).ConfigureAwait(true)) | |
{ | |
//カラー/Depth画像にKinectで取得した情報を書き込む | |
SetColorBitmap(capture); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
NewerOlder