Skip to content

Instantly share code, notes, and snippets.

@ochilab
Created March 13, 2015 10:41
Show Gist options
  • Select an option

  • Save ochilab/9fab2070922b910a385c to your computer and use it in GitHub Desktop.

Select an option

Save ochilab/9fab2070922b910a385c to your computer and use it in GitHub Desktop.
Kinect v2でbodyIndexFrameを利用して人物画像(RGB)を抜き出す
//人物インデックスフレームデータを_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