Last active
September 30, 2016 08:41
-
-
Save ochilab/976d92a8cdffee8ad0cc384ab7f20158 to your computer and use it in GitHub Desktop.
Kinectの震度情報を利用してマスクを作るテンプレート
This file contains 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
// 各変数の宣言は省略してあります | |
maskStride = (int)(depthFrameDesc.Width * colorFrameDesc.BytesPerPixel); | |
var maskBuffer = new byte[depthFrameDesc.LengthInPixels * colorFrameDesc.BytesPerPixel]; | |
//距離カメラの座標に対応するRGBカメラの座標を取得// | |
var colorSpace = new ColorSpacePoint[depthFrameDesc.LengthInPixels]; | |
kinect.CoordinateMapper.MapDepthFrameToColorSpace(depthBuffer, colorSpace); | |
for (int i = 0; i < depthFrameDesc.LengthInPixels; i++) { | |
int colorx = (int)colorSpace[i].X; | |
int colory = (int)colorSpace[i].Y; | |
int colorIndex = (colory * colorFrameDesc.Width) + colorx; | |
int bodyIndex = bodyIndexBuffer[i]; //人物領域かどうかのチェック | |
int colorImageIndex = (int)(i * colorFrameDesc.BytesPerPixel); | |
ushort depth = depthBuffer[i]; | |
if (/*なんらかの条件 */) { | |
if (bodyIndex != 255) //人物領域であれば | |
{ | |
maskBuffer[colorImageIndex + 0] = 100; //青 | |
maskBuffer[colorImageIndex + 1] = 0; | |
maskBuffer[colorImageIndex + 2] = 0; | |
maskBuffer[colorImageIndex + 3] = 0; | |
} | |
else if (/*なんらかの条件*/)//初期背景より手前にあるもの | |
{ | |
maskBuffer[colorImageIndex + 0] = 255; //白 | |
maskBuffer[colorImageIndex + 1] = 255; | |
maskBuffer[colorImageIndex + 2] = 255; | |
maskBuffer[colorImageIndex + 3] = 0; | |
} | |
else //認識範囲外 | |
{ | |
maskBuffer[colorImageIndex + 0] = 0; //黒 | |
maskBuffer[colorImageIndex + 1] = 0; | |
maskBuffer[colorImageIndex + 2] = 0; | |
maskBuffer[colorImageIndex + 3] = 0; | |
} | |
} | |
} | |
WriteableBitmap maskimage = new WriteableBitmap(depthFrameDesc.Width, depthFrameDesc.Height, 96, 96, PixelFormats.Bgra32, null); | |
maskimage.WritePixels(depthRect, maskBuffer, maskStride, 0); | |
image1.Source = maskimage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment