예제 #1
0
        /*
         * /// <summary>
         * /// Converts rotation quaternion to Euler angles
         * /// And then maps them to a specified range of values to control the refresh rate
         * /// v1(v1.5-v1.8)ではQuaternion使えない??
         * /// </summary>
         * /// <param name="rotQuaternion">face rotation quaternion</param>
         * /// <param name="pitch">rotation about the X-axis</param>
         * /// <param name="yaw">rotation about the Y-axis</param>
         * /// <param name="roll">rotation about the Z-axis</param>
         * private static void ExtractFaceRotationInDegrees(double qx, double qy, double qz, double qw, out double pitch, out double yaw, out double roll)
         * {
         *  double x = qx;
         *  double y = qy;
         *  double z = qz;
         *  double w = qw;
         *
         *  double pitchD, yawD, rollD;
         *
         *  // convert face rotation quaternion to Euler angles in degrees
         *
         *  pitchD = Math.Atan2(2 * ((y * z) + (w * x)), (w * w) - (x * x) - (y * y) + (z * z)) / Math.PI * 180.0;
         *  yawD = Math.Asin(2 * ((w * y) - (x * z))) / Math.PI * 180.0;
         *  rollD = Math.Atan2(2 * ((x * y) + (w * z)), (w * w) + (x * x) - (y * y) - (z * z)) / Math.PI * 180.0;
         *
         *  // clamp the values to a multiple of the specified increment to control the refresh rate
         *  double increment = FaceRotationIncrementInDegrees;
         *  pitch = (double)(Math.Floor((pitchD + ((increment / 2.0) * (pitchD > 0 ? 1.0 : -1.0))) / increment) * increment);
         *  yaw = (double)(Math.Floor((yawD + ((increment / 2.0) * (yawD > 0 ? 1.0 : -1.0))) / increment) * increment);
         *  roll = (double)(Math.Floor((rollD + ((increment / 2.0) * (rollD > 0 ? 1.0 : -1.0))) / increment) * increment);
         * }
         */

        /// <summary>
        /// Frames更新で実行されるイベント(eの中に更新されたデータを格納)
        /// kinectのメインループ
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
                using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
                    using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
                    {
                        // Image部品にRGB表示
                        if (colorFrame != null)
                        {
                            imageRgbCamera.Source = colorFrame.ToBitmapSource();
                        }

                        // Skeletonが取れているとき表示
                        if (skeletonFrame != null)
                        {
                            foreach (var skeleton in skeletonFrame.GetTrackedSkeletons())
                            {
                                ShowSkeleton(skeleton);
                            }
                        }

                        // RGB, Depth, Skeltonフレームが取得できたら, 追跡されているSkeltonに対して顔認識
                        if ((colorFrame != null) && (depthFrame != null) && (skeletonFrame != null))
                        {
                            foreach (var skeleton in skeletonFrame.GetTrackedSkeletons())
                            {
                                FaceDataAcquisition(colorFrame, depthFrame, skeleton);
                            }
                        }
                    }
        }
예제 #2
0
        public static void Rastrear(SkeletonFrame skeletonFrame, ITracker[] rastreadoresCheck)
        {
            if (skeletonFrame == null)
            {
                return;
            }

            Skeleton esqueletoUsuario = skeletonFrame.GetTrackedSkeletons()?.First();

            if (esqueletoUsuario == null)
            {
                return;
            }

            foreach (ITracker rastreador in rastreadoresCheck)
            {
                rastreador.Rastrear(esqueletoUsuario);
            }
        }
예제 #3
0
        /// <summary>
        /// Retorna verdadeiro se o Kinect estiver reconhecendo apenas um jogador e o mesmo estiver na distância mínima
        /// </summary>
        /// <param name="skeletonFrame"></param>
        /// <returns></returns>
        public static bool Validation(this SkeletonFrame skeletonFrame)
        {
            var skeletonsTracked = skeletonFrame.GetTrackedSkeletons();

            if (skeletonsTracked == null || skeletonsTracked.Count() > 1)
            {
                return(false);
            }

            if (skeletonsTracked.First().Joints[JointType.Spine].TrackingState == JointTrackingState.NotTracked)
            {
                return(false);
            }

            var distance = Util.GetDistance(skeletonsTracked.First().Joints[JointType.Spine].Position);

            if (distance >= Configuration.DISTANCE_CHECK)
            {
                return(true);
            }

            return(false);
        }