Created
March 13, 2015 10:41
-
-
Save ochilab/9fab2070922b910a385c to your computer and use it in GitHub Desktop.
Kinect v2でbodyIndexFrameを利用して人物画像(RGB)を抜き出す
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
| //人物インデックスフレームデータを_bodyDataにコピー | |
| bodyIndexFrame.CopyFrameDataToArray(_bodyData); | |
| //depthframeからカラースペースに | |
| kinect.CoordinateMapper.MapDepthFrameToColorSpace(_depthData, _colorPoints); | |
| for (int depthIndex=0; depthIndex < length; depthIndex++){ | |
| byte player = _bodyData[depthIndex]; | |
| //もし人物の領域ならば | |
| if (player != 0xff){ | |
| ColorSpacePoint colorPoint = _colorPoints[depthIndex]; | |
| //整数に変換している | |
| int colorX = (int)Math.Floor(colorPoint.X + 0.5); | |
| int colorY = (int)Math.Floor(colorPoint.Y + 0.5); | |
| //すべて正ならば そこだけをカラーで表示 | |
| if ((colorX >= 0) && (colorX < colorWidth) && (colorY >= 0) && (colorY < colorHeight)){ | |
| int colorIndex = ((colorY * colorWidth) + colorX) * BYTES_PER_PIXEL; | |
| int displayIndex = depthIndex * BYTES_PER_PIXEL; | |
| //RGBカメラの色情報を表示用Byte配列へコピー | |
| outputColor[displayIndex + 0] = _colorData[colorIndex]; | |
| outputColor[displayIndex + 1] = _colorData[colorIndex + 1]; | |
| outputColor[displayIndex + 2] = _colorData[colorIndex + 2]; | |
| outputColor[displayIndex + 3] = 0xff; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment