Beispiel #1
0
        /// <summary>
        /// 顔を認識し回転のパラメータを取得
        /// </summary>
        /// <param name="colorFrame"></param>
        /// <param name="depthFrame"></param>
        /// <param name="skeletonFrame"></param>
        private void FaceDataAcquisition(ColorImageFrame colorFrame, DepthImageFrame depthFrame, Skeleton skeleton)
        {
            FaceTrackFrame faceFrame = faceTracker.Track(colorFrame.Format, colorFrame.ToPixelData(),
                                                         depthFrame.Format, depthFrame.ToPixelData(), skeleton);

            if (faceFrame.TrackSuccessful)
            {
                rotHeadXYZ.x = faceFrame.Rotation.X;
                rotHeadXYZ.y = faceFrame.Rotation.Y;
                rotHeadXYZ.z = faceFrame.Rotation.Z;

                // トラッキング状態を表示
                statusTextBlock.Text       = "Status: Tracked";
                statusTextBlock.Background = new SolidColorBrush(Color.FromRgb(0xBB, 0xDE, 0xFB));

                // 送信
                if (sendTextBlock.Text != "push 'Update IP and Port'")
                {
                    SendOSCMessage(rotHeadXYZ, posHeadXYZ, posHandRightXYZ, posHandLeftXYZ);
                }
            }
            else
            {
                // トラッキング状態を表示
                statusTextBlock.Text       = "Status: NOT Tracked";
                statusTextBlock.Background = (SolidColorBrush)this.FindResource("MyBrush");
            }
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <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);
        }