/// <summary>
        /// 距離データをカラー画像に変換する
        /// </summary>
        /// <param name="depthFrame"></param>
        /// <returns></returns>
        private static byte[] ConvertDepthToColor( DepthImageFrame depthFrame )
        {
            // 距離カメラのピクセルごとのデータを取得する
            short[] depthPixel = depthFrame.ToPixelData();

            // 画像化データを作成する
            byte[] depthColor = new byte[depthFrame.Width * depthFrame.Height * BytesPerPixel];

            // 画像化する
            for ( int i = 0; i < depthPixel.Length; i++ ) {
                // 距離カメラのデータから、距離とプレイヤーIDを取得する
                int distance = depthPixel[i] >> DepthImageFrame.PlayerIndexBitmaskWidth;
                int player = depthPixel[i] & DepthImageFrame.PlayerIndexBitmask;

                // バイトインデックスを計算する
                int index = i * BytesPerPixel;

                byte gray = (byte)~(byte)KinectUtility.ScaleTo( distance, 0x0FFF, 0xFF );
                depthColor[index + 0] = gray;
                depthColor[index + 1] = gray;
                depthColor[index + 2] = gray;
            }

            return depthColor;
        }
コード例 #2
0
        /// <summary>
        /// 顔を追跡する
        /// </summary>
        /// <param name="colorFrame"></param>
        /// <param name="depthFrame"></param>
        /// <param name="skeleton"></param>
        private void FaceTracking( ColorImageFrame colorFrame, DepthImageFrame depthFrame, Skeleton skeleton )
        {
            var faceFrame = faceTracker.Track( colorFrame.Format, colorFrame.ToPixelData(),
                depthFrame.Format, depthFrame.ToPixelData(), skeleton );
            if ( faceFrame.TrackSuccessful ) {
                // 四角を移動させる
                rectFace.Margin = new Thickness( faceFrame.FaceRect.Left, faceFrame.FaceRect.Top, 0, 0 );
                rectFace.Width = faceFrame.FaceRect.Width;
                rectFace.Height = faceFrame.FaceRect.Height;

                rectFace.Visibility = System.Windows.Visibility.Visible;
            }
            else {
                rectFace.Visibility = System.Windows.Visibility.Hidden;
            }
        }
        /// <summary>
        /// 距離データをカラー画像に変換する
        /// </summary>
        /// <param name="kinect"></param>
        /// <param name="depthFrame"></param>
        /// <returns></returns>
        private static byte[] ConvertDepthToColor( DepthImageFrame depthFrame, DepthImageStream depthStream )
        {
            // 距離カメラのピクセルごとのデータを取得する
            short[] depthPixel = depthFrame.ToPixelData();

            // 画像化データを作成する
            byte[] depthColor = new byte[depthFrame.Width * depthFrame.Height * BytesPerPixel];

            // 画像化する
            for ( int i = 0; i < depthPixel.Length; i++ ) {
                // 距離カメラのデータから、距離とプレイヤーIDを取得する
                int distance = depthPixel[i] >> DepthImageFrame.PlayerIndexBitmaskWidth;
                int player = depthPixel[i] & DepthImageFrame.PlayerIndexBitmask;

                // バイトインデックスを計算する
                int index = i * BytesPerPixel;

                // プレイヤーがいる座標
                if ( player != 0 ) {
                    depthColor[index + 0] = PlayerColors[player].B;
                    depthColor[index + 1] = PlayerColors[player].G;
                    depthColor[index + 2] = PlayerColors[player].R;
                }
                // プレイヤーがいない座標
                else {
                    // サポート外 0-40cm
                    if ( distance == depthStream.UnknownDepth ) {
                        // Colors.DarkGoldenrod
                        depthColor[index + 0] = 0x0B;
                        depthColor[index + 1] = 0x86;
                        depthColor[index + 2] = 0xB8;
                    }
                    // 近すぎ 40cm-80cm(default mode)
                    else if ( distance == depthStream.TooNearDepth ) {
                        // Colors.White
                        depthColor[index + 0] = 0xFF;
                        depthColor[index + 1] = 0xFF;
                        depthColor[index + 2] = 0xFF;
                    }
                    // 遠すぎ 3m(Near),4m(Default)-8m
                    else if ( distance == depthStream.TooFarDepth ) {
                        // Colors.Purple
                        depthColor[index + 0] = 0x80;
                        depthColor[index + 1] = 0x00;
                        depthColor[index + 2] = 0x80;
                    }
                    // 有効な距離データ
                    else {
                        // Colors.DarkCyan
                        depthColor[index + 0] = 0x8B;
                        depthColor[index + 1] = 0x8B;
                        depthColor[index + 2] = 0x00;
                    }
                }
            }

            return depthColor;
        }
        /// <summary>
        /// 距離データをカラー画像に変換する
        /// </summary>
        /// <param name="depthFrame"></param>
        /// <returns></returns>
        private static byte[] ConvertDepthToColor( DepthImageFrame depthFrame, KinectSensor kinect )
        {
            // 距離カメラのピクセルごとのデータを取得する
            short[] depthPixel = depthFrame.ToPixelData();

            // 画像化データを作成する
            byte[] depthColor = new byte[depthFrame.Width * depthFrame.Height * BytesPerPixel];

            var colorPoints = new ColorImagePoint[kinect.ColorStream.FrameWidth * kinect.ColorStream.FrameHeight];
            kinect.CoordinateMapper.MapDepthFrameToColorFrame(kinect.DepthStream.Format,
                depthFrame.ToDepthImagePixel(), kinect.ColorStream.Format, colorPoints
                );

            // 画像化する
            for ( int i = 0; i < depthPixel.Length; i++ ) {
                // 距離カメラのデータから、距離とプレイヤーIDを取得する
                int distance = depthPixel[i] >> DepthImageFrame.PlayerIndexBitmaskWidth;
                int player = depthPixel[i] & DepthImageFrame.PlayerIndexBitmask;

                // バイトインデックスを計算する
                int index = (colorPoints[i].Y * kinect.ColorStream.FrameWidth + colorPoints[i].X) * BytesPerPixel;

                byte gray = (byte)~(byte)KinectUtility.ScaleTo( distance, 0x0FFF, 0xFF );
                depthColor[index + 0] = gray;
                depthColor[index + 1] = gray;
                depthColor[index + 2] = gray;
            }

            return depthColor;
        }