Loading [MathJax]/extensions/tex2jax.js

2014-10-10

Kinectにてユーザ領域のマスク(WriteableBitmap)を生成する

よくあるテキスト等で書かれている処理ですが、ユーザ領域のマスクを作っておくと、後々便利なことがあったりしますので、、、、
public WriteableBitmap createPlayerMaskWBitmap(DepthImagePixel[] depthImagePixels, ColorImagePoint[] colorImagePoints) {
int width = KINECT.DepthStream.FrameWidth;
byte[] outputColor = new Byte[KINECT.ColorStream.FramePixelDataLength];
WriteableBitmap testBitmap = new WriteableBitmap(colorFrameWidth, colorFrameHeight, 96, 96, PixelFormats.Bgr32, null);
for (int i = 0; i < depthImagePixels.Length; i++) {
int colorIndex = ((colorImagePoints[i].Y * width) + colorImagePoints[i].X) * 4;
if (depthImagePixels[i].PlayerIndex != 0) {
outputColor[colorIndex] = 255;
outputColor[colorIndex + 1] = 255;
outputColor[colorIndex + 2] = 255;
outputColor[colorIndex + 3] = 0;
} else {
outputColor[colorIndex] = 0;
outputColor[colorIndex + 1] = 0;
outputColor[colorIndex + 2] = 0;
outputColor[colorIndex + 3] = 0;
}
}
testBitmap.WritePixels(ColorImageBitmapRect, outputColor, ColorImageStride, 0);
return testBitmap;
}


0 件のコメント:

コメントを投稿